diff --git a/Dockerfile b/Dockerfile index d4c8617..7313ac0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,11 @@ WORKDIR /app/timeoff-management # Copy files from first stage COPY --from=base /app/timeoff-management/ /app/timeoff-management +# 20190118-chnage-type-value-for-api-token.js isn't compatible with mariadb. A fixed version is used to replace it +# Issue comment: https://github.com/timeoff-management/timeoff-management-application/issues/329#issuecomment-488327844 +COPY scripts/20190118-chnage-type-value-for-api-token.js /app/timeoff-management/migrations/ + ADD docker-entrypoint.sh /docker-entrypoint.sh EXPOSE 3000 -ENTRYPOINT ["sh","/docker-entrypoint.sh"] +# ENTRYPOINT ["sh","/docker-entrypoint.sh"] diff --git a/scripts/20190118-chnage-type-value-for-api-token.js b/scripts/20190118-chnage-type-value-for-api-token.js new file mode 100644 index 0000000..7638520 --- /dev/null +++ b/scripts/20190118-chnage-type-value-for-api-token.js @@ -0,0 +1,43 @@ +"use strict"; + +const models = require("../lib/model/db"); + +module.exports = { + up: function(queryInterface, Sequelize) { + return queryInterface.describeTable("Companies").then(attributes => { + if (attributes.integration_api_token.type === "UUID") { + return 1; + } + + return ( + queryInterface + // Create Temp Compaies based on current model definitiom + .createTable("Companies_backup", models.Company.attributes) + .then(() => + queryInterface.sequelize.query("SET FOREIGN_KEY_CHECKS=0;") + ) + .then(() => + queryInterface.sequelize.query( + "INSERT INTO `Companies_backup` (`id`,`name`,`country`,`start_of_new_year`,`createdAt`,`updatedAt`,share_all_absences,ldap_auth_enabled,ldap_auth_config,`date_format`,`company_wide_message`,`mode`,`timezone`,`integration_api_token`,`integration_api_enabled`,`carry_over`) SELECT `id`,`name`,`country`,`start_of_new_year`,`createdAt`,`updatedAt`,share_all_absences,ldap_auth_enabled,ldap_auth_config,`date_format`,`company_wide_message`,`mode`,`timezone`,`integration_api_token`,`integration_api_enabled`,`carry_over` FROM `" + + models.Company.tableName + + "`" + ) + ) + .then(() => queryInterface.dropTable(models.Company.tableName)) + .then(() => + queryInterface.renameTable( + "Companies_backup", + models.Company.tableName + ) + ) + .then(() => queryInterface.sequelize.query("SET FOREIGN_KEY_CHECKS=1;")) + .then(() => queryInterface.addIndex(models.Company.tableName, ["id"])) + ); + }); + }, + + down: function(queryInterface, Sequelize) { + // No way back! + return Promise.resolve(); + } +};