diff --git a/db/Dockerfile b/db/Dockerfile index bedcf75d6..c376e6893 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -1,4 +1,4 @@ -FROM mysql:5.6.42 +FROM mysql:8.0.18 ENV MYSQL_ROOT_PASSWORD root ENV TZ Europe/Madrid @@ -7,36 +7,33 @@ ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y --no-install-recommends curl ca-certificates \ && curl -sL https://apt.verdnatura.es/conf/verdnatura.gpg | apt-key add - \ - && echo "deb http://apt.verdnatura.es/ jessie main" > /etc/apt/sources.list.d/vn.list \ + && echo "deb http://apt.verdnatura.es/ stretch main" > /etc/apt/sources.list.d/vn.list \ && apt-get update \ - && apt-get install -y --allow-unauthenticated vn-mysql \ + && apt-get install -y vn-mysql libmysqlclient21 \ && apt-get purge -y --auto-remove curl ca-certificates \ && rm -rf /var/lib/apt/lists/* -# XXX: Removes the last script line to avoid daemon to be started -RUN cp /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-init.sh \ - && sed -i '$ d' /usr/local/bin/docker-init.sh - -WORKDIR /docker-entrypoint-initdb.d -ARG STAMP=unknown - -COPY import-changes.sh config.ini /docker-entrypoint-initdb.d/import/ -COPY docker.cnf /etc/mysql/mysql.conf.d/ -COPY changes /docker-entrypoint-initdb.d/import/changes - -COPY docker-boot.sh /docker-entrypoint-initdb.d/ -COPY dump /docker-entrypoint-initdb.d/dump +COPY docker/docker.cnf /etc/mysql/conf.d/ +COPY docker/docker-init.sh docker/docker-start.sh /usr/local/bin/ RUN mkdir /mysql-data \ - && /usr/local/bin/docker-init.sh mysqld --datadir /mysql-data \ - && chown -R mysql:mysql /mysql-data \ + && chown -R mysql:mysql /mysql-data + +WORKDIR /docker-entrypoint-initdb.d + +COPY dump dump +COPY docker/docker-boot.sh /docker-entrypoint-initdb.d/ +COPY changes import/changes +COPY import-changes.sh config.ini import/ + +ARG STAMP=unknown +RUN gosu mysql docker-init.sh mysqld \ && rm -rf /docker-entrypoint-initdb.d/* -COPY docker-start.sh /usr/local/bin/ +USER mysql ENTRYPOINT ["docker-start.sh"] -USER mysql -CMD ["mysqld", "--datadir", "/mysql-data"] +CMD ["mysqld"] #HEALTHCHECK --interval=5s --timeout=10s --retries=200 \ # CMD mysqladmin ping -h 127.0.0.1 -u root || exit 1 diff --git a/db/changes/10081-agency/01-zone_getWarehouse.sql b/db/changes/10081-agency/01-zone_getWarehouse.sql index 838c225f8..28478e2cc 100644 --- a/db/changes/10081-agency/01-zone_getWarehouse.sql +++ b/db/changes/10081-agency/01-zone_getWarehouse.sql @@ -6,8 +6,8 @@ USE `vn`$$ CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse`(vAddress INT, vLanded DATE, vWarehouse INT) BEGIN /** -* Devuelve el listado de agencias disponibles para la fecha, - * dirección y warehouse pasadas + * Devuelve el listado de agencias disponibles para la fecha, + * dirección y almacén pasados. * * @param vAddress * @param vWarehouse warehouse @@ -30,7 +30,8 @@ BEGIN JOIN agencyMode am ON am.id = z.agencyModeFk JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk WHERE zw.warehouseFk - GROUP BY z.agencyModeFk; + GROUP BY z.agencyModeFk + ORDER BY agencyMode; DROP TEMPORARY TABLE tmp.zone, diff --git a/db/docker.cnf b/db/docker.cnf deleted file mode 100644 index 2b593b972..000000000 --- a/db/docker.cnf +++ /dev/null @@ -1,4 +0,0 @@ -[mysqld] -innodb_log_file_size = 4M -innodb_autoextend_increment = 4 -innodb_page_size = 8K \ No newline at end of file diff --git a/db/docker-boot.sh b/db/docker/docker-boot.sh similarity index 100% rename from db/docker-boot.sh rename to db/docker/docker-boot.sh diff --git a/db/docker/docker-init.sh b/db/docker/docker-init.sh new file mode 100755 index 000000000..19d13a15d --- /dev/null +++ b/db/docker/docker-init.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +. /usr/local/bin/docker-entrypoint.sh + +mysql_check_config "$@" +docker_setup_env "$@" +docker_create_db_directories + +docker_verify_minimum_env +docker_init_database_dir "$@" +docker_temp_server_start "$@" +docker_setup_db + +docker_process_init_files /docker-entrypoint-initdb.d/* + +mysql_expire_root_user +docker_temp_server_stop diff --git a/db/docker-start.sh b/db/docker/docker-start.sh similarity index 100% rename from db/docker-start.sh rename to db/docker/docker-start.sh diff --git a/db/docker/docker.cnf b/db/docker/docker.cnf new file mode 100644 index 000000000..1a0241487 --- /dev/null +++ b/db/docker/docker.cnf @@ -0,0 +1,10 @@ +[mysqld] +innodb_log_file_size = 4M +innodb_autoextend_increment = 4 +innodb_page_size = 8K +innodb_default_row_format = COMPACT +log_bin_trust_function_creators = ON +datadir = /mysql-data +sql_mode = NO_ENGINE_SUBSTITUTION +innodb_temp_data_file_path = /tmp/ibtmp1:12M:autoextend +skip-log-bin diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 4fc94e59e..cb810fa1c 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1,10 +1,13 @@ -- FIXME: cuando se eliminen los procedimientos de la cache, se podra eliminar esta linea CREATE SCHEMA IF NOT EXISTS `vn2008`; +CREATE SCHEMA IF NOT EXISTS `tmp`; +ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root'; ALTER TABLE `vn`.`itemTaxCountry` AUTO_INCREMENT = 1; ALTER TABLE `vn`.`address` AUTO_INCREMENT = 1; ALTER TABLE `vn`.`zoneGeo` AUTO_INCREMENT = 1; +ALTER TABLE `vn`.`ticket` AUTO_INCREMENT = 1; INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) VALUES diff --git a/db/dump/mysqlPlugins.sql b/db/dump/mysqlPlugins.sql index 861db4afe..c3b6f6ee4 100644 --- a/db/dump/mysqlPlugins.sql +++ b/db/dump/mysqlPlugins.sql @@ -1,4 +1,4 @@ -- Import compiled functions CREATE AGGREGATE FUNCTION minacum RETURNS INT SONAME 'minacum.so'; -CREATE AGGREGATE FUNCTION multimax RETURNS INT SONAME 'multimax.so'; \ No newline at end of file +CREATE AGGREGATE FUNCTION multimax RETURNS INT SONAME 'multimax.so'; diff --git a/e2e/paths/06-claim-module/02_development.spec.js b/e2e/paths/06-claim-module/02_development.spec.js index 7df38e945..7ee94497f 100644 --- a/e2e/paths/06-claim-module/02_development.spec.js +++ b/e2e/paths/06-claim-module/02_development.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; -describe('Claim development', () => { +fdescribe('Claim development', () => { const nightmare = createNightmare(); beforeAll(() => { @@ -116,16 +116,12 @@ describe('Claim development', () => { const responsible = await nightmare .waitToGetProperty(`${selectors.claimDevelopment.secondClaimResponsibleAutocomplete} input`, 'value'); - const worker = await nightmare - .waitToGetProperty(`${selectors.claimDevelopment.secondClaimWorkerAutocomplete} input`, 'value'); - const redelivery = await nightmare .waitToGetProperty(`${selectors.claimDevelopment.secondClaimRedeliveryAutocomplete} input`, 'value'); expect(reason).toEqual('Prisas'); expect(result).toEqual('Otros daños'); expect(responsible).toEqual('Compradores'); - expect(worker).toEqual('managerNick'); expect(redelivery).toEqual('Cliente'); }); }); diff --git a/loopback/common/methods/vn-model/getSetValues.js b/loopback/common/methods/vn-model/getSetValues.js index 74403e65c..ac6485d3c 100644 --- a/loopback/common/methods/vn-model/getSetValues.js +++ b/loopback/common/methods/vn-model/getSetValues.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { /** * Returns a set of allowed values defined on table scheme @@ -7,7 +9,6 @@ module.exports = Self => { Self.getSetValues = async function(column) { let model = this.app.models[this.modelName].definition; let properties = model.properties; - let columnName; let tableName = this.modelName; let schema = null; @@ -17,35 +18,32 @@ module.exports = Self => { schema = tableSplit.pop() || null; } - if (properties[column]) { - columnName = column; + let property = properties[column]; - if (properties[column].mysql) - columnName = properties[column].mysql.columnName; - } + if (!property) + throw new UserError(`Column does not exist`); - let findColumn = Object.keys(properties).find(prop => { - return properties[prop].mysql && properties[prop].mysql.columnName === column; - }); + let columnName = property.mysql + ? property.mysql.columnName + : column; - if (findColumn) - columnName = properties[findColumn].mysql.columnName; - - let type = await this.rawSql( - `SELECT DISTINCT column_type FROM information_schema.columns + let columnInfo = await this.rawSql( + `SELECT column_type columnType + FROM information_schema.columns WHERE table_name = ? AND table_schema = IFNULL(?, DATABASE()) AND column_name = ?`, [tableName, schema, columnName] ); - if (!type) return; + if (!columnInfo || !columnInfo[0]) + throw new UserError(`Cannot fetch column values`); let setValues; - setValues = type[0].column_type; - setValues = setValues.replace(/set\((.*)\)/i, '$1'); - setValues = setValues.replace(/'/g, ''); - setValues = setValues.match(new RegExp(/(\w+)+/, 'ig')); + setValues = columnInfo[0].columnType + .replace(/^set\((.*)\)$/i, '$1') + .replace(/'/g, '') + .match(new RegExp(/(\w+)+/, 'ig')); let values = []; setValues.forEach(setValue => { diff --git a/loopback/common/methods/vn-model/specs/getSetValues.spec.js b/loopback/common/methods/vn-model/specs/getSetValues.spec.js index d14a9113f..cd64697c9 100644 --- a/loopback/common/methods/vn-model/specs/getSetValues.spec.js +++ b/loopback/common/methods/vn-model/specs/getSetValues.spec.js @@ -13,11 +13,4 @@ describe('Model getSetValues()', () => { expect(result.length).toEqual(6); expect(result[5].value).toEqual('TABLET_VN'); }); - - it('should return an array of set values from table column source_app', async() => { - let result = await app.models.Order.getSetValues('source_app'); - - expect(result.length).toEqual(6); - expect(result[5].value).toEqual('TABLET_VN'); - }); }); diff --git a/modules/worker/back/methods/worker-calendar/specs/absences.spec.js b/modules/worker/back/methods/worker-calendar/specs/absences.spec.js index 6cc204e28..a306d9e39 100644 --- a/modules/worker/back/methods/worker-calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/worker-calendar/specs/absences.spec.js @@ -34,7 +34,11 @@ describe('Worker absences()', () => { let workerFk = 106; let worker = await app.models.WorkerLabour.findById(workerFk); let endedDate = worker.ended; - await worker.updateAttributes({ended: null}); + + await app.models.WorkerLabour.rawSql( + `UPDATE postgresql.business SET date_end = ? WHERE business_id = ?`, + [null, worker.businessFk] + ); let ctx = {req: {accessToken: {userId: 9}}}; @@ -63,7 +67,10 @@ describe('Worker absences()', () => { expect(sixthType).toEqual('Holidays'); // restores the contract end date - await worker.updateAttributes({ended: endedDate}); + await app.models.WorkerLabour.rawSql( + `UPDATE postgresql.business SET date_end = ? WHERE business_id = ?`, + [endedDate, worker.businessFk] + ); }); it('should give the same holidays as worked days since the holidays amount matches the amount of days in a year', async() => { @@ -112,7 +119,10 @@ describe('Worker absences()', () => { startingContract.setMonth(today.getMonth()); startingContract.setDate(1); - await contract.updateAttributes({started: startingContract}); + await app.models.WorkerLabour.rawSql( + `UPDATE postgresql.business SET date_start = ? WHERE business_id = ?`, + [startingContract, contract.businessFk] + ); let ctx = {req: {accessToken: {userId: 106}}}; let workerFk = 106; @@ -148,6 +158,10 @@ describe('Worker absences()', () => { days: originalHolidaysValue } ); - await contract.updateAttributes({started: contractStartDate}); + + await app.models.WorkerLabour.rawSql( + `UPDATE postgresql.business SET date_start = ? WHERE business_id = ?`, + [contractStartDate, contract.businessFk] + ); }); });