Merge pull request #969 from dbgate/feature/triggers

Feature/triggers
This commit is contained in:
Jan Prochazka
2024-12-19 12:09:08 +01:00
committed by GitHub
22 changed files with 402 additions and 48 deletions

View File

@@ -71,6 +71,10 @@ class Analyser extends DatabaseAnalyser {
this.feedback({ analysingMessage: 'Loading indexes' });
const indexes = await this.analyserQuery('indexes', ['tables'], { $owner: this.dbhan.database });
this.feedback({ analysingMessage: 'Loading unique names' });
const triggers = await this.analyserQuery('triggers', undefined, { $owner: this.dbhan.database });
this.feedback({ analysingMessage: 'Loading triggers' });
const uniqueNames = await this.analyserQuery('uniqueNames', ['tables'], { $owner: this.dbhan.database });
this.feedback({ analysingMessage: 'Finalizing DB structure' });
@@ -183,6 +187,15 @@ class Analyser extends DatabaseAnalyser {
// schemaName: func.schema_name,
contentHash: func.hash_code,
})),
triggers: triggers.rows.map(row => ({
pureName: row.TRIGGER_NAME,
trigerName: row.TRIGGER_NAME,
definition: row.DEFINITION,
tableName: row.TABLE_NAME,
triggerLevel: row.TRIGGER_LEVEL,
triggerTiming: row.TRIGGER_TIMING,
eventType: row.EVENT_TYPE,
})),
};
this.feedback({ analysingMessage: null });

View File

@@ -6,6 +6,7 @@ const views = require('./views');
const matviews = require('./matviews');
const routines = require('./routines');
const indexes = require('./indexes'); // use mysql
const triggers = require('./triggers');
//const indexcols = require('./indexcols');
const uniqueNames = require('./uniqueNames');
//const geometryColumns = require('./geometryColumns');
@@ -24,7 +25,8 @@ module.exports = {
routines,
matviews,
indexes,
// indexcols,
triggers,
// indexcols,
uniqueNames,
//geometryColumns,
//geographyColumns,

View File

@@ -0,0 +1,19 @@
module.exports = `
SELECT
TRIGGER_TYPE AS trigger_timing,
TRIGGERING_EVENT AS event_type,
TRIGGER_BODY AS definition,
TRIGGER_NAME AS trigger_name,
TABLE_NAME AS table_name,
OWNER,
CASE
WHEN INSTR(TRIGGER_TYPE, 'ROW') > 0 THEN 'ROW'
WHEN INSTR(TRIGGER_TYPE, 'STATEMENT') > 0 THEN 'STATEMENT'
ELSE NULL
END AS trigger_level
FROM
all_triggers
WHERE
OWNER='$owner'
AND 'tables:' || TABLE_NAME =OBJECT_ID_CONDITION
`;