mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 00:45:58 +00:00
feat: add triggers and scheduler events to sql generator
This commit is contained in:
@@ -18,6 +18,7 @@ import type {
|
|||||||
AlterProcessor,
|
AlterProcessor,
|
||||||
SqlObjectInfo,
|
SqlObjectInfo,
|
||||||
CallableObjectInfo,
|
CallableObjectInfo,
|
||||||
|
SchedulerEventInfo,
|
||||||
} from 'dbgate-types';
|
} from 'dbgate-types';
|
||||||
import _isString from 'lodash/isString';
|
import _isString from 'lodash/isString';
|
||||||
import _isNumber from 'lodash/isNumber';
|
import _isNumber from 'lodash/isNumber';
|
||||||
@@ -431,6 +432,14 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
changeTriggerSchema(obj: TriggerInfo, newSchema: string) {}
|
changeTriggerSchema(obj: TriggerInfo, newSchema: string) {}
|
||||||
renameTrigger(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) {
|
dropConstraintCore(cnt: ConstraintInfo) {
|
||||||
this.putCmd('^alter ^table %f ^drop ^constraint %i', cnt, cnt.constraintName);
|
this.putCmd('^alter ^table %f ^drop ^constraint %i', cnt, cnt.constraintName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type {
|
|||||||
EngineDriver,
|
EngineDriver,
|
||||||
FunctionInfo,
|
FunctionInfo,
|
||||||
ProcedureInfo,
|
ProcedureInfo,
|
||||||
|
SchedulerEventInfo,
|
||||||
TableInfo,
|
TableInfo,
|
||||||
TriggerInfo,
|
TriggerInfo,
|
||||||
ViewInfo,
|
ViewInfo,
|
||||||
@@ -49,12 +50,16 @@ interface SqlGeneratorOptions {
|
|||||||
dropTriggers: boolean;
|
dropTriggers: boolean;
|
||||||
checkIfTriggerExists: boolean;
|
checkIfTriggerExists: boolean;
|
||||||
createTriggers: boolean;
|
createTriggers: boolean;
|
||||||
|
|
||||||
|
dropSchedulerEvents: boolean;
|
||||||
|
checkIfSchedulerEventExists: boolean;
|
||||||
|
createSchedulerEvents: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SqlGeneratorObject {
|
interface SqlGeneratorObject {
|
||||||
schemaName: string;
|
schemaName: string;
|
||||||
pureName: string;
|
pureName: string;
|
||||||
objectTypeField: 'tables' | 'views' | 'procedures' | 'functions';
|
objectTypeField: 'tables' | 'views' | 'procedures' | 'functions' | 'triggers' | 'schedulerEvents';
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SqlGenerator {
|
export class SqlGenerator {
|
||||||
@@ -64,6 +69,7 @@ export class SqlGenerator {
|
|||||||
private procedures: ProcedureInfo[];
|
private procedures: ProcedureInfo[];
|
||||||
private functions: FunctionInfo[];
|
private functions: FunctionInfo[];
|
||||||
private triggers: TriggerInfo[];
|
private triggers: TriggerInfo[];
|
||||||
|
private schedulerEvents: SchedulerEventInfo[];
|
||||||
public dbinfo: DatabaseInfo;
|
public dbinfo: DatabaseInfo;
|
||||||
public isTruncated = false;
|
public isTruncated = false;
|
||||||
public isUnhandledException = false;
|
public isUnhandledException = false;
|
||||||
@@ -83,6 +89,7 @@ export class SqlGenerator {
|
|||||||
this.procedures = this.extract('procedures');
|
this.procedures = this.extract('procedures');
|
||||||
this.functions = this.extract('functions');
|
this.functions = this.extract('functions');
|
||||||
this.triggers = this.extract('triggers');
|
this.triggers = this.extract('triggers');
|
||||||
|
this.schedulerEvents = this.extract('schedulerEvents');
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleException = error => {
|
private handleException = error => {
|
||||||
@@ -104,6 +111,8 @@ export class SqlGenerator {
|
|||||||
if (this.checkDumper()) return;
|
if (this.checkDumper()) return;
|
||||||
this.dropObjects(this.triggers, 'Trigger');
|
this.dropObjects(this.triggers, 'Trigger');
|
||||||
if (this.checkDumper()) return;
|
if (this.checkDumper()) return;
|
||||||
|
this.dropObjects(this.schedulerEvents, 'SchedulerEvent');
|
||||||
|
if (this.checkDumper()) return;
|
||||||
|
|
||||||
this.dropTables();
|
this.dropTables();
|
||||||
if (this.checkDumper()) return;
|
if (this.checkDumper()) return;
|
||||||
@@ -130,6 +139,8 @@ export class SqlGenerator {
|
|||||||
if (this.checkDumper()) return;
|
if (this.checkDumper()) return;
|
||||||
this.createObjects(this.triggers, 'Trigger');
|
this.createObjects(this.triggers, 'Trigger');
|
||||||
if (this.checkDumper()) return;
|
if (this.checkDumper()) return;
|
||||||
|
this.createObjects(this.schedulerEvents, 'SchedulerEvent');
|
||||||
|
if (this.checkDumper()) return;
|
||||||
} finally {
|
} finally {
|
||||||
process.off('uncaughtException', this.handleException);
|
process.off('uncaughtException', this.handleException);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@
|
|||||||
$: generatePreview($valuesStore, $checkedObjectsStore);
|
$: generatePreview($valuesStore, $checkedObjectsStore);
|
||||||
|
|
||||||
$: objectList = _.flatten(
|
$: objectList = _.flatten(
|
||||||
['tables', 'views', 'matviews', 'procedures', 'functions'].map(objectTypeField =>
|
['tables', 'views', 'matviews', 'procedures', 'functions', 'triggers', 'schedulerEvents'].map(objectTypeField =>
|
||||||
_.sortBy(
|
_.sortBy(
|
||||||
(($dbinfo || {})[objectTypeField] || []).map(obj => ({ ...obj, objectTypeField })),
|
(($dbinfo || {})[objectTypeField] || []).map(obj => ({ ...obj, objectTypeField })),
|
||||||
['schemaName', 'pureName']
|
['schemaName', 'pureName']
|
||||||
@@ -214,8 +214,8 @@
|
|||||||
|
|
||||||
<FormCheckboxField label="Truncate tables (delete all rows)" name="truncate" />
|
<FormCheckboxField label="Truncate tables (delete all rows)" name="truncate" />
|
||||||
|
|
||||||
{#each ['View', 'Matview', 'Procedure', 'Function', 'Trigger'] as objtype}
|
{#each ['View', 'Matview', 'Procedure', 'Function', 'Trigger', 'SchedulerEvent'] as objtype}
|
||||||
<div class="obj-heading">{getObjectTypeFieldLabel(objtype.toLowerCase() + 's')}</div>
|
<div class="obj-heading">{getObjectTypeFieldLabel(objtype + 's')}</div>
|
||||||
<FormCheckboxField label="Create" name={`create${objtype}s`} />
|
<FormCheckboxField label="Create" name={`create${objtype}s`} />
|
||||||
<FormCheckboxField label="Drop" name={`drop${objtype}s`} />
|
<FormCheckboxField label="Drop" name={`drop${objtype}s`} />
|
||||||
{#if values[`drop${objtype}s`]}
|
{#if values[`drop${objtype}s`]}
|
||||||
|
|||||||
Reference in New Issue
Block a user