Browse Source

fix: PR requested changes

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4280/head
mertmit 2 years ago
parent
commit
1e99e31d69
  1. 17
      packages/nocodb/src/lib/db/sql-client/lib/mssql/MssqlClient.ts
  2. 6
      packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts

17
packages/nocodb/src/lib/db/sql-client/lib/mssql/MssqlClient.ts

@ -1595,9 +1595,10 @@ class MssqlClient extends KnexClient {
const result = new Result(); const result = new Result();
log.api(`${func}:args:`, args); log.api(`${func}:args:`, args);
try { try {
const query = `CREATE TRIGGER [${args.trigger_name}] on [${this.getTnPath( const query = this.genQuery(
args.tn `CREATE TRIGGER ?? on ?? \n${args.timing} ${args.event}\n as\n${args.statement}`,
)}] \n${args.timing} ${args.event}\n as\n${args.statement}`; [args.trigger_name, this.getTnPath(args.tn)]
);
await this.sqlClient.raw(query); await this.sqlClient.raw(query);
result.data.object = { result.data.object = {
upStatement: [{ sql: this.querySeparator() + query }], upStatement: [{ sql: this.querySeparator() + query }],
@ -1846,15 +1847,17 @@ class MssqlClient extends KnexClient {
for (let i = 0; i < args.columns.length; i++) { for (let i = 0; i < args.columns.length; i++) {
const column = args.columns[i]; const column = args.columns[i];
if (column.au) { if (column.au) {
const triggerName = `xc_trigger_${args.table_name}_${column.column_name}`; const triggerName = `[${this.schema}].[xc_trigger_${args.table_name}_${column.column_name}]`;
const triggerCreateQuery = const triggerCreateQuery =
this.querySeparator() + this.querySeparator() +
`CREATE TRIGGER [${this.schema}].[${triggerName}] ON [${this.schema}].[${args.table_name}] AFTER UPDATE this.genQuery(
`CREATE TRIGGER ?? ON ?? AFTER UPDATE
AS AS
BEGIN BEGIN
SET NOCOUNT ON; SET NOCOUNT ON;
UPDATE [${this.schema}].[${args.table_name}] Set [${column.column_name}] = GetDate() where [${pk.column_name}] in (SELECT [${pk.column_name}] FROM Inserted) UPDATE ?? Set ?? = GetDate() where ?? in (SELECT ?? FROM Inserted)
END;`; 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;

6
packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts

@ -2102,7 +2102,7 @@ class PGClient extends KnexClient {
this.genQuery(`DROP FUNCTION IF EXISTS ??()`, [triggerFnName]); this.genQuery(`DROP FUNCTION IF EXISTS ??()`, [triggerFnName]);
} }
} }
if (upQuery != '') await this.sqlClient.raw(upQuery); if (upQuery !== '') await this.sqlClient.raw(upQuery);
result.upStatement[0] = { sql: upQuery }; result.upStatement[0] = { sql: upQuery };
result.downStatement[0] = { sql: downQuery }; result.downStatement[0] = { sql: downQuery };
@ -2153,7 +2153,7 @@ class PGClient extends KnexClient {
this.genQuery(`DROP FUNCTION IF EXISTS ??()`, [triggerFnName]); this.genQuery(`DROP FUNCTION IF EXISTS ??()`, [triggerFnName]);
} }
} }
if (upQuery != '') await this.sqlClient.raw(upQuery); if (upQuery !== '') await this.sqlClient.raw(upQuery);
result.upStatement[0] = { sql: upQuery }; result.upStatement[0] = { sql: upQuery };
result.downStatement[0] = { sql: downQuery }; result.downStatement[0] = { sql: downQuery };
@ -2273,7 +2273,7 @@ class PGClient extends KnexClient {
//downQuery = `ALTER TABLE "${args.columns[0].tn}" ${downQuery};`; //downQuery = `ALTER TABLE "${args.columns[0].tn}" ${downQuery};`;
} }
if (upQuery != '') await this.sqlClient.raw(upQuery); if (upQuery !== '') await this.sqlClient.raw(upQuery);
// console.log(upQuery); // console.log(upQuery);

Loading…
Cancel
Save