mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-03 09:49:32 +02:00
Add new database fields
This commit is contained in:
parent
eeeb27161c
commit
0d86dab5fe
5 changed files with 89 additions and 6 deletions
|
@ -42,8 +42,12 @@ export interface CategoryAttributesVersion3 {
|
|||
blockAllNotifications: boolean
|
||||
}
|
||||
|
||||
export interface CategoryAttributesVersion4 {
|
||||
timeWarningFlags: number
|
||||
}
|
||||
|
||||
export type CategoryAttributes = CategoryAttributesVersion1 & CategoryAttributesVersion2 &
|
||||
CategoryAttributesVersion3
|
||||
CategoryAttributesVersion3 & CategoryAttributesVersion4
|
||||
|
||||
export type CategoryInstance = Sequelize.Instance<CategoryAttributes> & CategoryAttributes
|
||||
export type CategoryModel = Sequelize.Model<CategoryInstance, CategoryAttributes>
|
||||
|
@ -94,10 +98,28 @@ export const attributesVersion3: SequelizeAttributes<CategoryAttributesVersion3>
|
|||
}
|
||||
}
|
||||
|
||||
export const attributesVersion4: SequelizeAttributes<CategoryAttributesVersion4> = {
|
||||
timeWarningFlags: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
min: 0,
|
||||
max: 1 | 2 | 4 | 8 | 16
|
||||
// 1 => 1 minute
|
||||
// 2 => 3 minutes
|
||||
// 4 => 5 minutes
|
||||
// 8 => 10 minutes
|
||||
// 16 => 15 minutes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<CategoryAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2,
|
||||
...attributesVersion3
|
||||
...attributesVersion3,
|
||||
...attributesVersion4
|
||||
}
|
||||
|
||||
export const createCategoryModel = (sequelize: Sequelize.Sequelize): CategoryModel => sequelize.define<CategoryInstance, CategoryAttributes>('Category', attributes)
|
||||
|
|
|
@ -84,10 +84,14 @@ export interface DeviceAttributesVersion9 {
|
|||
activityLevelBlocking: boolean
|
||||
}
|
||||
|
||||
export interface DeviceAttributesVersion10 {
|
||||
isQorLater: boolean
|
||||
}
|
||||
|
||||
export type DeviceAttributes = DeviceAttributesVersion1 & DeviceAttributesVersion2 &
|
||||
DeviceAttributesVersion3 & DeviceAttributesVersion4 & DeviceAttributesVersion5 &
|
||||
DeviceAttributesVersion6 & DeviceAttributesVersion7 & DeviceAttributesVersion8 &
|
||||
DeviceAttributesVersion9
|
||||
DeviceAttributesVersion9 & DeviceAttributesVersion10
|
||||
|
||||
export type DeviceInstance = Sequelize.Instance<DeviceAttributes> & DeviceAttributes
|
||||
export type DeviceModel = Sequelize.Model<DeviceInstance, DeviceAttributes>
|
||||
|
@ -220,6 +224,13 @@ export const attributesVersion9: SequelizeAttributes<DeviceAttributesVersion9> =
|
|||
}
|
||||
}
|
||||
|
||||
export const attributesVersion10: SequelizeAttributes<DeviceAttributesVersion10> = {
|
||||
isQorLater: {
|
||||
...booleanColumn,
|
||||
defaultValue: false
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2,
|
||||
|
@ -229,7 +240,8 @@ export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
|||
...attributesVersion6,
|
||||
...attributesVersion7,
|
||||
...attributesVersion8,
|
||||
...attributesVersion9
|
||||
...attributesVersion9,
|
||||
...attributesVersion10
|
||||
}
|
||||
|
||||
export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModel => sequelize.define<DeviceInstance, DeviceAttributes>('Device', attributes)
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 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 } from 'sequelize'
|
||||
import { attributes as categoryAttributes } from '../../category'
|
||||
import { attributesVersion10 as deviceAttributes } from '../../device'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: 'EXCLUSIVE'
|
||||
}, async (transaction) => {
|
||||
await queryInterface.addColumn('Devices', 'isQorLater', {
|
||||
...deviceAttributes.isQorLater
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
|
||||
await queryInterface.addColumn('Categories', 'timeWarningFlags', {
|
||||
...categoryAttributes.timeWarningFlags
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: 'EXCLUSIVE'
|
||||
}, async (transaction) => {
|
||||
await queryInterface.removeColumn('Devices', 'isQorLater', { transaction })
|
||||
await queryInterface.removeColumn('Categories', 'timeWarningFlags', { transaction })
|
||||
})
|
||||
}
|
|
@ -60,5 +60,6 @@ export const prepareDeviceEntry = ({ familyId, userId, deviceAuthToken, deviceId
|
|||
highestOverlayPermission: 'not granted',
|
||||
asEnabled: false,
|
||||
wasAsEnabled: false,
|
||||
activityLevelBlocking: false
|
||||
activityLevelBlocking: false,
|
||||
isQorLater: false
|
||||
})
|
||||
|
|
|
@ -51,7 +51,8 @@ export async function dispatchCreateCategory ({ action, cache }: {
|
|||
assignedAppsVersion: generateVersionId(),
|
||||
usedTimesVersion: generateVersionId(),
|
||||
parentCategoryId: '',
|
||||
blockAllNotifications: false
|
||||
blockAllNotifications: false,
|
||||
timeWarningFlags: 0
|
||||
}, { transaction: cache.transaction })
|
||||
|
||||
// update the cache
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue