1
1
mirror of https://github.com/Fabio286/antares.git synced 2024-12-25 08:20:39 +01:00

fix: unable to rename views

This commit is contained in:
Fabio Di Stasio 2020-12-27 13:14:41 +01:00
parent b6b7be098a
commit b7053bdf80
2 changed files with 19 additions and 3 deletions

View File

@ -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);
}

View File

@ -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