Adjust for postgresql

This commit is contained in:
Jonas Lochmann 2021-01-25 01:00:00 +01:00
parent 99762d5d36
commit 964397cfa9
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
6 changed files with 114 additions and 45 deletions

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * 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 ...usedTimeAttributesVersion3
}, { transaction }) }, { transaction })
await sequelize.query(` const dialect = sequelize.getDialect()
INSERT INTO UsedTimes (familyId, categoryId, dayOfEpoch, usedTime, lastUpdate, startMinuteOfDay, endMinuteOfDay) const isMysql = dialect === 'mysql' || dialect === 'mariadb'
SELECT familyId, categoryId, dayOfEpoch, usedTime, lastUpdate,
${MinuteOfDay.MIN} AS startMinuteOfDay, ${MinuteOfDay.MAX} AS endMinuteOfDay if (isMysql) {
FROM UsedTimesOld await sequelize.query(`
`, { transaction }) 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 }) await queryInterface.dropTable('UsedTimesOld', { transaction })
}) })

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * 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.renameTable('Purchases', 'PurchasesOld', { transaction })
await queryInterface.createTable('Purchases', purchaseAttributes, { transaction }) await queryInterface.createTable('Purchases', purchaseAttributes, { transaction })
await sequelize.query(` const dialect = sequelize.getDialect()
INSERT INTO Purchases (familyId, service, transactionId, type, loggedAt, previousFullVersionEndTime, newFullVersionEndTime) const isMysql = dialect === 'mysql' || dialect === 'mariadb'
SELECT familyId, service, transactionId, type, 0 AS loggedAt, 0 AS previousFullVersionEndTime, loggedAt AS newFullVersionEndTime
FROM PurchasesOld if (isMysql) {
`, { 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 })
} 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 }) await queryInterface.dropTable('PurchasesOld', { transaction })
}) })

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * 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({ await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => { }, async (transaction) => {
await sequelize.query( const dialect = sequelize.getDialect()
'CREATE TABLE `UserLimitLoginCategories`' + const isMysql = dialect === 'mysql' || dialect === 'mariadb'
'(`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 }) 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 })
}
}) })
} }

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * 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({ await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => { }, async (transaction) => {
await sequelize.query( const dialect = sequelize.getDialect()
'CREATE TABLE `CategoryNetworkIds` ' + const isMysql = dialect === 'mysql' || dialect === 'mariadb'
'(`familyId` VARCHAR(10) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' +
'`networkItemId` VARCHAR(6) NOT NULL, `hashedNetworkId` VARCHAR(8) NOT NULL,' + if (isMysql) {
'PRIMARY KEY(`familyId`, `categoryId`, `networkItemId`), FOREIGN KEY(`familyId`, `categoryId`)' + await sequelize.query(
'REFERENCES `Categories`(`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE )', 'CREATE TABLE `CategoryNetworkIds` ' +
{ transaction } '(`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 }
)
}
}) })
} }

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * 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({ await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => { }, async (transaction) => {
await sequelize.query( const dialect = sequelize.getDialect()
'CREATE TABLE `ChildTasks` (' + const isMysql = dialect === 'mysql' || dialect === 'mariadb'
'`familyId` VARCHAR(10) NOT NULL, `taskId` VARCHAR(6) NOT NULL,' +
'`categoryId` VARCHAR(6) NOT NULL, `taskTitle` VARCHAR(50) NOT NULL,' + if (isMysql) {
'`extraTimeDuration` INTEGER NOT NULL, `pendingRequest` INTEGER NOT NULL,' + await sequelize.query(
'`lastGrantTimestamp` LONG NOT NULL,' + 'CREATE TABLE `ChildTasks` (' +
'PRIMARY KEY(`familyId`, `taskId`),' + '`familyId` VARCHAR(10) NOT NULL, `taskId` VARCHAR(6) NOT NULL,' +
'FOREIGN KEY(`familyId`, `categoryId`) REFERENCES `Categories`(`familyId`, `categoryId`) ' + '`categoryId` VARCHAR(6) NOT NULL, `taskTitle` VARCHAR(50) NOT NULL,' +
'ON UPDATE CASCADE ON DELETE CASCADE' + '`extraTimeDuration` INTEGER NOT NULL, `pendingRequest` INTEGER NOT NULL,' +
')', '`lastGrantTimestamp` LONG NOT NULL,' +
{ transaction } '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', { await queryInterface.addColumn('Categories', 'taskListVersion', {
...categoryAttributes.taskListVersion ...categoryAttributes.taskListVersion

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
@ -61,7 +61,7 @@ export const attributesVersion1: SequelizeAttributes<TimelimitRuleAttributesVers
categoryId: { ...idWithinFamilyColumn }, categoryId: { ...idWithinFamilyColumn },
applyToExtraTimeUsage: { ...booleanColumn }, applyToExtraTimeUsage: { ...booleanColumn },
dayMaskAsBitmask: { dayMaskAsBitmask: {
type: Sequelize.TINYINT, type: Sequelize.SMALLINT,
allowNull: false, allowNull: false,
validate: { validate: {
min: 0, min: 0,