mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 01:55:59 +00:00
feat: add triggers and scheduler events to sql generator
This commit is contained in:
@@ -18,6 +18,7 @@ import type {
|
||||
AlterProcessor,
|
||||
SqlObjectInfo,
|
||||
CallableObjectInfo,
|
||||
SchedulerEventInfo,
|
||||
} from 'dbgate-types';
|
||||
import _isString from 'lodash/isString';
|
||||
import _isNumber from 'lodash/isNumber';
|
||||
@@ -431,6 +432,14 @@ export class SqlDumper implements AlterProcessor {
|
||||
changeTriggerSchema(obj: TriggerInfo, newSchema: string) {}
|
||||
renameTrigger(obj: TriggerInfo, newSchema: string) {}
|
||||
|
||||
createSchedulerEvent(obj: SchedulerEventInfo) {
|
||||
this.putRaw(obj.createSql);
|
||||
this.endCommand();
|
||||
}
|
||||
dropSchedulerEvent(obj: SchedulerEventInfo, { testIfExists = false }) {
|
||||
this.putCmd('^drop ^event %f', obj);
|
||||
}
|
||||
|
||||
dropConstraintCore(cnt: ConstraintInfo) {
|
||||
this.putCmd('^alter ^table %f ^drop ^constraint %i', cnt, cnt.constraintName);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
EngineDriver,
|
||||
FunctionInfo,
|
||||
ProcedureInfo,
|
||||
SchedulerEventInfo,
|
||||
TableInfo,
|
||||
TriggerInfo,
|
||||
ViewInfo,
|
||||
@@ -49,12 +50,16 @@ interface SqlGeneratorOptions {
|
||||
dropTriggers: boolean;
|
||||
checkIfTriggerExists: boolean;
|
||||
createTriggers: boolean;
|
||||
|
||||
dropSchedulerEvents: boolean;
|
||||
checkIfSchedulerEventExists: boolean;
|
||||
createSchedulerEvents: boolean;
|
||||
}
|
||||
|
||||
interface SqlGeneratorObject {
|
||||
schemaName: string;
|
||||
pureName: string;
|
||||
objectTypeField: 'tables' | 'views' | 'procedures' | 'functions';
|
||||
objectTypeField: 'tables' | 'views' | 'procedures' | 'functions' | 'triggers' | 'schedulerEvents';
|
||||
}
|
||||
|
||||
export class SqlGenerator {
|
||||
@@ -64,6 +69,7 @@ export class SqlGenerator {
|
||||
private procedures: ProcedureInfo[];
|
||||
private functions: FunctionInfo[];
|
||||
private triggers: TriggerInfo[];
|
||||
private schedulerEvents: SchedulerEventInfo[];
|
||||
public dbinfo: DatabaseInfo;
|
||||
public isTruncated = false;
|
||||
public isUnhandledException = false;
|
||||
@@ -83,6 +89,7 @@ export class SqlGenerator {
|
||||
this.procedures = this.extract('procedures');
|
||||
this.functions = this.extract('functions');
|
||||
this.triggers = this.extract('triggers');
|
||||
this.schedulerEvents = this.extract('schedulerEvents');
|
||||
}
|
||||
|
||||
private handleException = error => {
|
||||
@@ -104,6 +111,8 @@ export class SqlGenerator {
|
||||
if (this.checkDumper()) return;
|
||||
this.dropObjects(this.triggers, 'Trigger');
|
||||
if (this.checkDumper()) return;
|
||||
this.dropObjects(this.schedulerEvents, 'SchedulerEvent');
|
||||
if (this.checkDumper()) return;
|
||||
|
||||
this.dropTables();
|
||||
if (this.checkDumper()) return;
|
||||
@@ -130,6 +139,8 @@ export class SqlGenerator {
|
||||
if (this.checkDumper()) return;
|
||||
this.createObjects(this.triggers, 'Trigger');
|
||||
if (this.checkDumper()) return;
|
||||
this.createObjects(this.schedulerEvents, 'SchedulerEvent');
|
||||
if (this.checkDumper()) return;
|
||||
} finally {
|
||||
process.off('uncaughtException', this.handleException);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user