mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-03 01:39:31 +02:00
Add database migration for activity level blocking
This commit is contained in:
parent
0e601995ec
commit
723f81e46f
5 changed files with 123 additions and 3 deletions
61
src/database/appactivity.ts
Normal file
61
src/database/appactivity.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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 * as Sequelize from 'sequelize'
|
||||
import { familyIdColumn, idWithinFamilyColumn, optionalLabelColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface AppActivityAttributes {
|
||||
familyId: string
|
||||
deviceId: string
|
||||
packageName: string
|
||||
activityName: string
|
||||
title: string
|
||||
}
|
||||
|
||||
export type AppActivityInstance = Sequelize.Instance<AppActivityAttributes> & AppActivityAttributes
|
||||
export type AppActivityModel = Sequelize.Model<AppActivityInstance, AppActivityAttributes>
|
||||
|
||||
export const attributes: SequelizeAttributes<AppActivityAttributes> = {
|
||||
familyId: {
|
||||
...familyIdColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
deviceId: {
|
||||
...idWithinFamilyColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
packageName: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
notEmpty: true
|
||||
},
|
||||
primaryKey: true
|
||||
},
|
||||
activityName: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
notEmpty: true
|
||||
},
|
||||
primaryKey: true
|
||||
},
|
||||
title: { ...optionalLabelColumn }
|
||||
}
|
||||
|
||||
export const createAppActivityModel = (sequelize: Sequelize.Sequelize): AppActivityModel => sequelize.define<AppActivityInstance, AppActivityAttributes>('AppActivity', attributes)
|
|
@ -80,9 +80,14 @@ export interface DeviceAttributesVersion8 {
|
|||
wasAsEnabled: boolean
|
||||
}
|
||||
|
||||
export interface DeviceAttributesVersion9 {
|
||||
activityLevelBlocking: boolean
|
||||
}
|
||||
|
||||
export type DeviceAttributes = DeviceAttributesVersion1 & DeviceAttributesVersion2 &
|
||||
DeviceAttributesVersion3 & DeviceAttributesVersion4 & DeviceAttributesVersion5 &
|
||||
DeviceAttributesVersion6 & DeviceAttributesVersion7 & DeviceAttributesVersion8
|
||||
DeviceAttributesVersion6 & DeviceAttributesVersion7 & DeviceAttributesVersion8 &
|
||||
DeviceAttributesVersion9
|
||||
|
||||
export type DeviceInstance = Sequelize.Instance<DeviceAttributes> & DeviceAttributes
|
||||
export type DeviceModel = Sequelize.Model<DeviceInstance, DeviceAttributes>
|
||||
|
@ -208,6 +213,13 @@ export const attributesVersion8: SequelizeAttributes<DeviceAttributesVersion8> =
|
|||
}
|
||||
}
|
||||
|
||||
export const attributesVersion9: SequelizeAttributes<DeviceAttributesVersion9> = {
|
||||
activityLevelBlocking: {
|
||||
...booleanColumn,
|
||||
defaultValue: false
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2,
|
||||
|
@ -216,7 +228,8 @@ export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
|||
...attributesVersion5,
|
||||
...attributesVersion6,
|
||||
...attributesVersion7,
|
||||
...attributesVersion8
|
||||
...attributesVersion8,
|
||||
...attributesVersion9
|
||||
}
|
||||
|
||||
export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModel => sequelize.define<DeviceInstance, DeviceAttributes>('Device', attributes)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
import * as Sequelize from 'sequelize'
|
||||
import { AddDeviceTokenModel, createAddDeviceTokenModel } from './adddevicetoken'
|
||||
import { AppModel, createAppModel } from './app'
|
||||
import { AppActivityModel, createAppActivityModel } from './appactivity'
|
||||
import { AuthTokenModel, createAuthtokenModel } from './authtoken'
|
||||
import { CategoryModel, createCategoryModel } from './category'
|
||||
import { CategoryAppModel, createCategoryAppModel } from './categoryapp'
|
||||
|
@ -35,6 +36,7 @@ export interface Database {
|
|||
addDeviceToken: AddDeviceTokenModel
|
||||
authtoken: AuthTokenModel
|
||||
app: AppModel
|
||||
appActivity: AppActivityModel
|
||||
category: CategoryModel
|
||||
categoryApp: CategoryAppModel
|
||||
device: DeviceModel
|
||||
|
@ -52,6 +54,7 @@ const createDatabase = (sequelize: Sequelize.Sequelize): Database => ({
|
|||
addDeviceToken: createAddDeviceTokenModel(sequelize),
|
||||
authtoken: createAuthtokenModel(sequelize),
|
||||
app: createAppModel(sequelize),
|
||||
appActivity: createAppActivityModel(sequelize),
|
||||
category: createCategoryModel(sequelize),
|
||||
categoryApp: createCategoryAppModel(sequelize),
|
||||
device: createDeviceModel(sequelize),
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 appActivityAttributes } from '../../appactivity'
|
||||
import { attributesVersion9 as deviceAttributes } from '../../device'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: 'EXCLUSIVE'
|
||||
}, async (transaction) => {
|
||||
await queryInterface.createTable('AppActivities', appActivityAttributes, { transaction })
|
||||
await queryInterface.addColumn('Devices', 'activityLevelBlocking', {
|
||||
...deviceAttributes.activityLevelBlocking
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: 'EXCLUSIVE'
|
||||
}, async (transaction) => {
|
||||
await queryInterface.dropTable('AppActivities', { transaction })
|
||||
await queryInterface.removeColumn('Devices', 'activityLevelBlocking', { transaction })
|
||||
})
|
||||
}
|
|
@ -59,5 +59,6 @@ export const prepareDeviceEntry = ({ familyId, userId, deviceAuthToken, deviceId
|
|||
currentOverlayPermission: 'not granted',
|
||||
highestOverlayPermission: 'not granted',
|
||||
asEnabled: false,
|
||||
wasAsEnabled: false
|
||||
wasAsEnabled: false,
|
||||
activityLevelBlocking: false
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue