|
|
|
@ -356,12 +356,14 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
/** ************** 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) { |
|
|
|
|
await this.sqlClient.schema.withSchema(this.schema).createTable( |
|
|
|
|
args.tn, |
|
|
|
|
function (table) { |
|
|
|
|
await this.sqlClient.schema |
|
|
|
|
.withSchema(this.schema) |
|
|
|
|
.createTable(args.tn, function (table) { |
|
|
|
|
table.increments(); |
|
|
|
|
table.string('title').notNullable(); |
|
|
|
|
table.string('titleDown').nullable(); |
|
|
|
@ -371,8 +373,7 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
table.integer('status').nullable(); |
|
|
|
|
table.dateTime('created'); |
|
|
|
|
table.timestamps(); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
log.debug('Table created:', `${this.getTnPath(args.tn)}`); |
|
|
|
|
} else { |
|
|
|
|
log.debug(`${this.getTnPath(args.tn)} tables exists`); |
|
|
|
@ -394,7 +395,9 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
log.api(`${_func}:args:`, args); |
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
log.ppe(e, _func); |
|
|
|
|
throw e; |
|
|
|
@ -1814,7 +1817,10 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
|
|
|
|
|
const downStatement = |
|
|
|
|
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}`); |
|
|
|
|
|
|
|
|
@ -1856,7 +1862,15 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
BEGIN |
|
|
|
|
SET NOCOUNT ON; |
|
|
|
|
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; |
|
|
|
@ -2058,7 +2072,10 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
/** ************** create up & down statements *************** */ |
|
|
|
|
const upStatement = |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
this.emit(`Success : ${upStatement}`); |
|
|
|
@ -2072,8 +2089,9 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
for (const relation of relationsList) { |
|
|
|
|
downQuery += |
|
|
|
|
this.querySeparator() + |
|
|
|
|
(await this.sqlClient.withSchema(this.schema).schema |
|
|
|
|
.table(relation.tn, (table) => { |
|
|
|
|
(await this.sqlClient |
|
|
|
|
.withSchema(this.schema) |
|
|
|
|
.schema.table(relation.tn, (table) => { |
|
|
|
|
table = table |
|
|
|
|
.foreign(relation.cn, null) |
|
|
|
|
.references(relation.rcn) |
|
|
|
@ -2116,7 +2134,8 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
)) { |
|
|
|
|
downQuery += |
|
|
|
|
this.querySeparator() + |
|
|
|
|
this.sqlClient.schema.withSchema(this.schema) |
|
|
|
|
this.sqlClient.schema |
|
|
|
|
.withSchema(this.schema) |
|
|
|
|
.table(tn, function (table) { |
|
|
|
|
if (non_unique) { |
|
|
|
|
table.index(columns, key_name); |
|
|
|
@ -2161,7 +2180,9 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
const self = this; |
|
|
|
|
await this.sqlClient.schema.table(this.getTnPath(args.childTable), function (table) { |
|
|
|
|
await this.sqlClient.schema.table( |
|
|
|
|
this.getTnPath(args.childTable), |
|
|
|
|
function (table) { |
|
|
|
|
table = table |
|
|
|
|
.foreign(args.childColumn, foreignKeyName) |
|
|
|
|
.references(args.parentColumn) |
|
|
|
@ -2173,7 +2194,8 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
if (args.onDelete) { |
|
|
|
|
table = table.onDelete(args.onDelete); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const upStatement = |
|
|
|
|
this.querySeparator() + |
|
|
|
@ -2234,9 +2256,12 @@ class MssqlClient extends KnexClient {
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
const self = this; |
|
|
|
|
await this.sqlClient.schema.table(this.getTnPath(args.childTable), function (table) { |
|
|
|
|
await this.sqlClient.schema.table( |
|
|
|
|
this.getTnPath(args.childTable), |
|
|
|
|
function (table) { |
|
|
|
|
table.dropForeign(args.childColumn, foreignKeyName); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const upStatement = |
|
|
|
|
this.querySeparator() + |
|
|
|
|