From 0d86dab5fe20c1a8474e58bfd6c250049b488612 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Mon, 3 Jun 2019 00:00:00 +0000 Subject: [PATCH] Add new database fields --- src/database/category.ts | 26 +++++++++- src/database/device.ts | 16 ++++++- ...0190603-add-time-warnings-and-android-q.ts | 47 +++++++++++++++++++ src/function/device/prepare-device-entry.ts | 3 +- .../dispatch-parent-action/createcategory.ts | 3 +- 5 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 src/database/migration/migrations/20190603-add-time-warnings-and-android-q.ts diff --git a/src/database/category.ts b/src/database/category.ts index 088928c..e7b3d8b 100644 --- a/src/database/category.ts +++ b/src/database/category.ts @@ -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 export type CategoryModel = Sequelize.Model @@ -94,10 +98,28 @@ export const attributesVersion3: SequelizeAttributes } } +export const attributesVersion4: SequelizeAttributes = { + 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 = { ...attributesVersion1, ...attributesVersion2, - ...attributesVersion3 + ...attributesVersion3, + ...attributesVersion4 } export const createCategoryModel = (sequelize: Sequelize.Sequelize): CategoryModel => sequelize.define('Category', attributes) diff --git a/src/database/device.ts b/src/database/device.ts index 949737d..52b7527 100644 --- a/src/database/device.ts +++ b/src/database/device.ts @@ -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 export type DeviceModel = Sequelize.Model @@ -220,6 +224,13 @@ export const attributesVersion9: SequelizeAttributes = } } +export const attributesVersion10: SequelizeAttributes = { + isQorLater: { + ...booleanColumn, + defaultValue: false + } +} + export const attributes: SequelizeAttributes = { ...attributesVersion1, ...attributesVersion2, @@ -229,7 +240,8 @@ export const attributes: SequelizeAttributes = { ...attributesVersion6, ...attributesVersion7, ...attributesVersion8, - ...attributesVersion9 + ...attributesVersion9, + ...attributesVersion10 } export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModel => sequelize.define('Device', attributes) diff --git a/src/database/migration/migrations/20190603-add-time-warnings-and-android-q.ts b/src/database/migration/migrations/20190603-add-time-warnings-and-android-q.ts new file mode 100644 index 0000000..4153d82 --- /dev/null +++ b/src/database/migration/migrations/20190603-add-time-warnings-and-android-q.ts @@ -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 . + */ + +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 }) + }) +} diff --git a/src/function/device/prepare-device-entry.ts b/src/function/device/prepare-device-entry.ts index ed91693..36b35a5 100644 --- a/src/function/device/prepare-device-entry.ts +++ b/src/function/device/prepare-device-entry.ts @@ -60,5 +60,6 @@ export const prepareDeviceEntry = ({ familyId, userId, deviceAuthToken, deviceId highestOverlayPermission: 'not granted', asEnabled: false, wasAsEnabled: false, - activityLevelBlocking: false + activityLevelBlocking: false, + isQorLater: false }) diff --git a/src/function/sync/apply-actions/dispatch-parent-action/createcategory.ts b/src/function/sync/apply-actions/dispatch-parent-action/createcategory.ts index 9b49685..389b341 100644 --- a/src/function/sync/apply-actions/dispatch-parent-action/createcategory.ts +++ b/src/function/sync/apply-actions/dispatch-parent-action/createcategory.ts @@ -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