Gulpfile refactor, SQL scripts
This commit is contained in:
parent
89c745244a
commit
90ce07881a
11
gulpfile.js
11
gulpfile.js
|
@ -1,9 +1,6 @@
|
||||||
require('require-yaml');
|
require('require-yaml');
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const gutil = require('gulp-util');
|
const gutil = require('gulp-util');
|
||||||
const wrap = require('gulp-wrap');
|
|
||||||
const concat = require('gulp-concat');
|
|
||||||
const merge = require('merge-stream');
|
|
||||||
const print = require('gulp-print');
|
const print = require('gulp-print');
|
||||||
const runSequence = require('run-sequence');
|
const runSequence = require('run-sequence');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
|
@ -108,9 +105,8 @@ gulp.task('build', ['clean'], () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('docker-compose', async () => {
|
gulp.task('docker-compose', async () => {
|
||||||
let compose = await fs.readFile('./docker-compose.tpl.yml', 'utf8');
|
|
||||||
|
|
||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
|
let compose = await fs.readFile('./docker-compose.tpl.yml', 'utf8');
|
||||||
let composeYml = yaml.safeLoad(compose);
|
let composeYml = yaml.safeLoad(compose);
|
||||||
let services = await getServices();
|
let services = await getServices();
|
||||||
|
|
||||||
|
@ -253,6 +249,8 @@ let localeFiles = `${srcDir}/**/locale/*.json`;
|
||||||
gulp.task('locales', function() {
|
gulp.task('locales', function() {
|
||||||
const extend = require('gulp-extend');
|
const extend = require('gulp-extend');
|
||||||
const yaml = require('gulp-yaml');
|
const yaml = require('gulp-yaml');
|
||||||
|
const merge = require('merge-stream');
|
||||||
|
|
||||||
let streams = [];
|
let streams = [];
|
||||||
|
|
||||||
for (let mod in modules)
|
for (let mod in modules)
|
||||||
|
@ -272,6 +270,9 @@ gulp.task('locales', function() {
|
||||||
let routeFiles = `${srcDir}/**/routes.json`;
|
let routeFiles = `${srcDir}/**/routes.json`;
|
||||||
|
|
||||||
gulp.task('routes', function() {
|
gulp.task('routes', function() {
|
||||||
|
const concat = require('gulp-concat');
|
||||||
|
const wrap = require('gulp-wrap');
|
||||||
|
|
||||||
return gulp.src(routeFiles)
|
return gulp.src(routeFiles)
|
||||||
.pipe(concat('routes.js', {newLine: ','}))
|
.pipe(concat('routes.js', {newLine: ','}))
|
||||||
.pipe(wrap('var routes = [<%=contents%>\n];'))
|
.pipe(wrap('var routes = [<%=contents%>\n];'))
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
DROP PROCEDURE IF EXISTS mysql.truncateAll;
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE PROCEDURE mysql.truncateAll()
|
||||||
|
BEGIN
|
||||||
|
DECLARE vSchema VARCHAR(255);
|
||||||
|
DECLARE vTable VARCHAR(255);
|
||||||
|
DECLARE vDone BOOL;
|
||||||
|
|
||||||
|
DECLARE cTables CURSOR FOR
|
||||||
|
SELECT `TABLE_SCHEMA`, `TABLE_NAME`
|
||||||
|
FROM `information_schema`.`TABLES`
|
||||||
|
WHERE `TABLE_TYPE` = 'BASE TABLE'
|
||||||
|
AND `TABLE_ROWS` > 0
|
||||||
|
AND `TABLE_SCHEMA` NOT IN ('information_schema', 'mysql', 'performance_schema');
|
||||||
|
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = FALSE;
|
||||||
|
OPEN cTables;
|
||||||
|
|
||||||
|
l: LOOP
|
||||||
|
SET vDone = FALSE;
|
||||||
|
FETCH cTables INTO vSchema, vTable;
|
||||||
|
|
||||||
|
IF vDone THEN
|
||||||
|
LEAVE l;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SET @stmt = CONCAT('TRUNCATE TABLE `', vSchema, '`.`', vTable, '`');
|
||||||
|
PREPARE stmt FROM @stmt;
|
||||||
|
EXECUTE stmt;
|
||||||
|
DEALLOCATE PREPARE stmt;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
CLOSE cTables;
|
||||||
|
SET FOREIGN_KEY_CHECKS = TRUE;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,25 @@
|
||||||
|
CREATE OR REPLACE
|
||||||
|
ALGORITHM = UNDEFINED
|
||||||
|
DEFINER = `root`@`%`
|
||||||
|
SQL SECURITY DEFINER
|
||||||
|
VIEW `vn`.`agencyMode` AS
|
||||||
|
SELECT
|
||||||
|
`a`.`Id_Agencia` AS `id`,
|
||||||
|
`a`.`Agencia` AS `name`,
|
||||||
|
`a`.`description` AS `description`,
|
||||||
|
`a`.`Vista` AS `deliveryMethodFk`,
|
||||||
|
`a`.`Vista` AS `__deliveryMethod`,
|
||||||
|
`a`.`Vista` AS `__view`,
|
||||||
|
`a`.`m3` AS `m3`,
|
||||||
|
`a`.`cod71` AS `cod71`,
|
||||||
|
`a`.`web` AS `web`,
|
||||||
|
`a`.`agency_id` AS `agencyFk`,
|
||||||
|
`a`.`agency_id` AS `__agency`,
|
||||||
|
`a`.`agency_service_id` AS `agencyServiceFk`,
|
||||||
|
`a`.`agency_service_id` AS `__agencyService`,
|
||||||
|
`a`.`inflacion` AS `inflation`,
|
||||||
|
`a`.`inflacion` AS `__inflacion`,
|
||||||
|
`a`.`is_volumetric` AS `isVolumetric`,
|
||||||
|
`a`.`send_mail` AS `reportMail`
|
||||||
|
FROM
|
||||||
|
`vn2008`.`Agencias` `a`
|
|
@ -0,0 +1,18 @@
|
||||||
|
CREATE OR REPLACE
|
||||||
|
ALGORITHM = UNDEFINED
|
||||||
|
DEFINER = `root`@`%`
|
||||||
|
SQL SECURITY DEFINER
|
||||||
|
VIEW `vn`.`agencyHour` AS
|
||||||
|
SELECT
|
||||||
|
`h`.`agency_hour_id` AS `id`,
|
||||||
|
`h`.`agency_id` AS `agencyFk`,
|
||||||
|
`h`.`agency_id` AS `__agency`,
|
||||||
|
`h`.`week_day` AS `weekDay`,
|
||||||
|
`h`.`warehouse_id` AS `warehouseFk`,
|
||||||
|
`h`.`warehouse_id` AS `__warehouse`,
|
||||||
|
`h`.`province_id` AS `provinceFk`,
|
||||||
|
`h`.`province_id` AS `__province`,
|
||||||
|
`h`.`subtract_day` AS `substractDay`,
|
||||||
|
`h`.`max_hour` AS `maxHour`
|
||||||
|
FROM
|
||||||
|
`vn2008`.`agency_hour` `h`
|
|
@ -0,0 +1,24 @@
|
||||||
|
CREATE OR REPLACE
|
||||||
|
ALGORITHM = UNDEFINED
|
||||||
|
DEFINER = `root`@`%`
|
||||||
|
SQL SECURITY DEFINER
|
||||||
|
VIEW `vn`.`address` AS
|
||||||
|
SELECT
|
||||||
|
`t`.`id_consigna` AS `id`,
|
||||||
|
`t`.`Id_cliente` AS `clientFk`,
|
||||||
|
`t`.`domicilio` AS `street`,
|
||||||
|
`t`.`poblacion` AS `city`,
|
||||||
|
`t`.`codPostal` AS `postalCode`,
|
||||||
|
`t`.`province_id` AS `provinceFk`,
|
||||||
|
`t`.`telefono` AS `phone`,
|
||||||
|
`t`.`movil` AS `mobile`,
|
||||||
|
`t`.`consignatario` AS `nickname`,
|
||||||
|
`t`.`predeterminada` AS `isDefaultAddress`,
|
||||||
|
`t`.`longitude` AS `longitude`,
|
||||||
|
`t`.`latitude` AS `latitude`,
|
||||||
|
`t`.`warehouse_id` AS `warehouseFk`,
|
||||||
|
`t`.`Id_Agencia` AS `agencyFk`,
|
||||||
|
`t`.`isEqualizated` AS `isEqualizated`,
|
||||||
|
`t`.`active` AS `isActive`
|
||||||
|
FROM
|
||||||
|
`vn2008`.`Consignatarios` `t`
|
|
@ -0,0 +1,36 @@
|
||||||
|
USE `account`;
|
||||||
|
CREATE
|
||||||
|
OR REPLACE ALGORITHM = UNDEFINED
|
||||||
|
DEFINER = `root`@`%`
|
||||||
|
SQL SECURITY DEFINER
|
||||||
|
VIEW `account`.`__userRole` AS
|
||||||
|
SELECT
|
||||||
|
`r`.`inheritsFrom` AS `id`
|
||||||
|
FROM
|
||||||
|
(`account`.`roleRole` `r`
|
||||||
|
JOIN `account`.`user` `u` ON ((`u`.`role` = `r`.`role`)))
|
||||||
|
WHERE
|
||||||
|
(`u`.`id` = USERGETID());
|
||||||
|
|
||||||
|
DROP VIEW `account`.`userRole`;
|
||||||
|
|
||||||
|
CREATE TABLE `account`.`userRole` (
|
||||||
|
`userFk` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`roleFk` INT(10) UNSIGNED NOT NULL,
|
||||||
|
PRIMARY KEY (`userFk`, `roleFk`));
|
||||||
|
|
||||||
|
ALTER TABLE `account`.`userRole`
|
||||||
|
ADD INDEX `user` (`userFk` ASC),
|
||||||
|
ADD INDEX `role` (`roleFk` ASC);
|
||||||
|
|
||||||
|
ALTER TABLE `account`.`userRole`
|
||||||
|
ADD CONSTRAINT `user`
|
||||||
|
FOREIGN KEY (`userFk`)
|
||||||
|
REFERENCES `account`.`user` (`id`)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
ON UPDATE CASCADE,
|
||||||
|
ADD CONSTRAINT `role`
|
||||||
|
FOREIGN KEY (`roleFk`)
|
||||||
|
REFERENCES `account`.`role` (`id`)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
ON UPDATE CASCADE;
|
|
@ -0,0 +1,31 @@
|
||||||
|
DROP function IF EXISTS `userHasRoleId`;
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE DEFINER=`root`@`%` FUNCTION `account`.`userHasRoleId`(vRoleId INT) RETURNS tinyint(1)
|
||||||
|
DETERMINISTIC
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Comprueba si el usuario actual tiene asociado un rol.
|
||||||
|
*
|
||||||
|
* @param vRoleId Identificador del rol a comprobar
|
||||||
|
* @return %TRUE si tiene el rol, %FALSE en caso contrario
|
||||||
|
*/
|
||||||
|
DECLARE vHasRole BOOL DEFAULT FALSE;
|
||||||
|
|
||||||
|
SELECT COUNT(*) > 0 INTO vHasRole
|
||||||
|
FROM user u
|
||||||
|
JOIN roleRole r ON r.role = u.role
|
||||||
|
WHERE u.id = userGetId()
|
||||||
|
AND r.inheritsFrom = vRoleId;
|
||||||
|
|
||||||
|
IF NOT vHasRole
|
||||||
|
THEN
|
||||||
|
SELECT COUNT(*) > 0 INTO vHasRole
|
||||||
|
FROM userRole
|
||||||
|
WHERE userFk = userGetId()
|
||||||
|
AND roleFk = vRoleId;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN vHasRole;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue