diff --git a/src/common/customizations/defaults.js b/src/common/customizations/defaults.js index 89fdd829..8323448b 100644 --- a/src/common/customizations/defaults.js +++ b/src/common/customizations/defaults.js @@ -43,6 +43,10 @@ module.exports = { autoIncrement: false, comment: false, collation: false, + definer: false, arrays: false, - onUpdate: false + onUpdate: false, + viewAlgorithm: false, + viewSqlSecurity: false, + viewUpdateOption: false }; diff --git a/src/common/customizations/mysql.js b/src/common/customizations/mysql.js index 049706ab..33ab3556 100644 --- a/src/common/customizations/mysql.js +++ b/src/common/customizations/mysql.js @@ -42,5 +42,9 @@ module.exports = { autoIncrement: true, comment: true, collation: true, - onUpdate: true + definer: true, + onUpdate: true, + viewAlgorithm: true, + viewSqlSecurity: true, + viewUpdateOption: true }; diff --git a/src/common/customizations/postgresql.js b/src/common/customizations/postgresql.js index 18d24b79..030beb50 100644 --- a/src/common/customizations/postgresql.js +++ b/src/common/customizations/postgresql.js @@ -12,16 +12,17 @@ module.exports = { processesList: true, // Structure tables: true, - views: false, + views: true, triggers: false, routines: false, functions: false, schedulers: false, // Settings tableAdd: true, + viewAdd: true, databaseEdit: false, tableSettings: true, - viewSettings: false, + viewSettings: true, triggerSettings: false, routineSettings: false, functionSettings: false, diff --git a/src/main/libs/clients/PostgreSQLClient.js b/src/main/libs/clients/PostgreSQLClient.js index 7d2cda87..0bc70b7a 100644 --- a/src/main/libs/clients/PostgreSQLClient.js +++ b/src/main/libs/clients/PostgreSQLClient.js @@ -454,17 +454,17 @@ export class PostgreSQLClient extends AntaresCore { * @memberof PostgreSQLClient */ async getViewInformations ({ schema, view }) { - const sql = `SHOW CREATE VIEW \`${schema}\`.\`${view}\``; + const sql = `SELECT "definition" FROM "pg_views" WHERE "viewname"='${view}' AND "schemaname"='${schema}'`; const results = await this.raw(sql); return results.rows.map(row => { return { - algorithm: row['Create View'].match(/(?<=CREATE ALGORITHM=).*?(?=\s)/gs)[0], - definer: row['Create View'].match(/(?<=DEFINER=).*?(?=\s)/gs)[0], - security: row['Create View'].match(/(?<=SQL SECURITY ).*?(?=\s)/gs)[0], - updateOption: row['Create View'].match(/(?<=WITH ).*?(?=\s)/gs) ? row['Create View'].match(/(?<=WITH ).*?(?=\s)/gs)[0] : '', - sql: row['Create View'].match(/(?<=AS ).*?$/gs)[0], - name: row.View + algorithm: '', + definer: '', + security: '', + updateOption: '', + sql: row.definition, + name: view }; })[0]; } @@ -476,7 +476,7 @@ export class PostgreSQLClient extends AntaresCore { * @memberof PostgreSQLClient */ async dropView (params) { - const sql = `DROP VIEW \`${params.view}\``; + const sql = `DROP VIEW ${params.view}`; return await this.raw(sql); } @@ -488,10 +488,10 @@ export class PostgreSQLClient extends AntaresCore { */ async alterView (params) { const { view } = params; - let sql = `ALTER ALGORITHM = ${view.algorithm}${view.definer ? ` DEFINER=${view.definer}` : ''} SQL SECURITY ${view.security} VIEW \`${view.oldName}\` AS ${view.sql} ${view.updateOption ? `WITH ${view.updateOption} CHECK OPTION` : ''}`; + let sql = `CREATE OR REPLACE VIEW ${view.oldName} AS ${view.sql}`; if (view.name !== view.oldName) - sql += `; RENAME TABLE \`${view.oldName}\` TO \`${view.name}\``; + sql += `; ALTER VIEW ${view.oldName} RENAME TO ${view.name}`; return await this.raw(sql); } @@ -503,7 +503,7 @@ export class PostgreSQLClient extends AntaresCore { * @memberof PostgreSQLClient */ async createView (view) { - const sql = `CREATE ALGORITHM = ${view.algorithm} ${view.definer ? `DEFINER=${view.definer} ` : ''}SQL SECURITY ${view.security} VIEW \`${view.name}\` AS ${view.sql} ${view.updateOption ? `WITH ${view.updateOption} CHECK OPTION` : ''}`; + const sql = `CREATE VIEW ${view.name} AS ${view.sql}`; return await this.raw(sql); } @@ -823,33 +823,33 @@ export class PostgreSQLClient extends AntaresCore { * @returns {Array.} view informations * @memberof PostgreSQLClient */ - async getEventInformations ({ schema, scheduler }) { - const sql = `SHOW CREATE EVENT \`${schema}\`.\`${scheduler}\``; - const results = await this.raw(sql); + // async getEventInformations ({ schema, scheduler }) { + // const sql = `SHOW CREATE EVENT \`${schema}\`.\`${scheduler}\``; + // const results = await this.raw(sql); - return results.rows.map(row => { - const schedule = row['Create Event']; - const execution = schedule.includes('EVERY') ? 'EVERY' : 'ONCE'; - const every = execution === 'EVERY' ? row['Create Event'].match(/(?<=EVERY )(\s*([^\s]+)){0,2}/gs)[0].replaceAll('\'', '').split(' ') : []; - const starts = execution === 'EVERY' && schedule.includes('STARTS') ? schedule.match(/(?<=STARTS ').*?(?='\s)/gs)[0] : ''; - const ends = execution === 'EVERY' && schedule.includes('ENDS') ? schedule.match(/(?<=ENDS ').*?(?='\s)/gs)[0] : ''; - const at = execution === 'ONCE' && schedule.includes('AT') ? schedule.match(/(?<=AT ').*?(?='\s)/gs)[0] : ''; + // return results.rows.map(row => { + // const schedule = row['Create Event']; + // const execution = schedule.includes('EVERY') ? 'EVERY' : 'ONCE'; + // const every = execution === 'EVERY' ? row['Create Event'].match(/(?<=EVERY )(\s*([^\s]+)){0,2}/gs)[0].replaceAll('\'', '').split(' ') : []; + // const starts = execution === 'EVERY' && schedule.includes('STARTS') ? schedule.match(/(?<=STARTS ').*?(?='\s)/gs)[0] : ''; + // const ends = execution === 'EVERY' && schedule.includes('ENDS') ? schedule.match(/(?<=ENDS ').*?(?='\s)/gs)[0] : ''; + // const at = execution === 'ONCE' && schedule.includes('AT') ? schedule.match(/(?<=AT ').*?(?='\s)/gs)[0] : ''; - return { - definer: row['Create Event'].match(/(?<=DEFINER=).*?(?=\s)/gs)[0], - sql: row['Create Event'].match(/(?<=DO )(.*)/gs)[0], - name: row.Event, - comment: row['Create Event'].match(/(?<=COMMENT ').*?(?=')/gs) ? row['Create Event'].match(/(?<=COMMENT ').*?(?=')/gs)[0] : '', - state: row['Create Event'].includes('ENABLE') ? 'ENABLE' : row['Create Event'].includes('DISABLE ON SLAVE') ? 'DISABLE ON SLAVE' : 'DISABLE', - preserve: row['Create Event'].includes('ON COMPLETION PRESERVE'), - execution, - every, - starts, - ends, - at - }; - })[0]; - } + // return { + // definer: row['Create Event'].match(/(?<=DEFINER=).*?(?=\s)/gs)[0], + // sql: row['Create Event'].match(/(?<=DO )(.*)/gs)[0], + // name: row.Event, + // comment: row['Create Event'].match(/(?<=COMMENT ').*?(?=')/gs) ? row['Create Event'].match(/(?<=COMMENT ').*?(?=')/gs)[0] : '', + // state: row['Create Event'].includes('ENABLE') ? 'ENABLE' : row['Create Event'].includes('DISABLE ON SLAVE') ? 'DISABLE ON SLAVE' : 'DISABLE', + // preserve: row['Create Event'].includes('ON COMPLETION PRESERVE'), + // execution, + // every, + // starts, + // ends, + // at + // }; + // })[0]; + // } /** * DROP EVENT @@ -857,10 +857,10 @@ export class PostgreSQLClient extends AntaresCore { * @returns {Array.} parameters * @memberof PostgreSQLClient */ - async dropEvent (params) { - const sql = `DROP EVENT \`${params.scheduler}\``; - return await this.raw(sql); - } + // async dropEvent (params) { + // const sql = `DROP EVENT \`${params.scheduler}\``; + // return await this.raw(sql); + // } /** * ALTER EVENT @@ -868,25 +868,25 @@ export class PostgreSQLClient extends AntaresCore { * @returns {Array.} parameters * @memberof PostgreSQLClient */ - async alterEvent (params) { - const { scheduler } = params; + // async alterEvent (params) { + // const { scheduler } = params; - if (scheduler.execution === 'EVERY' && scheduler.every[0].includes('-')) - scheduler.every[0] = `'${scheduler.every[0]}'`; + // if (scheduler.execution === 'EVERY' && scheduler.every[0].includes('-')) + // scheduler.every[0] = `'${scheduler.every[0]}'`; - const sql = `ALTER ${scheduler.definer ? ` DEFINER=${scheduler.definer}` : ''} EVENT \`${scheduler.oldName}\` - ON SCHEDULE - ${scheduler.execution === 'EVERY' - ? `EVERY ${scheduler.every.join(' ')}${scheduler.starts ? ` STARTS '${scheduler.starts}'` : ''}${scheduler.ends ? ` ENDS '${scheduler.ends}'` : ''}` - : `AT '${scheduler.at}'`} - ON COMPLETION${!scheduler.preserve ? ' NOT' : ''} PRESERVE - ${scheduler.name !== scheduler.oldName ? `RENAME TO \`${scheduler.name}\`` : ''} - ${scheduler.state} - COMMENT '${scheduler.comment}' - DO ${scheduler.sql}`; + // const sql = `ALTER ${scheduler.definer ? ` DEFINER=${scheduler.definer}` : ''} EVENT \`${scheduler.oldName}\` + // ON SCHEDULE + // ${scheduler.execution === 'EVERY' + // ? `EVERY ${scheduler.every.join(' ')}${scheduler.starts ? ` STARTS '${scheduler.starts}'` : ''}${scheduler.ends ? ` ENDS '${scheduler.ends}'` : ''}` + // : `AT '${scheduler.at}'`} + // ON COMPLETION${!scheduler.preserve ? ' NOT' : ''} PRESERVE + // ${scheduler.name !== scheduler.oldName ? `RENAME TO \`${scheduler.name}\`` : ''} + // ${scheduler.state} + // COMMENT '${scheduler.comment}' + // DO ${scheduler.sql}`; - return await this.raw(sql, { split: false }); - } + // return await this.raw(sql, { split: false }); + // } /** * CREATE EVENT @@ -894,19 +894,19 @@ export class PostgreSQLClient extends AntaresCore { * @returns {Array.} parameters * @memberof PostgreSQLClient */ - async createEvent (scheduler) { - const sql = `CREATE ${scheduler.definer ? ` DEFINER=${scheduler.definer}` : ''} EVENT \`${scheduler.name}\` - ON SCHEDULE - ${scheduler.execution === 'EVERY' - ? `EVERY ${scheduler.every.join(' ')}${scheduler.starts ? ` STARTS '${scheduler.starts}'` : ''}${scheduler.ends ? ` ENDS '${scheduler.ends}'` : ''}` - : `AT '${scheduler.at}'`} - ON COMPLETION${!scheduler.preserve ? ' NOT' : ''} PRESERVE - ${scheduler.state} - COMMENT '${scheduler.comment}' - DO ${scheduler.sql}`; + // async createEvent (scheduler) { + // const sql = `CREATE ${scheduler.definer ? ` DEFINER=${scheduler.definer}` : ''} EVENT \`${scheduler.name}\` + // ON SCHEDULE + // ${scheduler.execution === 'EVERY' + // ? `EVERY ${scheduler.every.join(' ')}${scheduler.starts ? ` STARTS '${scheduler.starts}'` : ''}${scheduler.ends ? ` ENDS '${scheduler.ends}'` : ''}` + // : `AT '${scheduler.at}'`} + // ON COMPLETION${!scheduler.preserve ? ' NOT' : ''} PRESERVE + // ${scheduler.state} + // COMMENT '${scheduler.comment}' + // DO ${scheduler.sql}`; - return await this.raw(sql, { split: false }); - } + // return await this.raw(sql, { split: false }); + // } /** * SELECT * FROM pg_collation diff --git a/src/renderer/components/ModalNewView.vue b/src/renderer/components/ModalNewView.vue index 093df111..cef429e3 100644 --- a/src/renderer/components/ModalNewView.vue +++ b/src/renderer/components/ModalNewView.vue @@ -25,7 +25,7 @@
-
+
-
+
-
+
-
+
-
+
-
+