From b7053bdf8036d027e1685d6b5080d6b927a80e08 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sun, 27 Dec 2020 13:14:41 +0100 Subject: [PATCH] fix: unable to rename views --- src/main/libs/clients/MySQLClient.js | 6 +++++- .../components/WorkspacePropsTabView.vue | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/libs/clients/MySQLClient.js b/src/main/libs/clients/MySQLClient.js index 2acf7df5..39808cc6 100644 --- a/src/main/libs/clients/MySQLClient.js +++ b/src/main/libs/clients/MySQLClient.js @@ -303,7 +303,11 @@ export class MySQLClient extends AntaresCore { */ async alterView (params) { const { view } = params; - const sql = `ALTER ALGORITHM = ${view.algorithm} DEFINER=${view.definer} SQL SECURITY ${view.security} VIEW \`${view.name}\` AS ${view.sql} ${view.updateOption ? `WITH ${view.updateOption} CHECK OPTION` : ''}`; + let sql = `ALTER ALGORITHM = ${view.algorithm} DEFINER=${view.definer} SQL SECURITY ${view.security} VIEW \`${view.oldName}\` AS ${view.sql} ${view.updateOption ? `WITH ${view.updateOption} CHECK OPTION` : ''}`; + + if (view.name !== view.oldName) + sql += `; RENAME TABLE \`${view.oldName}\` TO \`${view.name}\``; + return await this.raw(sql); } diff --git a/src/renderer/components/WorkspacePropsTabView.vue b/src/renderer/components/WorkspacePropsTabView.vue index c6367d24..9f91bbc8 100644 --- a/src/renderer/components/WorkspacePropsTabView.vue +++ b/src/renderer/components/WorkspacePropsTabView.vue @@ -225,7 +225,8 @@ export default { ...mapActions({ addNotification: 'notifications/addNotification', refreshStructure: 'workspaces/refreshStructure', - setUnsavedChanges: 'workspaces/setUnsavedChanges' + setUnsavedChanges: 'workspaces/setUnsavedChanges', + changeBreadcrumbs: 'workspaces/changeBreadcrumbs' }), async getViewData () { if (!this.view) return; @@ -260,14 +261,25 @@ export default { const params = { uid: this.connection.uid, schema: this.schema, - view: this.localView + view: { + ...this.localView, + oldName: this.originalView.name + } }; try { const { status, response } = await Views.alterView(params); if (status === 'success') { + const oldName = this.originalView.name; + await this.refreshStructure(this.connection.uid); + + if (oldName !== this.localView.name) { + this.setUnsavedChanges(false); + this.changeBreadcrumbs({ schema: this.schema, view: this.localView.name }); + } + this.getViewData(); } else