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 })
const dialect = sequelize.getDialect()
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
if (isMysql) {
await sequelize.query(` await sequelize.query(`
INSERT INTO UsedTimes (familyId, categoryId, dayOfEpoch, usedTime, lastUpdate, startMinuteOfDay, endMinuteOfDay) INSERT INTO UsedTimes (familyId, categoryId, dayOfEpoch, usedTime, lastUpdate, startMinuteOfDay, endMinuteOfDay)
SELECT familyId, categoryId, dayOfEpoch, usedTime, lastUpdate, SELECT familyId, categoryId, dayOfEpoch, usedTime, lastUpdate,
${MinuteOfDay.MIN} AS startMinuteOfDay, ${MinuteOfDay.MAX} AS endMinuteOfDay ${MinuteOfDay.MIN} AS startMinuteOfDay, ${MinuteOfDay.MAX} AS endMinuteOfDay
FROM UsedTimesOld FROM UsedTimesOld
`, { transaction }) `, { 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 })
const dialect = sequelize.getDialect()
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
if (isMysql) {
await sequelize.query(` await sequelize.query(`
INSERT INTO Purchases (familyId, service, transactionId, type, loggedAt, previousFullVersionEndTime, newFullVersionEndTime) INSERT INTO Purchases (familyId, service, transactionId, type, loggedAt, previousFullVersionEndTime, newFullVersionEndTime)
SELECT familyId, service, transactionId, type, 0 AS loggedAt, 0 AS previousFullVersionEndTime, loggedAt AS newFullVersionEndTime SELECT familyId, service, transactionId, type, 0 AS loggedAt, 0 AS previousFullVersionEndTime, loggedAt AS newFullVersionEndTime
FROM PurchasesOld FROM PurchasesOld
`, { transaction }) `, { 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,6 +21,10 @@ 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) => {
const dialect = sequelize.getDialect()
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
if (isMysql) {
await sequelize.query( await sequelize.query(
'CREATE TABLE `UserLimitLoginCategories`' + 'CREATE TABLE `UserLimitLoginCategories`' +
'(`familyId` VARCHAR(10) NOT NULL, `userId` VARCHAR(6) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' + '(`familyId` VARCHAR(10) NOT NULL, `userId` VARCHAR(6) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' +
@ -29,6 +33,16 @@ export async function up (queryInterface: QueryInterface, sequelize: Sequelize)
) )
await sequelize.query('CREATE INDEX `UserLimitLoginCategoriesIndexCategoryId` ON `UserLimitLoginCategories` (`familyId`, `categoryId`)', { 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,6 +21,10 @@ 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) => {
const dialect = sequelize.getDialect()
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
if (isMysql) {
await sequelize.query( await sequelize.query(
'CREATE TABLE `CategoryNetworkIds` ' + 'CREATE TABLE `CategoryNetworkIds` ' +
'(`familyId` VARCHAR(10) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' + '(`familyId` VARCHAR(10) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' +
@ -29,6 +33,16 @@ export async function up (_: QueryInterface, sequelize: Sequelize) {
'REFERENCES `Categories`(`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE )', 'REFERENCES `Categories`(`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE )',
{ transaction } { 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,6 +22,10 @@ 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) => {
const dialect = sequelize.getDialect()
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
if (isMysql) {
await sequelize.query( await sequelize.query(
'CREATE TABLE `ChildTasks` (' + 'CREATE TABLE `ChildTasks` (' +
'`familyId` VARCHAR(10) NOT NULL, `taskId` VARCHAR(6) NOT NULL,' + '`familyId` VARCHAR(10) NOT NULL, `taskId` VARCHAR(6) NOT NULL,' +
@ -34,6 +38,20 @@ export async function up (queryInterface: QueryInterface, sequelize: Sequelize)
')', ')',
{ transaction } { 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,