using GO separator for MS SQL db sync

This commit is contained in:
Jan Prochazka 2021-11-25 17:43:09 +01:00
parent 9dcc235f5a
commit 8fd2c78b6a
5 changed files with 21 additions and 5 deletions

View File

@ -468,7 +468,7 @@ export function getAlterTableScript(
}
const plan = createAlterTablePlan(oldTable, newTable, opts, wholeOldDb, wholeNewDb, driver);
const dmp = driver.createDumper();
const dmp = driver.createDumper({ useHardSeparator: true });
if (!driver.dialect.disableExplicitTransaction) dmp.beginTransaction();
plan.run(dmp);
if (!driver.dialect.disableExplicitTransaction) dmp.commitTransaction();
@ -487,7 +487,7 @@ export function getAlterDatabaseScript(
driver: EngineDriver
) {
const plan = createAlterDatabasePlan(oldDb, newDb, opts, wholeOldDb, wholeNewDb, driver);
const dmp = driver.createDumper();
const dmp = driver.createDumper({ useHardSeparator: true });
if (!driver.dialect.disableExplicitTransaction) dmp.beginTransaction();
plan.run(dmp);
if (!driver.dialect.disableExplicitTransaction) dmp.commitTransaction();

View File

@ -32,8 +32,8 @@ export const driverBase = {
const analyser = new this.analyserClass(pool, this, version);
return analyser.incrementalAnalysis(structure);
},
createDumper() {
return new this.dumperClass(this);
createDumper(options = null) {
return new this.dumperClass(this, options);
},
async script(pool, sql) {
for (const sqlItem of splitQuery(sql, this.getQuerySplitterOptions('script'))) {

View File

@ -72,7 +72,7 @@ export interface EngineDriver {
analyseIncremental(pool: any, structure: DatabaseInfo, serverVersion): Promise<DatabaseInfo>;
dialect: SqlDialect;
dialectByVersion(version): SqlDialect;
createDumper(): SqlDumper;
createDumper(options = null): SqlDumper;
getAuthTypes(): EngineAuthType[];
readCollection(pool: any, options: ReadCollectionOptions): Promise<any>;
updateCollection(pool: any, changeSet: any): Promise<any>;

View File

@ -186,6 +186,7 @@
$: console.log('sourceDb', sourceDb);
$: console.log('targetDb', targetDb);
$: console.log('connection', connection);
$: console.log('driver', driver);
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);

View File

@ -1,6 +1,21 @@
const { SqlDumper, testEqualColumns } = global.DBGATE_TOOLS;
class MsSqlDumper extends SqlDumper {
constructor(driver, options) {
super(driver);
if (options && options.useHardSeparator) {
this.useHardSeparator = true;
}
}
endCommand() {
if (this.useHardSeparator) {
this.putRaw('\nGO\n');
} else {
super.endCommand();
}
}
autoIncrement() {
this.put(' ^identity');
}