diff --git a/src/database/appactivity.ts b/src/database/appactivity.ts
new file mode 100644
index 0000000..515a0fb
--- /dev/null
+++ b/src/database/appactivity.ts
@@ -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 .
+ */
+
+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
+export type AppActivityModel = Sequelize.Model
+
+export const attributes: SequelizeAttributes = {
+ 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('AppActivity', attributes)
diff --git a/src/database/device.ts b/src/database/device.ts
index c1e7e99..949737d 100644
--- a/src/database/device.ts
+++ b/src/database/device.ts
@@ -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
export type DeviceModel = Sequelize.Model
@@ -208,6 +213,13 @@ export const attributesVersion8: SequelizeAttributes =
}
}
+export const attributesVersion9: SequelizeAttributes = {
+ activityLevelBlocking: {
+ ...booleanColumn,
+ defaultValue: false
+ }
+}
+
export const attributes: SequelizeAttributes = {
...attributesVersion1,
...attributesVersion2,
@@ -216,7 +228,8 @@ export const attributes: SequelizeAttributes = {
...attributesVersion5,
...attributesVersion6,
...attributesVersion7,
- ...attributesVersion8
+ ...attributesVersion8,
+ ...attributesVersion9
}
export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModel => sequelize.define('Device', attributes)
diff --git a/src/database/index.ts b/src/database/index.ts
index 94c8103..5539239 100644
--- a/src/database/index.ts
+++ b/src/database/index.ts
@@ -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),
diff --git a/src/database/migration/migrations/20190415-add-activity-level-blocking.ts b/src/database/migration/migrations/20190415-add-activity-level-blocking.ts
new file mode 100644
index 0000000..f8c3404
--- /dev/null
+++ b/src/database/migration/migrations/20190415-add-activity-level-blocking.ts
@@ -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 .
+ */
+
+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 })
+ })
+}
diff --git a/src/function/device/prepare-device-entry.ts b/src/function/device/prepare-device-entry.ts
index c7aaafd..ed91693 100644
--- a/src/function/device/prepare-device-entry.ts
+++ b/src/function/device/prepare-device-entry.ts
@@ -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
})