mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 02:56:00 +00:00
maxMissingTablesRatio parameter
This commit is contained in:
@@ -17,6 +17,7 @@ async function deployDb({
|
|||||||
dbdiffOptionsExtra,
|
dbdiffOptionsExtra,
|
||||||
ignoreNameRegex = '',
|
ignoreNameRegex = '',
|
||||||
targetSchema = null,
|
targetSchema = null,
|
||||||
|
maxMissingTablesRatio = undefined,
|
||||||
}) {
|
}) {
|
||||||
if (!driver) driver = requireEngineDriver(connection);
|
if (!driver) driver = requireEngineDriver(connection);
|
||||||
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
||||||
@@ -41,6 +42,7 @@ async function deployDb({
|
|||||||
dbdiffOptionsExtra,
|
dbdiffOptionsExtra,
|
||||||
ignoreNameRegex,
|
ignoreNameRegex,
|
||||||
targetSchema,
|
targetSchema,
|
||||||
|
maxMissingTablesRatio,
|
||||||
});
|
});
|
||||||
// console.log('RUNNING DEPLOY SCRIPT:', sql);
|
// console.log('RUNNING DEPLOY SCRIPT:', sql);
|
||||||
await executeQuery({ connection, systemConnection: dbhan, driver, sql, logScriptItems: true });
|
await executeQuery({ connection, systemConnection: dbhan, driver, sql, logScriptItems: true });
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ async function generateDeploySql({
|
|||||||
dbdiffOptionsExtra = {},
|
dbdiffOptionsExtra = {},
|
||||||
ignoreNameRegex = '',
|
ignoreNameRegex = '',
|
||||||
targetSchema = null,
|
targetSchema = null,
|
||||||
|
maxMissingTablesRatio = undefined,
|
||||||
}) {
|
}) {
|
||||||
if (!driver) driver = requireEngineDriver(connection);
|
if (!driver) driver = requireEngineDriver(connection);
|
||||||
|
|
||||||
@@ -80,6 +81,17 @@ async function generateDeploySql({
|
|||||||
const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
|
const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
|
||||||
const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, dbhan, driver);
|
const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, dbhan, driver);
|
||||||
|
|
||||||
|
if (maxMissingTablesRatio != null) {
|
||||||
|
const missingTables = currentModelPaired.tables.filter(
|
||||||
|
x => !deployedModel.tables.find(y => y.pairingId == x.pairingId)
|
||||||
|
);
|
||||||
|
const missingTableCount = missingTables.length;
|
||||||
|
const missingTablesRatio = missingTableCount / (currentModelPaired.tables.length || 1);
|
||||||
|
if (missingTablesRatio > maxMissingTablesRatio) {
|
||||||
|
throw new Error(`Too many missing tables (${missingTablesRatio * 100}%), aborting deploy`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
|
// console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
|
||||||
// console.log('deployedModel', deployedModel.tables[0]);
|
// console.log('deployedModel', deployedModel.tables[0]);
|
||||||
// console.log('currentModel', currentModel.tables[0]);
|
// console.log('currentModel', currentModel.tables[0]);
|
||||||
|
|||||||
@@ -742,8 +742,12 @@ export function createAlterDatabasePlan(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (opts.deletedSqlObjectPrefix && hasDeletedPrefix(oldobj.pureName, opts, opts.deletedSqlObjectPrefix)) {
|
if (opts.deletedSqlObjectPrefix && hasDeletedPrefix(oldobj.pureName, opts, opts.deletedSqlObjectPrefix)) {
|
||||||
plan.dropSqlObject(oldobj);
|
if (driver.dialect.renameSqlObject && testEqualSqlObjects(oldobj, newobj, opts)) {
|
||||||
plan.createSqlObject(newobj);
|
plan.renameSqlObject(oldobj, newobj.pureName);
|
||||||
|
} else {
|
||||||
|
plan.dropSqlObject(oldobj);
|
||||||
|
plan.createSqlObject(newobj);
|
||||||
|
}
|
||||||
} else if (!testEqualSqlObjects(oldobj, newobj, opts)) {
|
} else if (!testEqualSqlObjects(oldobj, newobj, opts)) {
|
||||||
plan.recreates.sqlObjects += 1;
|
plan.recreates.sqlObjects += 1;
|
||||||
plan.dropSqlObject(oldobj);
|
plan.dropSqlObject(oldobj);
|
||||||
@@ -819,7 +823,7 @@ export function getAlterDatabaseScript(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function matchPairedObjects(db1: DatabaseInfo, db2: DatabaseInfo, opts: DbDiffOptions) {
|
export function matchPairedObjects(db1: DatabaseInfo, db2: DatabaseInfo, opts: DbDiffOptions): DatabaseInfo {
|
||||||
if (!db1 || !db2) return null;
|
if (!db1 || !db2) return null;
|
||||||
|
|
||||||
const res = _cloneDeep(db2);
|
const res = _cloneDeep(db2);
|
||||||
|
|||||||
Reference in New Issue
Block a user