mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 01:46:02 +00:00
feat: add useTransaction option to deployDb
This commit is contained in:
@@ -131,6 +131,7 @@ async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
|
|||||||
driver,
|
driver,
|
||||||
loadedDbModel: convertModelToEngine(loadedDbModel, driver),
|
loadedDbModel: convertModelToEngine(loadedDbModel, driver),
|
||||||
dbdiffOptionsExtra,
|
dbdiffOptionsExtra,
|
||||||
|
useTransaction: engine.runDeployInTransaction,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -711,6 +711,7 @@ const firebirdEngine = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
skipOnCI: false,
|
skipOnCI: false,
|
||||||
|
runDeployInTransaction: true,
|
||||||
// skipChangeColumn: true,
|
// skipChangeColumn: true,
|
||||||
// skipIndexes: true,
|
// skipIndexes: true,
|
||||||
// skipStringLength: true,
|
// skipStringLength: true,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const crypto = require('crypto');
|
|||||||
* @param {string} options.ignoreNameRegex - regex for ignoring objects by name
|
* @param {string} options.ignoreNameRegex - regex for ignoring objects by name
|
||||||
* @param {string} options.targetSchema - target schema for deployment
|
* @param {string} options.targetSchema - target schema for deployment
|
||||||
* @param {number} options.maxMissingTablesRatio - maximum ratio of missing tables in database. Safety check, if missing ratio is highe, deploy is stopped (preventing accidental drop of all tables)
|
* @param {number} options.maxMissingTablesRatio - maximum ratio of missing tables in database. Safety check, if missing ratio is highe, deploy is stopped (preventing accidental drop of all tables)
|
||||||
|
* @param {boolean} options.useTransaction - run deploy in transaction. If not provided, it will be set to true if driver supports transactions
|
||||||
*/
|
*/
|
||||||
async function deployDb({
|
async function deployDb({
|
||||||
connection,
|
connection,
|
||||||
@@ -33,6 +34,7 @@ async function deployDb({
|
|||||||
ignoreNameRegex = '',
|
ignoreNameRegex = '',
|
||||||
targetSchema = null,
|
targetSchema = null,
|
||||||
maxMissingTablesRatio = undefined,
|
maxMissingTablesRatio = undefined,
|
||||||
|
useTransaction,
|
||||||
}) {
|
}) {
|
||||||
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'));
|
||||||
@@ -60,7 +62,14 @@ async function deployDb({
|
|||||||
maxMissingTablesRatio,
|
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,
|
||||||
|
useTransaction,
|
||||||
|
});
|
||||||
|
|
||||||
await scriptDeployer.runPost();
|
await scriptDeployer.runPost();
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const logger = getLogger('execQuery');
|
|||||||
* @param {string} [options.sql] - SQL query
|
* @param {string} [options.sql] - SQL query
|
||||||
* @param {string} [options.sqlFile] - SQL file
|
* @param {string} [options.sqlFile] - SQL file
|
||||||
* @param {boolean} [options.logScriptItems] - whether to log script items instead of whole script
|
* @param {boolean} [options.logScriptItems] - whether to log script items instead of whole script
|
||||||
|
* @param {boolean} [options.useTransaction] - run query in transaction
|
||||||
*/
|
*/
|
||||||
async function executeQuery({
|
async function executeQuery({
|
||||||
connection = undefined,
|
connection = undefined,
|
||||||
@@ -22,6 +23,7 @@ async function executeQuery({
|
|||||||
sql,
|
sql,
|
||||||
sqlFile = undefined,
|
sqlFile = undefined,
|
||||||
logScriptItems = false,
|
logScriptItems = false,
|
||||||
|
useTransaction,
|
||||||
}) {
|
}) {
|
||||||
if (!logScriptItems) {
|
if (!logScriptItems) {
|
||||||
logger.info({ sql: getLimitedQuery(sql) }, `Execute query`);
|
logger.info({ sql: getLimitedQuery(sql) }, `Execute query`);
|
||||||
@@ -38,7 +40,7 @@ async function executeQuery({
|
|||||||
try {
|
try {
|
||||||
logger.debug(`Running SQL query, length: ${sql.length}`);
|
logger.debug(`Running SQL query, length: ${sql.length}`);
|
||||||
|
|
||||||
await driver.script(dbhan, sql, { logScriptItems });
|
await driver.script(dbhan, sql, { logScriptItems, useTransaction });
|
||||||
} finally {
|
} finally {
|
||||||
if (!systemConnection) {
|
if (!systemConnection) {
|
||||||
await driver.close(dbhan);
|
await driver.close(dbhan);
|
||||||
|
|||||||
@@ -41,13 +41,14 @@ program
|
|||||||
'regex, which table data will be loaded and stored in model (in load command)'
|
'regex, which table data will be loaded and stored in model (in load command)'
|
||||||
)
|
)
|
||||||
.option('-e, --engine <engine>', 'engine name, eg. mysql@dbgate-plugin-mysql')
|
.option('-e, --engine <engine>', 'engine name, eg. mysql@dbgate-plugin-mysql')
|
||||||
.option('--commonjs', 'Creates CommonJS module');
|
.option('--commonjs', 'Creates CommonJS module')
|
||||||
|
.option('--transaction', 'Run deploy query in transaction');
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('deploy <modelFolder>')
|
.command('deploy <modelFolder>')
|
||||||
.description('Deploys model to database')
|
.description('Deploys model to database')
|
||||||
.action(modelFolder => {
|
.action(modelFolder => {
|
||||||
const { engine, server, user, password, database } = program.opts();
|
const { engine, server, user, password, database, transaction } = program.opts();
|
||||||
// const hooks = [];
|
// const hooks = [];
|
||||||
// if (program.autoIndexForeignKeys) hooks.push(dbmodel.hooks.autoIndexForeignKeys);
|
// if (program.autoIndexForeignKeys) hooks.push(dbmodel.hooks.autoIndexForeignKeys);
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ program
|
|||||||
database,
|
database,
|
||||||
},
|
},
|
||||||
modelFolder,
|
modelFolder,
|
||||||
|
useTransaction: transaction,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
1
packages/types/test-engines.d.ts
vendored
1
packages/types/test-engines.d.ts
vendored
@@ -51,6 +51,7 @@ export type TestEngineInfo = {
|
|||||||
alterTableAddColumnSyntax?: boolean;
|
alterTableAddColumnSyntax?: boolean;
|
||||||
dbSnapshotBySeconds?: boolean;
|
dbSnapshotBySeconds?: boolean;
|
||||||
setNullDefaultInsteadOfDrop?: boolean;
|
setNullDefaultInsteadOfDrop?: boolean;
|
||||||
|
runDeployInTransaction?: boolean;
|
||||||
|
|
||||||
useTextTypeForStrings?: boolean;
|
useTextTypeForStrings?: boolean;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user