rename sql object oracle

This commit is contained in:
Jan Prochazka
2024-12-11 15:33:21 +01:00
parent 6035319035
commit face7ecdb5
3 changed files with 23 additions and 9 deletions

View File

@@ -69,6 +69,13 @@ function checkStructure(
} }
} }
function convertModelToEngine(model, driver) {
return model.map(x => ({
...x,
text: x.text ? formatQueryWithoutParams(driver, x.text) : undefined,
}));
}
async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) { async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
const { testEmptyLastScript, finalCheckAgainstModel, markDeleted, allowDropStatements } = options || {}; const { testEmptyLastScript, finalCheckAgainstModel, markDeleted, allowDropStatements } = options || {};
let index = 0; let index = 0;
@@ -89,10 +96,7 @@ async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
systemConnection: conn.isPreparedOnly ? undefined : conn, systemConnection: conn.isPreparedOnly ? undefined : conn,
connection: conn.isPreparedOnly ? conn : undefined, connection: conn.isPreparedOnly ? conn : undefined,
driver, driver,
loadedDbModel: loadedDbModel.map(x => ({ loadedDbModel: convertModelToEngine(loadedDbModel, driver),
...x,
text: x.text ? formatQueryWithoutParams(driver, x.text) : undefined,
})),
dbdiffOptionsExtra, dbdiffOptionsExtra,
}); });
console.debug('Generated deploy script:', sql); console.debug('Generated deploy script:', sql);
@@ -109,7 +113,7 @@ async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
systemConnection: conn.isPreparedOnly ? undefined : conn, systemConnection: conn.isPreparedOnly ? undefined : conn,
connection: conn.isPreparedOnly ? conn : undefined, connection: conn.isPreparedOnly ? conn : undefined,
driver, driver,
loadedDbModel, loadedDbModel: convertModelToEngine(loadedDbModel, driver),
dbdiffOptionsExtra, dbdiffOptionsExtra,
}); });
} }
@@ -120,7 +124,12 @@ async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
const dbhan = conn.isPreparedOnly ? await connectUtility(driver, conn, 'read') : conn; const dbhan = conn.isPreparedOnly ? await connectUtility(driver, conn, 'read') : conn;
const structure = await driver.analyseFull(dbhan); const structure = await driver.analyseFull(dbhan);
if (conn.isPreparedOnly) await driver.close(dbhan); if (conn.isPreparedOnly) await driver.close(dbhan);
checkStructure(engine, structure, finalCheckAgainstModel ?? _.findLast(dbModelsYaml, x => _.isArray(x)), options); checkStructure(
engine,
structure,
convertModelToEngine(finalCheckAgainstModel ?? _.findLast(dbModelsYaml, x => _.isArray(x)), driver),
options
);
} }
describe('Deploy database', () => { describe('Deploy database', () => {
@@ -528,17 +537,17 @@ describe('Deploy database', () => {
const V1 = { const V1 = {
name: 'v1.view.sql', name: 'v1.view.sql',
text: 'create view v1 as select * from t1', text: 'create view ~v1 as select * from ~t1',
}; };
const V1_VARIANT2 = { const V1_VARIANT2 = {
name: 'v1.view.sql', name: 'v1.view.sql',
text: 'create view v1 as select 1 as c1', text: 'create view ~v1 as select 1 as c1',
}; };
const V1_DELETED = { const V1_DELETED = {
name: '_deleted_v1.view.sql', name: '_deleted_v1.view.sql',
text: 'create view _deleted_v1 as select * from t1', text: 'create view ~_deleted_v1 as select * from ~t1',
}; };
test.each(engines.map(engine => [engine.label, engine]))( test.each(engines.map(engine => [engine.label, engine]))(

View File

@@ -126,6 +126,10 @@ class Dumper extends SqlDumper {
this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname); this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname);
} }
renameSqlObject(obj, newname) {
this.putCmd('^rename %f ^to %i', obj, newname);
}
// putValue(value) { // putValue(value) {
// if (value === true) this.putRaw('true'); // if (value === true) this.putRaw('true');
// else if (value === false) this.putRaw('false'); // else if (value === false) this.putRaw('false');

View File

@@ -37,6 +37,7 @@ const dialect = {
dropUnique: true, dropUnique: true,
createCheck: true, createCheck: true,
dropCheck: true, dropCheck: true,
renameSqlObject: true,
dropReferencesWhenDropTable: true, dropReferencesWhenDropTable: true,
requireFromDual: true, requireFromDual: true,