mirror of https://github.com/Fabio286/antares.git
feat(PostgreSQL): alter trigger support
This commit is contained in:
parent
b77e77f3bb
commit
5c8ee66f43
|
@ -62,7 +62,7 @@ module.exports = {
|
||||||
functionSql: false,
|
functionSql: false,
|
||||||
functionContext: false,
|
functionContext: false,
|
||||||
functionLanguage: false,
|
functionLanguage: false,
|
||||||
triggerMiltipleEvents: false,
|
triggerMultipleEvents: false,
|
||||||
triggerTableInName: false,
|
triggerTableInName: false,
|
||||||
triggerUpdateColumns: false,
|
triggerUpdateColumns: false,
|
||||||
triggerOnlyRename: false,
|
triggerOnlyRename: false,
|
||||||
|
|
|
@ -40,6 +40,6 @@ module.exports = {
|
||||||
functionLanguage: true,
|
functionLanguage: true,
|
||||||
triggerMultipleEvents: true,
|
triggerMultipleEvents: true,
|
||||||
triggerTableInName: true,
|
triggerTableInName: true,
|
||||||
triggerOnlyRename: true,
|
triggerOnlyRename: false,
|
||||||
languages: ['sql', 'plpgsql', 'c', 'internal']
|
languages: ['sql', 'plpgsql', 'c', 'internal']
|
||||||
};
|
};
|
||||||
|
|
|
@ -535,7 +535,7 @@ export class PostgreSQLClient extends AntaresCore {
|
||||||
*/
|
*/
|
||||||
async dropTrigger (params) {
|
async dropTrigger (params) {
|
||||||
const triggerParts = params.trigger.split('.');
|
const triggerParts = params.trigger.split('.');
|
||||||
const sql = `DROP TRIGGER ${triggerParts[1]} ON ${triggerParts[0]}`;
|
const sql = `DROP TRIGGER "${triggerParts[1]}" ON "${triggerParts[0]}"`;
|
||||||
return await this.raw(sql);
|
return await this.raw(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,21 +547,18 @@ export class PostgreSQLClient extends AntaresCore {
|
||||||
*/
|
*/
|
||||||
async alterTrigger (params) {
|
async alterTrigger (params) {
|
||||||
const { trigger } = params;
|
const { trigger } = params;
|
||||||
// const tempTrigger = Object.assign({}, trigger);
|
const tempTrigger = Object.assign({}, trigger);
|
||||||
// tempTrigger.name = `Antares_${tempTrigger.name}_tmp`;
|
tempTrigger.name = `Antares_${tempTrigger.name}_tmp`;
|
||||||
|
|
||||||
// try {
|
try {
|
||||||
// await this.createTrigger(tempTrigger);
|
await this.createTrigger(tempTrigger);
|
||||||
// await this.dropTrigger({ trigger: tempTrigger.name });
|
await this.dropTrigger({ trigger: `${tempTrigger.table}.${tempTrigger.name}` });
|
||||||
// await this.dropTrigger({ trigger: trigger.oldName });
|
await this.dropTrigger({ trigger: `${trigger.table}.${trigger.oldName}` });
|
||||||
// await this.createTrigger(trigger);
|
await this.createTrigger(trigger);
|
||||||
// }
|
}
|
||||||
// catch (err) {
|
catch (err) {
|
||||||
// return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
// }
|
}
|
||||||
|
|
||||||
const sql = `ALTER TRIGGER ${trigger.oldName} ON ${trigger.table} RENAME TO ${trigger.name}`;
|
|
||||||
return await this.raw(sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -571,7 +568,8 @@ export class PostgreSQLClient extends AntaresCore {
|
||||||
* @memberof PostgreSQLClient
|
* @memberof PostgreSQLClient
|
||||||
*/
|
*/
|
||||||
async createTrigger (trigger) {
|
async createTrigger (trigger) {
|
||||||
const sql = `CREATE ${trigger.definer ? `DEFINER=${trigger.definer} ` : ''}TRIGGER \`${trigger.name}\` ${trigger.event} ${trigger.activation} ON \`${trigger.table}\` FOR EACH ROW ${trigger.sql}`;
|
const eventsString = Array.isArray(trigger.event) ? trigger.event.join(' OR ') : trigger.event;
|
||||||
|
const sql = `CREATE TRIGGER "${trigger.name}" ${trigger.activation} ${eventsString} ON "${trigger.table}" FOR EACH ROW ${trigger.sql}`;
|
||||||
return await this.raw(sql, { split: false });
|
return await this.raw(sql, { split: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue