|
|
@ -356,12 +356,14 @@ class MssqlClient extends KnexClient { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
/** ************** START : create _evolution table if not exists *************** */ |
|
|
|
/** ************** START : create _evolution table if not exists *************** */ |
|
|
|
const exists = await this.sqlClient.schema.withSchema(this.schema).hasTable(args.tn); |
|
|
|
const exists = await this.sqlClient.schema |
|
|
|
|
|
|
|
.withSchema(this.schema) |
|
|
|
|
|
|
|
.hasTable(args.tn); |
|
|
|
|
|
|
|
|
|
|
|
if (!exists) { |
|
|
|
if (!exists) { |
|
|
|
await this.sqlClient.schema.withSchema(this.schema).createTable( |
|
|
|
await this.sqlClient.schema |
|
|
|
args.tn, |
|
|
|
.withSchema(this.schema) |
|
|
|
function (table) { |
|
|
|
.createTable(args.tn, function (table) { |
|
|
|
table.increments(); |
|
|
|
table.increments(); |
|
|
|
table.string('title').notNullable(); |
|
|
|
table.string('title').notNullable(); |
|
|
|
table.string('titleDown').nullable(); |
|
|
|
table.string('titleDown').nullable(); |
|
|
@ -371,8 +373,7 @@ class MssqlClient extends KnexClient { |
|
|
|
table.integer('status').nullable(); |
|
|
|
table.integer('status').nullable(); |
|
|
|
table.dateTime('created'); |
|
|
|
table.dateTime('created'); |
|
|
|
table.timestamps(); |
|
|
|
table.timestamps(); |
|
|
|
} |
|
|
|
}); |
|
|
|
); |
|
|
|
|
|
|
|
log.debug('Table created:', `${this.getTnPath(args.tn)}`); |
|
|
|
log.debug('Table created:', `${this.getTnPath(args.tn)}`); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.debug(`${this.getTnPath(args.tn)} tables exists`); |
|
|
|
log.debug(`${this.getTnPath(args.tn)} tables exists`); |
|
|
@ -394,7 +395,9 @@ class MssqlClient extends KnexClient { |
|
|
|
log.api(`${_func}:args:`, args); |
|
|
|
log.api(`${_func}:args:`, args); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
result.data.value = await this.sqlClient.schema.withSchema(this.schema).hasTable(args.tn); |
|
|
|
result.data.value = await this.sqlClient.schema |
|
|
|
|
|
|
|
.withSchema(this.schema) |
|
|
|
|
|
|
|
.hasTable(args.tn); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
log.ppe(e, _func); |
|
|
|
log.ppe(e, _func); |
|
|
|
throw e; |
|
|
|
throw e; |
|
|
@ -1814,7 +1817,10 @@ class MssqlClient extends KnexClient { |
|
|
|
|
|
|
|
|
|
|
|
const downStatement = |
|
|
|
const downStatement = |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
this.sqlClient.schema.withSchema(this.schema).dropTable(args.table).toString(); |
|
|
|
this.sqlClient.schema |
|
|
|
|
|
|
|
.withSchema(this.schema) |
|
|
|
|
|
|
|
.dropTable(args.table) |
|
|
|
|
|
|
|
.toString(); |
|
|
|
|
|
|
|
|
|
|
|
this.emit(`Success : ${upQuery}`); |
|
|
|
this.emit(`Success : ${upQuery}`); |
|
|
|
|
|
|
|
|
|
|
@ -1856,7 +1862,15 @@ class MssqlClient extends KnexClient { |
|
|
|
BEGIN |
|
|
|
BEGIN |
|
|
|
SET NOCOUNT ON; |
|
|
|
SET NOCOUNT ON; |
|
|
|
UPDATE ?? Set ?? = GetDate() where ?? in (SELECT ?? FROM Inserted) |
|
|
|
UPDATE ?? Set ?? = GetDate() where ?? in (SELECT ?? FROM Inserted) |
|
|
|
END;`, [triggerName, this.getTnPath(args.table_name), this.getTnPath(args.table_name), column.column_name, pk.column_name, pk.column_name]
|
|
|
|
END;`,
|
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
triggerName, |
|
|
|
|
|
|
|
this.getTnPath(args.table_name), |
|
|
|
|
|
|
|
this.getTnPath(args.table_name), |
|
|
|
|
|
|
|
column.column_name, |
|
|
|
|
|
|
|
pk.column_name, |
|
|
|
|
|
|
|
pk.column_name, |
|
|
|
|
|
|
|
] |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
upQuery += triggerCreateQuery; |
|
|
|
upQuery += triggerCreateQuery; |
|
|
@ -2058,7 +2072,10 @@ class MssqlClient extends KnexClient { |
|
|
|
/** ************** create up & down statements *************** */ |
|
|
|
/** ************** create up & down statements *************** */ |
|
|
|
const upStatement = |
|
|
|
const upStatement = |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
this.sqlClient.schema.withSchema(this.schema).dropTable(args.tn).toString(); |
|
|
|
this.sqlClient.schema |
|
|
|
|
|
|
|
.withSchema(this.schema) |
|
|
|
|
|
|
|
.dropTable(args.tn) |
|
|
|
|
|
|
|
.toString(); |
|
|
|
let downQuery = this.querySeparator() + this.createTable(args.tn, args); |
|
|
|
let downQuery = this.querySeparator() + this.createTable(args.tn, args); |
|
|
|
|
|
|
|
|
|
|
|
this.emit(`Success : ${upStatement}`); |
|
|
|
this.emit(`Success : ${upStatement}`); |
|
|
@ -2072,8 +2089,9 @@ class MssqlClient extends KnexClient { |
|
|
|
for (const relation of relationsList) { |
|
|
|
for (const relation of relationsList) { |
|
|
|
downQuery += |
|
|
|
downQuery += |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
(await this.sqlClient.withSchema(this.schema).schema |
|
|
|
(await this.sqlClient |
|
|
|
.table(relation.tn, (table) => { |
|
|
|
.withSchema(this.schema) |
|
|
|
|
|
|
|
.schema.table(relation.tn, (table) => { |
|
|
|
table = table |
|
|
|
table = table |
|
|
|
.foreign(relation.cn, null) |
|
|
|
.foreign(relation.cn, null) |
|
|
|
.references(relation.rcn) |
|
|
|
.references(relation.rcn) |
|
|
@ -2116,7 +2134,8 @@ class MssqlClient extends KnexClient { |
|
|
|
)) { |
|
|
|
)) { |
|
|
|
downQuery += |
|
|
|
downQuery += |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
this.sqlClient.schema.withSchema(this.schema) |
|
|
|
this.sqlClient.schema |
|
|
|
|
|
|
|
.withSchema(this.schema) |
|
|
|
.table(tn, function (table) { |
|
|
|
.table(tn, function (table) { |
|
|
|
if (non_unique) { |
|
|
|
if (non_unique) { |
|
|
|
table.index(columns, key_name); |
|
|
|
table.index(columns, key_name); |
|
|
@ -2152,7 +2171,7 @@ class MssqlClient extends KnexClient { |
|
|
|
* @param {String} - args.childTable |
|
|
|
* @param {String} - args.childTable |
|
|
|
* @returns {Promise<{upStatement, downStatement}>} |
|
|
|
* @returns {Promise<{upStatement, downStatement}>} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async relationCreate(args) { |
|
|
|
async relationCreate(args) { |
|
|
|
const _func = this.relationCreate.name; |
|
|
|
const _func = this.relationCreate.name; |
|
|
|
const result = new Result(); |
|
|
|
const result = new Result(); |
|
|
|
log.api(`${_func}:args:`, args); |
|
|
|
log.api(`${_func}:args:`, args); |
|
|
@ -2161,19 +2180,22 @@ class MssqlClient extends KnexClient { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const self = this; |
|
|
|
const self = this; |
|
|
|
await this.sqlClient.schema.table(this.getTnPath(args.childTable), function (table) { |
|
|
|
await this.sqlClient.schema.table( |
|
|
|
table = table |
|
|
|
this.getTnPath(args.childTable), |
|
|
|
.foreign(args.childColumn, foreignKeyName) |
|
|
|
function (table) { |
|
|
|
.references(args.parentColumn) |
|
|
|
table = table |
|
|
|
.on(self.getTnPath(args.parentTable)); |
|
|
|
.foreign(args.childColumn, foreignKeyName) |
|
|
|
|
|
|
|
.references(args.parentColumn) |
|
|
|
if (args.onUpdate) { |
|
|
|
.on(self.getTnPath(args.parentTable)); |
|
|
|
table = table.onUpdate(args.onUpdate); |
|
|
|
|
|
|
|
} |
|
|
|
if (args.onUpdate) { |
|
|
|
if (args.onDelete) { |
|
|
|
table = table.onUpdate(args.onUpdate); |
|
|
|
table = table.onDelete(args.onDelete); |
|
|
|
} |
|
|
|
|
|
|
|
if (args.onDelete) { |
|
|
|
|
|
|
|
table = table.onDelete(args.onDelete); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const upStatement = |
|
|
|
const upStatement = |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
@ -2234,9 +2256,12 @@ class MssqlClient extends KnexClient { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const self = this; |
|
|
|
const self = this; |
|
|
|
await this.sqlClient.schema.table(this.getTnPath(args.childTable), function (table) { |
|
|
|
await this.sqlClient.schema.table( |
|
|
|
table.dropForeign(args.childColumn, foreignKeyName); |
|
|
|
this.getTnPath(args.childTable), |
|
|
|
}); |
|
|
|
function (table) { |
|
|
|
|
|
|
|
table.dropForeign(args.childColumn, foreignKeyName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const upStatement = |
|
|
|
const upStatement = |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|