|
|
@ -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; |
|
|
@ -1343,7 +1346,8 @@ class MssqlClient extends KnexClient { |
|
|
|
log.api(`${func}:args:`, args); |
|
|
|
log.api(`${func}:args:`, args); |
|
|
|
// `DROP TRIGGER ${args.trigger_name}`
|
|
|
|
// `DROP TRIGGER ${args.trigger_name}`
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const query = `${this.querySeparator()}DROP TRIGGER IF EXISTS ${args.trigger_name |
|
|
|
const query = `${this.querySeparator()}DROP TRIGGER IF EXISTS ${ |
|
|
|
|
|
|
|
args.trigger_name |
|
|
|
}`;
|
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
|
|
await this.sqlClient.raw(query); |
|
|
|
await this.sqlClient.raw(query); |
|
|
@ -1474,7 +1478,8 @@ class MssqlClient extends KnexClient { |
|
|
|
{ |
|
|
|
{ |
|
|
|
sql: |
|
|
|
sql: |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
`DROP FUNCTION IF EXISTS ${args.function_name |
|
|
|
`DROP FUNCTION IF EXISTS ${ |
|
|
|
|
|
|
|
args.function_name |
|
|
|
};${this.querySeparator()}\n${args.create_function}`,
|
|
|
|
};${this.querySeparator()}\n${args.create_function}`,
|
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
@ -1482,7 +1487,8 @@ class MssqlClient extends KnexClient { |
|
|
|
{ |
|
|
|
{ |
|
|
|
sql: |
|
|
|
sql: |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
`DROP FUNCTION IF EXISTS ${args.function_name |
|
|
|
`DROP FUNCTION IF EXISTS ${ |
|
|
|
|
|
|
|
args.function_name |
|
|
|
};${this.querySeparator()} ${args.oldCreateFunction}`,
|
|
|
|
};${this.querySeparator()} ${args.oldCreateFunction}`,
|
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
@ -1554,7 +1560,8 @@ class MssqlClient extends KnexClient { |
|
|
|
{ |
|
|
|
{ |
|
|
|
sql: |
|
|
|
sql: |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
`DROP PROCEDURE IF EXISTS ${args.procedure_name |
|
|
|
`DROP PROCEDURE IF EXISTS ${ |
|
|
|
|
|
|
|
args.procedure_name |
|
|
|
};${this.querySeparator()}\n${args.create_procedure}`,
|
|
|
|
};${this.querySeparator()}\n${args.create_procedure}`,
|
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
@ -1562,7 +1569,8 @@ class MssqlClient extends KnexClient { |
|
|
|
{ |
|
|
|
{ |
|
|
|
sql: |
|
|
|
sql: |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
`DROP PROCEDURE IF EXISTS ${args.procedure_name |
|
|
|
`DROP PROCEDURE IF EXISTS ${ |
|
|
|
|
|
|
|
args.procedure_name |
|
|
|
};${this.querySeparator()}${args.oldCreateProcedure}`,
|
|
|
|
};${this.querySeparator()}${args.oldCreateProcedure}`,
|
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
@ -1627,7 +1635,8 @@ class MssqlClient extends KnexClient { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// await this.sqlClient.raw(`DROP TRIGGER ${args.trigger_name}`);
|
|
|
|
// await this.sqlClient.raw(`DROP TRIGGER ${args.trigger_name}`);
|
|
|
|
await this.sqlClient.raw( |
|
|
|
await this.sqlClient.raw( |
|
|
|
`ALTER TRIGGER ${args.trigger_name} ON ${this.getTnPath(args.tn)} \n${args.timing |
|
|
|
`ALTER TRIGGER ${args.trigger_name} ON ${this.getTnPath(args.tn)} \n${ |
|
|
|
|
|
|
|
args.timing |
|
|
|
} ${args.event}\n AS\n${args.statement}` |
|
|
|
} ${args.event}\n AS\n${args.statement}` |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -1712,7 +1721,8 @@ class MssqlClient extends KnexClient { |
|
|
|
{ |
|
|
|
{ |
|
|
|
sql: |
|
|
|
sql: |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|
`DROP VIEW ${args.view_name} ; ${this.querySeparator()}${args.oldViewDefination |
|
|
|
`DROP VIEW ${args.view_name} ; ${this.querySeparator()}${ |
|
|
|
|
|
|
|
args.oldViewDefination |
|
|
|
};`,
|
|
|
|
};`,
|
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
@ -1807,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}`); |
|
|
|
|
|
|
|
|
|
|
@ -1849,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; |
|
|
@ -2051,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}`); |
|
|
@ -2065,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) |
|
|
@ -2109,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); |
|
|
@ -2154,7 +2180,9 @@ 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( |
|
|
|
|
|
|
|
this.getTnPath(args.childTable), |
|
|
|
|
|
|
|
function (table) { |
|
|
|
table = table |
|
|
|
table = table |
|
|
|
.foreign(args.childColumn, foreignKeyName) |
|
|
|
.foreign(args.childColumn, foreignKeyName) |
|
|
|
.references(args.parentColumn) |
|
|
|
.references(args.parentColumn) |
|
|
@ -2166,7 +2194,8 @@ class MssqlClient extends KnexClient { |
|
|
|
if (args.onDelete) { |
|
|
|
if (args.onDelete) { |
|
|
|
table = table.onDelete(args.onDelete); |
|
|
|
table = table.onDelete(args.onDelete); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const upStatement = |
|
|
|
const upStatement = |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
@ -2227,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( |
|
|
|
|
|
|
|
this.getTnPath(args.childTable), |
|
|
|
|
|
|
|
function (table) { |
|
|
|
table.dropForeign(args.childColumn, foreignKeyName); |
|
|
|
table.dropForeign(args.childColumn, foreignKeyName); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const upStatement = |
|
|
|
const upStatement = |
|
|
|
this.querySeparator() + |
|
|
|
this.querySeparator() + |
|
|
|