From 193588da45bca49bbfd377ea15366a6e5ce33f56 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 7 Feb 2022 15:43:12 +0100 Subject: [PATCH] Preserve characteristics on pull --- README.md | 2 +- exporters/event.ejs | 22 ++++++++++++---------- exporters/event.js | 19 +++++++++++++++++-- exporters/function.ejs | 17 +++++++++++++++-- exporters/function.js | 20 +++++++++++++++++++- exporters/function.sql | 9 ++++++--- exporters/procedure.ejs | 11 ++++++++++- exporters/procedure.js | 20 +++++++++++++++++++- exporters/procedure.sql | 3 +++ exporters/view.ejs | 6 ++++-- exporters/view.js | 12 ++++++++++++ package.json | 2 +- 12 files changed, 119 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index e27dde1..a145d79 100644 --- a/README.md +++ b/README.md @@ -209,11 +209,11 @@ start a small project. ## Todo -* Preserve all characteristics on pull: comments, SQL mode, READS SQL DATA... * Undo changes when there is an error applying a version using "undo" files. * Use a custom *Dockerfile* for local database container. * Console logging via events. * Lock version table row when pushing. +* Preserve all characteristics on pull: SQL mode, character set, algorithm... ## Built With diff --git a/exporters/event.ejs b/exporters/event.ejs index 9d01636..60ea855 100755 --- a/exporters/event.ejs +++ b/exporters/event.ejs @@ -1,19 +1,21 @@ DROP EVENT IF EXISTS <%- schema %>.<%- name %>; DELIMITER $$ -CREATE DEFINER=<%- definer %> EVENT <%- schema %>.<%- name %> - ON SCHEDULE <% -if (type == 'RECURRING') { - %>EVERY <%- intervalValue %> <%- intervalField %><% +CREATE DEFINER=<%- definer %> EVENT <%- schema %>.<%- name %><% +if (type == 'RECURRING') { %> + ON SCHEDULE EVERY <%- intervalValue %> <%- intervalField %><% if (starts) { %> STARTS <%- starts %><% - } %><% - if (ends) { %> + } + if (ends) { %> ENDS <%- ends %><% - } %><% -} else { - %>AT <%- executeAt %><% + } +} else { %> + ON SCHEDULE AT <%- executeAt %><% } %> ON COMPLETION <%- onCompletion %> - <% if (status == 'ENABLED') { %>ENABLE<% } else { %>DISABLE<% } %> + <%- status %><% +if (comment) { %> + COMMENT <%- comment %><% +} %> DO <%- body %>$$ DELIMITER ; diff --git a/exporters/event.js b/exporters/event.js index 68095bd..0217864 100644 --- a/exporters/event.js +++ b/exporters/event.js @@ -5,6 +5,21 @@ module.exports = { escapeCols: [ 'starts', 'ends', - 'executeAt' - ] + 'executeAt', + 'comment' + ], + formatter(params) { + let status; + switch(params.status){ + case 'DISABLED': + status = 'DISABLE'; + break; + case 'SLAVESIDE_DISABLED': + status = 'DISABLE ON SLAVE'; + break; + default: + status = 'ENABLE' + } + params.status = status; + } }; diff --git a/exporters/function.ejs b/exporters/function.ejs index c33ed68..3fcc78c 100755 --- a/exporters/function.ejs +++ b/exporters/function.ejs @@ -1,7 +1,20 @@ DROP FUNCTION IF EXISTS <%- schema %>.<%- name %>; DELIMITER $$ CREATE DEFINER=<%- definer %> FUNCTION <%- schema %>.<%- name %>(<%- paramList %>) - RETURNS <%- returns %> - <% if (isDeterministic != 'NO') { %>DETERMINISTIC<% } else { %>NOT DETERMINISTIC<% } %> + RETURNS <%- returns %><% +if (isDeterministic == 'NO') { %> + NOT DETERMINISTIC<% +} else { %> + DETERMINISTIC<% +} +if (dataAccess) { %> + <%- dataAccess %><% +} +if (securityType == 'INVOKER') { %> + SQL SECURITY <%- securityType %><% +} +if (comment) { %> + COMMENT <%- comment %><% +} %> <%- body %>$$ DELIMITER ; diff --git a/exporters/function.js b/exporters/function.js index 028b233..68cb15d 100644 --- a/exporters/function.js +++ b/exporters/function.js @@ -1,5 +1,23 @@ module.exports = { schemaCol: 'db', - nameCol: 'name' + nameCol: 'name', + escapeCols: [ + 'comment' + ], + formatter(params) { + let dataAccess; + switch(params.dataAccess) { + case 'NO_SQL': + dataAccess = 'NO SQL'; + break; + case 'READS_SQL_DATA': + dataAccess = 'READS SQL DATA'; + break; + case 'MODIFIES_SQL_DATA': + dataAccess = 'MODIFIES SQL DATA'; + break; + } + params.dataAccess = dataAccess; + } }; diff --git a/exporters/function.sql b/exporters/function.sql index 5c168bc..854a973 100755 --- a/exporters/function.sql +++ b/exporters/function.sql @@ -4,10 +4,13 @@ SELECT `name`, `definer`, `param_list` AS `paramList`, - `returns`, - `is_deterministic` AS `isDeterministic`, `body`, - `modified` + `sql_data_access` AS `dataAccess`, + `security_type` AS `securityType`, + `comment`, + `modified`, + `is_deterministic` AS `isDeterministic`, + `returns` FROM `mysql`.`proc` WHERE ? AND `type` = 'FUNCTION' ORDER BY `name` diff --git a/exporters/procedure.ejs b/exporters/procedure.ejs index f204c9a..78793f1 100755 --- a/exporters/procedure.ejs +++ b/exporters/procedure.ejs @@ -1,5 +1,14 @@ DROP PROCEDURE IF EXISTS <%- schema %>.<%- name %>; DELIMITER $$ -CREATE DEFINER=<%- definer %> PROCEDURE <%- schema %>.<%- name %>(<%- paramList %>) +CREATE DEFINER=<%- definer %> PROCEDURE <%- schema %>.<%- name %>(<%- paramList %>)<% +if (dataAccess) { %> + <%- dataAccess %><% +} +if (securityType == 'INVOKER') { %> + SQL SECURITY <%- securityType %><% +} +if (comment) { %> + COMMENT <%- comment %><% +} %> <%- body %>$$ DELIMITER ; diff --git a/exporters/procedure.js b/exporters/procedure.js index 028b233..68cb15d 100644 --- a/exporters/procedure.js +++ b/exporters/procedure.js @@ -1,5 +1,23 @@ module.exports = { schemaCol: 'db', - nameCol: 'name' + nameCol: 'name', + escapeCols: [ + 'comment' + ], + formatter(params) { + let dataAccess; + switch(params.dataAccess) { + case 'NO_SQL': + dataAccess = 'NO SQL'; + break; + case 'READS_SQL_DATA': + dataAccess = 'READS SQL DATA'; + break; + case 'MODIFIES_SQL_DATA': + dataAccess = 'MODIFIES SQL DATA'; + break; + } + params.dataAccess = dataAccess; + } }; diff --git a/exporters/procedure.sql b/exporters/procedure.sql index 289d5a6..cfe587e 100755 --- a/exporters/procedure.sql +++ b/exporters/procedure.sql @@ -5,6 +5,9 @@ SELECT `definer`, `param_list` AS `paramList`, `body`, + `sql_data_access` AS `dataAccess`, + `security_type` AS `securityType`, + `comment`, `modified` FROM `mysql`.`proc` WHERE ? AND `type` = 'PROCEDURE' diff --git a/exporters/view.ejs b/exporters/view.ejs index 3a1bd2d..41115c7 100755 --- a/exporters/view.ejs +++ b/exporters/view.ejs @@ -1,5 +1,7 @@ CREATE OR REPLACE DEFINER=<%- definer %> SQL SECURITY <%- securityType %> VIEW <%- schema %>.<%- name %> -AS <%- definition %><% if (checkOption != 'NONE') { %> -WITH CASCADED CHECK OPTION<% } %> +AS <%- definition %><% +if (checkOption != 'NONE') { %> +WITH <%- checkOption %> CHECK OPTION<% +} %> diff --git a/exporters/view.js b/exporters/view.js index 8674215..e098fc3 100644 --- a/exporters/view.js +++ b/exporters/view.js @@ -9,5 +9,17 @@ module.exports = { indent: '\t', reservedWordCase: 'upper' }); + + let algorithm; + switch (params.isUpdatable) { + case 'YES': + algorithm = 'MERGE'; + break; + case 'NO': + algorithm = 'TEMPTABLE'; + break; + default: + algorithm = 'UNDEFINED'; + } } }; diff --git a/package.json b/package.json index 9a9f624..b38e0be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "myvc", - "version": "1.2.7", + "version": "1.2.8", "author": "Verdnatura Levante SL", "description": "MySQL Version Control", "license": "GPL-3.0",