1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

feat(PostgreSQL): triggers creation

This commit is contained in:
2021-06-26 16:36:05 +02:00
parent 3aef7e953e
commit 7df0cf8389
6 changed files with 66 additions and 12 deletions

View File

@ -62,6 +62,8 @@ module.exports = {
functionSql: false, functionSql: false,
functionContext: false, functionContext: false,
functionLanguage: false, functionLanguage: false,
triggerSql: false,
triggerStatementInCreation: false,
triggerMultipleEvents: false, triggerMultipleEvents: false,
triggerTableInName: false, triggerTableInName: false,
triggerUpdateColumns: false, triggerUpdateColumns: false,

View File

@ -51,6 +51,7 @@ module.exports = {
procedureDataAccess: true, procedureDataAccess: true,
procedureSql: 'BEGIN\r\n\r\nEND', procedureSql: 'BEGIN\r\n\r\nEND',
procedureContext: true, procedureContext: true,
triggerSql: 'BEGIN\r\n\r\nEND',
functionDeterministic: true, functionDeterministic: true,
functionDataAccess: true, functionDataAccess: true,
functionSql: 'BEGIN\r\n\r\nEND', functionSql: 'BEGIN\r\n\r\nEND',

View File

@ -14,12 +14,13 @@ module.exports = {
tables: true, tables: true,
views: true, views: true,
triggers: true, triggers: true,
triggerFunctions: true,
routines: true, routines: true,
functions: true, functions: true,
// Settings // Settings
tableAdd: true, tableAdd: true,
viewAdd: true, viewAdd: true,
triggerAdd: false, triggerAdd: true,
routineAdd: true, routineAdd: true,
functionAdd: true, functionAdd: true,
databaseEdit: false, databaseEdit: false,
@ -38,6 +39,8 @@ module.exports = {
functionSql: '$BODY$\r\n\r\n$BODY$', functionSql: '$BODY$\r\n\r\n$BODY$',
functionContext: true, functionContext: true,
functionLanguage: true, functionLanguage: true,
triggerSql: 'EXECUTE PROCEDURE ',
triggerStatementInCreation: true,
triggerMultipleEvents: true, triggerMultipleEvents: true,
triggerTableInName: true, triggerTableInName: true,
triggerOnlyRename: false, triggerOnlyRename: false,

View File

@ -344,6 +344,7 @@ export default {
else { else {
try { try {
const res = await Connection.makeTest(this.connection); const res = await Connection.makeTest(this.connection);
console.log(res.response);
if (res.status === 'error') if (res.status === 'error')
this.toast = { status: 'error', message: res.response.message }; this.toast = { status: 'error', message: res.response.message };
else else

View File

@ -25,7 +25,7 @@
> >
</div> </div>
</div> </div>
<div class="form-group"> <div v-if="customizations.definer" class="form-group">
<label class="form-label col-4"> <label class="form-label col-4">
{{ $t('word.definer') }} {{ $t('word.definer') }}
</label> </label>
@ -75,26 +75,52 @@
<option>BEFORE</option> <option>BEFORE</option>
<option>AFTER</option> <option>AFTER</option>
</select> </select>
<select v-model="localTrigger.event" class="form-select"> <select
<option>INSERT</option> v-if="!customizations.triggerMultipleEvents"
<option>UPDATE</option> v-model="localTrigger.event"
<option>DELETE</option> class="form-select"
>
<option v-for="event in Object.keys(localEvents)" :key="event">
{{ event }}
</option>
</select> </select>
<div v-if="customizations.triggerMultipleEvents" class="px-4">
<label
v-for="event in Object.keys(localEvents)"
:key="event"
class="form-checkbox form-inline"
@change.prevent="changeEvents(event)"
>
<input :checked="localEvents[event]" type="checkbox"><i class="form-icon" /> {{ event }}
</label>
</div>
</div> </div>
</div> </div>
</div> </div>
</form> </form>
<div v-if="customizations.triggerStatementInCreation" class="workspace-query-results column col-12 mt-2">
<label class="form-label ml-2">{{ $t('message.triggerStatement') }}</label>
<QueryEditor
ref="queryEditor"
:value.sync="localTrigger.sql"
:workspace="workspace"
:schema="schema"
:height="editorHeight"
/>
</div>
</div> </div>
</ConfirmModal> </ConfirmModal>
</template> </template>
<script> <script>
import ConfirmModal from '@/components/BaseConfirmModal'; import ConfirmModal from '@/components/BaseConfirmModal';
import QueryEditor from '@/components/QueryEditor';
export default { export default {
name: 'ModalNewTrigger', name: 'ModalNewTrigger',
components: { components: {
ConfirmModal ConfirmModal,
QueryEditor
}, },
props: { props: {
workspace: Object workspace: Object
@ -103,13 +129,15 @@ export default {
return { return {
localTrigger: { localTrigger: {
definer: '', definer: '',
sql: 'BEGIN\r\n\r\nEND', sql: '',
name: '', name: '',
table: '', table: '',
activation: 'BEFORE', activation: 'BEFORE',
event: 'INSERT' event: 'INSERT'
}, },
isOptionsChanging: false isOptionsChanging: false,
localEvents: { INSERT: false, UPDATE: false, DELETE: false },
editorHeight: 150
}; };
}, },
computed: { computed: {
@ -122,11 +150,16 @@ export default {
.map(schema => schema.tables); .map(schema => schema.tables);
return schemaTables.length ? schemaTables[0].filter(table => table.type === 'table') : []; return schemaTables.length ? schemaTables[0].filter(table => table.type === 'table') : [];
},
customizations () {
return this.workspace.customizations;
} }
}, },
mounted () { created () {
this.localTrigger.table = this.schemaTables.length ? this.schemaTables[0].name : ''; this.localTrigger.table = this.schemaTables.length ? this.schemaTables[0].name : '';
this.localTrigger.sql = this.customizations.triggerSql;
},
mounted () {
setTimeout(() => { setTimeout(() => {
this.$refs.firstInput.focus(); this.$refs.firstInput.focus();
}, 20); }, 20);
@ -134,6 +167,16 @@ export default {
methods: { methods: {
confirmNewTrigger () { confirmNewTrigger () {
this.$emit('open-create-trigger-editor', this.localTrigger); this.$emit('open-create-trigger-editor', this.localTrigger);
},
changeEvents (event) {
if (this.customizations.triggerMultipleEvents) {
this.localEvents[event] = !this.localEvents[event];
this.localTrigger.event = [];
for (const key in this.localEvents) {
if (this.localEvents[key])
this.localTrigger.event.push(key);
}
}
} }
} }
}; };

View File

@ -209,6 +209,9 @@ export default {
}, },
connectionName () { connectionName () {
return this.getConnectionName(this.connection.uid); return this.getConnectionName(this.connection.uid);
},
customizations () {
return this.workspace.customizations;
} }
}, },
watch: { watch: {
@ -363,7 +366,8 @@ export default {
if (status === 'success') { if (status === 'success') {
await this.refresh(); await this.refresh();
this.changeBreadcrumbs({ schema: this.selectedDatabase, trigger: payload.name }); const triggerName = this.customizations.triggerTableInName ? `${payload.table}.${payload.name}` : payload.name;
this.changeBreadcrumbs({ schema: this.selectedDatabase, trigger: triggerName });
this.selectTab({ uid: this.workspace.uid, tab: 'prop' }); this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
} }
else else