diff --git a/src/database/migration/migrations/20200525-add-new-limit-options.ts b/src/database/migration/migrations/20200525-add-new-limit-options.ts index ce05f2a..eda4a98 100644 --- a/src/database/migration/migrations/20200525-add-new-limit-options.ts +++ b/src/database/migration/migrations/20200525-add-new-limit-options.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 - 2020 Jonas Lochmann + * Copyright (C) 2019 - 2021 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -58,12 +58,24 @@ export async function up (queryInterface: QueryInterface, sequelize: Sequelize) ...usedTimeAttributesVersion3 }, { transaction }) - await sequelize.query(` - INSERT INTO UsedTimes (familyId, categoryId, dayOfEpoch, usedTime, lastUpdate, startMinuteOfDay, endMinuteOfDay) - SELECT familyId, categoryId, dayOfEpoch, usedTime, lastUpdate, - ${MinuteOfDay.MIN} AS startMinuteOfDay, ${MinuteOfDay.MAX} AS endMinuteOfDay - FROM UsedTimesOld - `, { transaction }) + const dialect = sequelize.getDialect() + const isMysql = dialect === 'mysql' || dialect === 'mariadb' + + if (isMysql) { + await sequelize.query(` + INSERT INTO UsedTimes (familyId, categoryId, dayOfEpoch, usedTime, lastUpdate, startMinuteOfDay, endMinuteOfDay) + SELECT familyId, categoryId, dayOfEpoch, usedTime, lastUpdate, + ${MinuteOfDay.MIN} AS startMinuteOfDay, ${MinuteOfDay.MAX} AS endMinuteOfDay + FROM UsedTimesOld + `, { transaction }) + } else { + await sequelize.query(` + INSERT INTO "UsedTimes" ("familyId", "categoryId", "dayOfEpoch", "usedTime", "lastUpdate", "startMinuteOfDay", "endMinuteOfDay") + SELECT "familyId", "categoryId", "dayOfEpoch", "usedTime", "lastUpdate", + ${MinuteOfDay.MIN} AS "startMinuteOfDay", ${MinuteOfDay.MAX} AS "endMinuteOfDay" + FROM "UsedTimesOld" + `, { transaction }) + } await queryInterface.dropTable('UsedTimesOld', { transaction }) }) diff --git a/src/database/migration/migrations/20200601-fix-purchase-table.ts b/src/database/migration/migrations/20200601-fix-purchase-table.ts index 65dc2ae..abb2410 100644 --- a/src/database/migration/migrations/20200601-fix-purchase-table.ts +++ b/src/database/migration/migrations/20200601-fix-purchase-table.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 - 2020 Jonas Lochmann + * Copyright (C) 2019 - 2021 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -25,11 +25,22 @@ export async function up (queryInterface: QueryInterface, sequelize: Sequelize) await queryInterface.renameTable('Purchases', 'PurchasesOld', { transaction }) await queryInterface.createTable('Purchases', purchaseAttributes, { transaction }) - await sequelize.query(` - INSERT INTO Purchases (familyId, service, transactionId, type, loggedAt, previousFullVersionEndTime, newFullVersionEndTime) - SELECT familyId, service, transactionId, type, 0 AS loggedAt, 0 AS previousFullVersionEndTime, loggedAt AS newFullVersionEndTime - FROM PurchasesOld - `, { transaction }) + const dialect = sequelize.getDialect() + const isMysql = dialect === 'mysql' || dialect === 'mariadb' + + if (isMysql) { + await sequelize.query(` + INSERT INTO Purchases (familyId, service, transactionId, type, loggedAt, previousFullVersionEndTime, newFullVersionEndTime) + SELECT familyId, service, transactionId, type, 0 AS loggedAt, 0 AS previousFullVersionEndTime, loggedAt AS newFullVersionEndTime + FROM PurchasesOld + `, { transaction }) + } else { + await sequelize.query(` + INSERT INTO "Purchases" ("familyId", service, "transactionId", type, "loggedAt", "previousFullVersionEndTime", "newFullVersionEndTime") + SELECT "familyId", service, "transactionId", type, 0 AS "loggedAt", 0 AS "previousFullVersionEndTime", "loggedAt" AS "newFullVersionEndTime" + FROM "PurchasesOld" + `, { transaction }) + } await queryInterface.dropTable('PurchasesOld', { transaction }) }) diff --git a/src/database/migration/migrations/20200706-create-user-limit-login-category-table.ts b/src/database/migration/migrations/20200706-create-user-limit-login-category-table.ts index 55d9740..a8b9d35 100644 --- a/src/database/migration/migrations/20200706-create-user-limit-login-category-table.ts +++ b/src/database/migration/migrations/20200706-create-user-limit-login-category-table.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 - 2020 Jonas Lochmann + * Copyright (C) 2019 - 2021 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -21,14 +21,28 @@ export async function up (queryInterface: QueryInterface, sequelize: Sequelize) await sequelize.transaction({ type: Transaction.TYPES.EXCLUSIVE }, async (transaction) => { - await sequelize.query( - 'CREATE TABLE `UserLimitLoginCategories`' + - '(`familyId` VARCHAR(10) NOT NULL, `userId` VARCHAR(6) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' + - 'PRIMARY KEY(`familyId`, `userId`), FOREIGN KEY(`familyId`, `userId`) REFERENCES `Users`(`familyId`, `userId`) ON UPDATE CASCADE ON DELETE CASCADE , FOREIGN KEY(`familyId`, `categoryId`) REFERENCES `Categories`(`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE )', - { transaction } - ) + const dialect = sequelize.getDialect() + const isMysql = dialect === 'mysql' || dialect === 'mariadb' - await sequelize.query('CREATE INDEX `UserLimitLoginCategoriesIndexCategoryId` ON `UserLimitLoginCategories` (`familyId`, `categoryId`)', { transaction }) + if (isMysql) { + await sequelize.query( + 'CREATE TABLE `UserLimitLoginCategories`' + + '(`familyId` VARCHAR(10) NOT NULL, `userId` VARCHAR(6) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' + + 'PRIMARY KEY(`familyId`, `userId`), FOREIGN KEY(`familyId`, `userId`) REFERENCES `Users`(`familyId`, `userId`) ON UPDATE CASCADE ON DELETE CASCADE , FOREIGN KEY(`familyId`, `categoryId`) REFERENCES `Categories`(`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE )', + { transaction } + ) + + await sequelize.query('CREATE INDEX `UserLimitLoginCategoriesIndexCategoryId` ON `UserLimitLoginCategories` (`familyId`, `categoryId`)', { transaction }) + } else { + await sequelize.query( + 'CREATE TABLE "UserLimitLoginCategories"' + + '("familyId" VARCHAR(10) NOT NULL, "userId" VARCHAR(6) NOT NULL, "categoryId" VARCHAR(6) NOT NULL,' + + 'PRIMARY KEY("familyId", "userId"), FOREIGN KEY("familyId", "userId") REFERENCES "Users" ("familyId", "userId") ON UPDATE CASCADE ON DELETE CASCADE , FOREIGN KEY("familyId", "categoryId") REFERENCES "Categories" ("familyId", "categoryId") ON UPDATE CASCADE ON DELETE CASCADE )', + { transaction } + ) + + await sequelize.query('CREATE INDEX "UserLimitLoginCategoriesIndexCategoryId" ON "UserLimitLoginCategories" ("familyId", "categoryId")', { transaction }) + } }) } diff --git a/src/database/migration/migrations/20200824-create-category-network-id-table.ts b/src/database/migration/migrations/20200824-create-category-network-id-table.ts index 720adee..54dd7b5 100644 --- a/src/database/migration/migrations/20200824-create-category-network-id-table.ts +++ b/src/database/migration/migrations/20200824-create-category-network-id-table.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 - 2020 Jonas Lochmann + * Copyright (C) 2019 - 2021 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -21,14 +21,28 @@ export async function up (_: QueryInterface, sequelize: Sequelize) { await sequelize.transaction({ type: Transaction.TYPES.EXCLUSIVE }, async (transaction) => { - await sequelize.query( - 'CREATE TABLE `CategoryNetworkIds` ' + - '(`familyId` VARCHAR(10) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' + - '`networkItemId` VARCHAR(6) NOT NULL, `hashedNetworkId` VARCHAR(8) NOT NULL,' + - 'PRIMARY KEY(`familyId`, `categoryId`, `networkItemId`), FOREIGN KEY(`familyId`, `categoryId`)' + - 'REFERENCES `Categories`(`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE )', - { transaction } - ) + const dialect = sequelize.getDialect() + const isMysql = dialect === 'mysql' || dialect === 'mariadb' + + if (isMysql) { + await sequelize.query( + 'CREATE TABLE `CategoryNetworkIds` ' + + '(`familyId` VARCHAR(10) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' + + '`networkItemId` VARCHAR(6) NOT NULL, `hashedNetworkId` VARCHAR(8) NOT NULL,' + + 'PRIMARY KEY(`familyId`, `categoryId`, `networkItemId`), FOREIGN KEY(`familyId`, `categoryId`)' + + 'REFERENCES `Categories`(`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE )', + { transaction } + ) + } else { + await sequelize.query( + 'CREATE TABLE "CategoryNetworkIds" ' + + '("familyId" VARCHAR(10) NOT NULL, "categoryId" VARCHAR(6) NOT NULL,' + + '"networkItemId" VARCHAR(6) NOT NULL, "hashedNetworkId" VARCHAR(8) NOT NULL,' + + 'PRIMARY KEY("familyId", "categoryId", "networkItemId"), FOREIGN KEY("familyId", "categoryId")' + + 'REFERENCES "Categories"("familyId", "categoryId") ON UPDATE CASCADE ON DELETE CASCADE )', + { transaction } + ) + } }) } diff --git a/src/database/migration/migrations/20201116-add-child-tasks.ts b/src/database/migration/migrations/20201116-add-child-tasks.ts index bcf4223..117a3d0 100644 --- a/src/database/migration/migrations/20201116-add-child-tasks.ts +++ b/src/database/migration/migrations/20201116-add-child-tasks.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 - 2020 Jonas Lochmann + * Copyright (C) 2019 - 2021 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -22,18 +22,36 @@ export async function up (queryInterface: QueryInterface, sequelize: Sequelize) await sequelize.transaction({ type: Transaction.TYPES.EXCLUSIVE }, async (transaction) => { - await sequelize.query( - 'CREATE TABLE `ChildTasks` (' + - '`familyId` VARCHAR(10) NOT NULL, `taskId` VARCHAR(6) NOT NULL,' + - '`categoryId` VARCHAR(6) NOT NULL, `taskTitle` VARCHAR(50) NOT NULL,' + - '`extraTimeDuration` INTEGER NOT NULL, `pendingRequest` INTEGER NOT NULL,' + - '`lastGrantTimestamp` LONG NOT NULL,' + - 'PRIMARY KEY(`familyId`, `taskId`),' + - 'FOREIGN KEY(`familyId`, `categoryId`) REFERENCES `Categories`(`familyId`, `categoryId`) ' + - 'ON UPDATE CASCADE ON DELETE CASCADE' + - ')', - { transaction } - ) + const dialect = sequelize.getDialect() + const isMysql = dialect === 'mysql' || dialect === 'mariadb' + + if (isMysql) { + await sequelize.query( + 'CREATE TABLE `ChildTasks` (' + + '`familyId` VARCHAR(10) NOT NULL, `taskId` VARCHAR(6) NOT NULL,' + + '`categoryId` VARCHAR(6) NOT NULL, `taskTitle` VARCHAR(50) NOT NULL,' + + '`extraTimeDuration` INTEGER NOT NULL, `pendingRequest` INTEGER NOT NULL,' + + '`lastGrantTimestamp` LONG NOT NULL,' + + 'PRIMARY KEY(`familyId`, `taskId`),' + + 'FOREIGN KEY(`familyId`, `categoryId`) REFERENCES `Categories`(`familyId`, `categoryId`) ' + + 'ON UPDATE CASCADE ON DELETE CASCADE' + + ')', + { transaction } + ) + } else { + await sequelize.query( + 'CREATE TABLE "ChildTasks" (' + + '"familyId" VARCHAR(10) NOT NULL, "taskId" VARCHAR(6) NOT NULL,' + + '"categoryId" VARCHAR(6) NOT NULL, "taskTitle" VARCHAR(50) NOT NULL,' + + '"extraTimeDuration" INTEGER NOT NULL, "pendingRequest" INTEGER NOT NULL,' + + '"lastGrantTimestamp" BIGINT NOT NULL,' + + 'PRIMARY KEY("familyId", "taskId"),' + + 'FOREIGN KEY("familyId", "categoryId") REFERENCES "Categories"("familyId", "categoryId") ' + + 'ON UPDATE CASCADE ON DELETE CASCADE' + + ')', + { transaction } + ) + } await queryInterface.addColumn('Categories', 'taskListVersion', { ...categoryAttributes.taskListVersion diff --git a/src/database/timelimitrule.ts b/src/database/timelimitrule.ts index 5b3f775..1d0aa1f 100644 --- a/src/database/timelimitrule.ts +++ b/src/database/timelimitrule.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 - 2020 Jonas Lochmann + * Copyright (C) 2019 - 2021 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -61,7 +61,7 @@ export const attributesVersion1: SequelizeAttributes