diff --git a/db/import-changes.sh b/db/import-changes.sh index d9042cf3c..498390b51 100755 --- a/db/import-changes.sh +++ b/db/import-changes.sh @@ -1,5 +1,26 @@ #!/bin/bash +FORCE=FALSE + +usage() { + echo "Usage: $0 [-f] [environment]" + exit 1 +} + +while getopts ":f" option +do + case $option in + f) + FORCE=TRUE + ;; + \?|:) + usage + ;; + esac +done + +shift $(($OPTIND - 1)) + ENV=$1 if [ "$ENV" == "production" ]; then @@ -14,11 +35,13 @@ if [ "$ENV" == "production" ]; then echo "|_| |_|_\ \___/|___/ \___/ \___| |_| |___| \___/|_|\_|" echo "" - read -p "Are you sure? (Default: no) [yes|no]: " ANSWER + if [ "$FORCE" != "TRUE" ]; then + read -p "Are you sure? (Default: no) [yes|no]: " ANSWER - if [ "$ANSWER" != "yes" ]; then - echo "Aborting" - exit; + if [ "$ANSWER" != "yes" ]; then + echo "Aborting" + exit; + fi fi fi if [ -z "$ENV" ]; then @@ -28,15 +51,16 @@ fi INI_FILE="config.$ENV.ini" if [ ! -f "$INI_FILE" ]; then - echo "File $INI_FILE doesn't exists" - exit 1 + echo "Config file doesn't exists: $INI_FILE" + exit 2 fi echo "[INFO] Config file: $INI_FILE" -echo "[INFO] Importing changes." +echo "[INFO] Applying changes" # Import changes for file in install/changes/*.sql; do - echo "[INFO] -> Applying $file" + echo "[INFO] -> $file" mysql --defaults-file="$INI_FILE" < $file done + diff --git a/db/install/changes/0-ACL.sql b/db/install/changes/0-ACL.sql index 099e3c5a9..a2f3991f1 100644 --- a/db/install/changes/0-ACL.sql +++ b/db/install/changes/0-ACL.sql @@ -1,2 +1,4 @@ INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (149, 'Sip', '*', 'WRITE', 'ALLOW', 'ROLE', 'hr'); -INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (150, 'Sip', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file +INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (150, 'Sip', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (151, 'Department','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (152, 'Department','*','WRITE','ALLOW','ROLE','hr'); diff --git a/db/install/changes/12-department.sql b/db/install/changes/12-department.sql new file mode 100644 index 000000000..4203b059e --- /dev/null +++ b/db/install/changes/12-department.sql @@ -0,0 +1,23 @@ +/* Ejecutar en prod * / + +/* USE `vn2008`; + +ALTER TABLE vn2008.department ADD `depth` int DEFAULT 0 NOT NULL; +ALTER TABLE vn2008.department ADD sons int DEFAULT 0 NOT NULL; + +USE `vn`; + +CREATE +OR REPLACE +VIEW `vn`.`department` AS select + `b`.`department_id` AS `id`, + `b`.`name` AS `name`, + `b`.`father_id` AS `fatherFk`, + `b`.`production` AS `isProduction`, + `b`.`lft` AS `lft`, + `b`.`rgt` AS `rgt`, + `b`.`isSelected` AS `isSelected`, + `b`.`depth` AS `depth`, + `b`.`sons` AS `sons` +from + `vn2008`.`department` `b`; */ \ No newline at end of file diff --git a/db/install/changes/13-nodeAdd.sql b/db/install/changes/13-nodeAdd.sql new file mode 100644 index 000000000..f3f4381f3 --- /dev/null +++ b/db/install/changes/13-nodeAdd.sql @@ -0,0 +1,86 @@ +/* Ejecutar en prod * / + +/* DROP PROCEDURE IF EXISTS nst.NodeAdd; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`%` PROCEDURE `nst`.`nodeAdd`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vParentFk` INT, IN `vChild` VARCHAR(100)) +BEGIN + DECLARE vSql TEXT; + DECLARE vTableClone VARCHAR(45); + + SET vTableClone = CONCAT(vTable, 'Clone'); + + CALL util.exec(CONCAT('DROP TEMPORARY TABLE IF EXISTS tmp.', vTableClone)); + CALL util.exec(CONCAT( + 'CREATE TEMPORARY TABLE tmp.', vTableClone, + ' ENGINE = MEMORY' + ' SELECT * FROM ', vScheme, '.', vTable + )); + + -- Check parent childs + SET vSql = sql_printf(' + SELECT COUNT(c.id) INTO @childs + FROM %t.%t p + LEFT JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt AND c.id != %v + WHERE p.id = %v', + vScheme, vTable, 'tmp', vTableClone, vParentFk, vParentFk); + SET @qrySql := vSql; + + PREPARE stmt FROM @qrySql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + + -- Select left from last child + IF @childs = 0 THEN + SET vSql = sql_printf('SELECT lft INTO @vLeft FROM %t.%t WHERE id = %v', vScheme, vTable, vParentFk); + SET @qrySql := vSql; + ELSE + SET vSql = sql_printf(' + SELECT c.rgt INTO @vLeft + FROM %t.%t p + JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt + WHERE p.id = %v + ORDER BY c.lft + DESC LIMIT 1', + vScheme, vTable, 'tmp', vTableClone, vParentFk); + SET @qrySql := vSql; + END IF; + + PREPARE stmt FROM @qrySql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + + -- Update right + SET vSql = sql_printf('UPDATE %t.%t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC', vScheme, vTable, @vLeft); + SET @qrySql := vSql; + + PREPARE stmt FROM @qrySql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + + SET vSql = sql_printf('UPDATE %t.%t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC', vScheme, vTable, @vLeft); + SET @qrySql := vSql; + + PREPARE stmt FROM @qrySql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + + -- Escape character + SET vChild = REPLACE(vChild, "'", "\\'"); + + -- Add child + SET vSql = sql_printf('INSERT INTO %t.%t (name, lft, rgt) VALUES (%v, %v, %v)', vScheme, vTable, vChild, @vLeft + 1, @vLeft + 2); + SET @qrySql := vSql; + + PREPARE stmt FROM @qrySql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + + SELECT id, name, lft, rgt, depth, sons FROM vn.department + WHERE id = LAST_INSERT_ID(); + + CALL util.exec(CONCAT('DROP TEMPORARY TABLE tmp.', vTableClone)); +END$$ +DELIMITER ; + */ \ No newline at end of file diff --git a/db/install/changes/14-nodeRecalc.sql b/db/install/changes/14-nodeRecalc.sql new file mode 100644 index 000000000..73f3042c4 --- /dev/null +++ b/db/install/changes/14-nodeRecalc.sql @@ -0,0 +1,31 @@ +/* Ejecutar en prod * / + +/* DROP PROCEDURE IF EXISTS nst.nodeRecalc; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`%` PROCEDURE `nst`.`nodeRecalc`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45)) +BEGIN + CALL util.exec (sql_printf ( + 'UPDATE %t.%t d + JOIN (SELECT + node.id, + COUNT(parent.id) - 1 as depth, + cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons + FROM + %t.%t AS node, + %t.%t AS parent + WHERE node.lft BETWEEN parent.lft AND parent.rgt + GROUP BY node.id + ORDER BY node.lft) n ON n.id = d.id + SET d.`depth` = n.depth, d.sons = n.sons', + vScheme, + vTable, + vScheme, + vTable, + vScheme, + vTable + )); +END$$ +DELIMITER ; + */ \ No newline at end of file diff --git a/db/install/changes/15-ticketLog.sql b/db/install/changes/15-ticketLog.sql new file mode 100644 index 000000000..e4d5c9e98 --- /dev/null +++ b/db/install/changes/15-ticketLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.itemLog MODIFY COLUMN userFk int(10) unsigned NULL; diff --git a/db/install/changes/15-zoneGeo.sql b/db/install/changes/15-zoneGeo.sql new file mode 100644 index 000000000..1037fe089 --- /dev/null +++ b/db/install/changes/15-zoneGeo.sql @@ -0,0 +1,4 @@ +USE `vn`; + +CREATE UNIQUE INDEX zoneGeo_lft_IDX USING BTREE ON vn.zoneGeo (lft); +CREATE UNIQUE INDEX zoneGeo_rgt_IDX USING BTREE ON vn.zoneGeo (rgt); \ No newline at end of file diff --git a/front/core/components/treeview/child.html b/front/core/components/treeview/child.html index 8589790ec..a079d8f40 100644 --- a/front/core/components/treeview/child.html +++ b/front/core/components/treeview/child.html @@ -1,25 +1,54 @@ -