Add support for more limits

This commit is contained in:
Jonas Lochmann
2020-05-18 02:00:00 +02:00
parent d021497e52
commit ef1b19a01c
79 changed files with 2785 additions and 136 deletions
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2020 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
@@ -24,7 +24,7 @@ import { attributes as categoryAppAttributes } from '../../categoryapp'
import { attributesVersion1 as deviceAttributes } from '../../device'
import { attributes as familyAttributes } from '../../family'
import { attributes as purchaseAttributes } from '../../purchase'
import { attributes as timelimitruleAttributes } from '../../timelimitrule'
import { attributesVersion1 as timelimitruleAttributes } from '../../timelimitrule'
import { attributesVersion1 as usedTimeAttribute } from '../../usedtime'
import { attributesVersion1 as userAttributes } from '../../user'
@@ -0,0 +1,88 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 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
* published by the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { QueryInterface, Sequelize, Transaction } from 'sequelize'
import { MinuteOfDay } from '../../../util/minuteofday'
import { attributesVersion1 as sessionDurationAttributes } from '../../sessionduration'
import { attributesVersion2 as timelimitRuleAttributes } from '../../timelimitrule'
import {
attributesVersion1 as usedTimeAttributesVersion1,
attributesVersion2 as usedTimeAttributesVersion2,
attributesVersion3 as usedTimeAttributesVersion3
} from '../../usedtime'
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
// session durations
await queryInterface.createTable('SessionDurations', sessionDurationAttributes, { transaction })
// timelimit rule table
await queryInterface.addColumn('TimelimitRules', 'startMinuteOfDay', {
...timelimitRuleAttributes.startMinuteOfDay
}, { transaction })
await queryInterface.addColumn('TimelimitRules', 'endMinuteOfDay', {
...timelimitRuleAttributes.endMinuteOfDay
}, { transaction })
await queryInterface.addColumn('TimelimitRules', 'sessionDurationMilliseconds', {
...timelimitRuleAttributes.sessionDurationMilliseconds
}, { transaction })
await queryInterface.addColumn('TimelimitRules', 'sessionPauseMilliseconds', {
...timelimitRuleAttributes.sessionPauseMilliseconds
}, { transaction })
// used times
await queryInterface.renameTable('UsedTimes', 'UsedTimesOld', { transaction })
await queryInterface.createTable('UsedTimes', {
...usedTimeAttributesVersion1,
...usedTimeAttributesVersion2,
...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 })
await queryInterface.dropTable('UsedTimesOld', { transaction })
})
}
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
// session durations
await queryInterface.dropTable('SessionDurations', { transaction })
// timelimit rule table
await queryInterface.removeColumn('TimelimitRules', 'startMinuteOfDay', { transaction })
await queryInterface.removeColumn('TimelimitRules', 'endMinuteOfDay', { transaction })
await queryInterface.removeColumn('TimelimitRules', 'sessionDurationMilliseconds', { transaction })
await queryInterface.removeColumn('TimelimitRules', 'sessionPauseMilliseconds', { transaction })
// used times
throw new Error('not implemented')
})
}