From 9436d7c1b4aeb36934f665d3bd7828aa06c661bd Mon Sep 17 00:00:00 2001 From: razeeman Date: Sat, 15 Jul 2023 17:17:29 +0300 Subject: [PATCH] migrate goals to separate table --- .../12.json | 74 +-- .../13.json | 447 ++++++++++++++++++ .../data_local/database/AppDatabase.kt | 4 +- .../database/AppDatabaseMigrations.kt | 39 +- .../mapper/RecordTypeDataLocalMapper.kt | 12 +- .../data_local/model/RecordTypeDBO.kt | 16 - .../data_local/model/RecordTypeGoalDBO.kt | 32 ++ .../domain/model/RecordTypeGoal.kt | 21 + 8 files changed, 590 insertions(+), 55 deletions(-) create mode 100644 data_local/schemas/com.example.util.simpletimetracker.data_local.database.AppDatabase/13.json create mode 100644 data_local/src/main/java/com/example/util/simpletimetracker/data_local/model/RecordTypeGoalDBO.kt create mode 100644 domain/src/main/java/com/example/util/simpletimetracker/domain/model/RecordTypeGoal.kt diff --git a/data_local/schemas/com.example.util.simpletimetracker.data_local.database.AppDatabase/12.json b/data_local/schemas/com.example.util.simpletimetracker.data_local.database.AppDatabase/12.json index 010fffc7..c19ad0a1 100644 --- a/data_local/schemas/com.example.util.simpletimetracker.data_local.database.AppDatabase/12.json +++ b/data_local/schemas/com.example.util.simpletimetracker.data_local.database.AppDatabase/12.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 12, - "identityHash": "ad1b19d2645f1f3d72ff21e406326ff5", + "identityHash": "87a74039829f7642ea3ad2c7b1b517a2", "entities": [ { "tableName": "records", @@ -56,7 +56,7 @@ }, { "tableName": "recordTypes", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `icon` TEXT NOT NULL, `color` INTEGER NOT NULL, `color_int` TEXT NOT NULL, `hidden` INTEGER NOT NULL, `goal_time` INTEGER NOT NULL, `daily_goal_time` INTEGER NOT NULL, `weekly_goal_time` INTEGER NOT NULL, `monthly_goal_time` INTEGER NOT NULL)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `icon` TEXT NOT NULL, `color` INTEGER NOT NULL, `color_int` TEXT NOT NULL, `hidden` INTEGER NOT NULL)", "fields": [ { "fieldPath": "id", @@ -93,30 +93,6 @@ "columnName": "hidden", "affinity": "INTEGER", "notNull": true - }, - { - "fieldPath": "goalTime", - "columnName": "goal_time", - "affinity": "INTEGER", - "notNull": true - }, - { - "fieldPath": "dailyGoalTime", - "columnName": "daily_goal_time", - "affinity": "INTEGER", - "notNull": true - }, - { - "fieldPath": "weeklyGoalTime", - "columnName": "weekly_goal_time", - "affinity": "INTEGER", - "notNull": true - }, - { - "fieldPath": "monthlyGoalTime", - "columnName": "monthly_goal_time", - "affinity": "INTEGER", - "notNull": true } ], "primaryKey": { @@ -416,12 +392,56 @@ }, "indices": [], "foreignKeys": [] + }, + { + "tableName": "recordTypeGoals", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type_id` INTEGER NOT NULL, `range` INTEGER NOT NULL, `type` INTEGER NOT NULL, `value` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "typeId", + "columnName": "type_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "range", + "columnName": "range", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] } ], "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ad1b19d2645f1f3d72ff21e406326ff5')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '87a74039829f7642ea3ad2c7b1b517a2')" ] } } \ No newline at end of file diff --git a/data_local/schemas/com.example.util.simpletimetracker.data_local.database.AppDatabase/13.json b/data_local/schemas/com.example.util.simpletimetracker.data_local.database.AppDatabase/13.json new file mode 100644 index 00000000..00fbdc7d --- /dev/null +++ b/data_local/schemas/com.example.util.simpletimetracker.data_local.database.AppDatabase/13.json @@ -0,0 +1,447 @@ +{ + "formatVersion": 1, + "database": { + "version": 13, + "identityHash": "87a74039829f7642ea3ad2c7b1b517a2", + "entities": [ + { + "tableName": "records", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type_id` INTEGER NOT NULL, `time_started` INTEGER NOT NULL, `time_ended` INTEGER NOT NULL, `comment` TEXT NOT NULL, `tag_id` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "typeId", + "columnName": "type_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timeStarted", + "columnName": "time_started", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timeEnded", + "columnName": "time_ended", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "comment", + "columnName": "comment", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "tagId", + "columnName": "tag_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "recordTypes", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `icon` TEXT NOT NULL, `color` INTEGER NOT NULL, `color_int` TEXT NOT NULL, `hidden` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "colorInt", + "columnName": "color_int", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "hidden", + "columnName": "hidden", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "runningRecords", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `time_started` INTEGER NOT NULL, `comment` TEXT NOT NULL, `tag_id` INTEGER NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timeStarted", + "columnName": "time_started", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "comment", + "columnName": "comment", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "tagId", + "columnName": "tag_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "categories", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `color` INTEGER NOT NULL, `color_int` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "colorInt", + "columnName": "color_int", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "recordTypeCategory", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`record_type_id` INTEGER NOT NULL, `category_id` INTEGER NOT NULL, PRIMARY KEY(`record_type_id`, `category_id`))", + "fields": [ + { + "fieldPath": "recordTypeId", + "columnName": "record_type_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "categoryId", + "columnName": "category_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "record_type_id", + "category_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "recordTags", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type_id` INTEGER NOT NULL, `name` TEXT NOT NULL, `color` INTEGER NOT NULL, `color_int` TEXT NOT NULL, `archived` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "typeId", + "columnName": "type_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "colorInt", + "columnName": "color_int", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "archived", + "columnName": "archived", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "recordToRecordTag", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`record_id` INTEGER NOT NULL, `record_tag_id` INTEGER NOT NULL, PRIMARY KEY(`record_id`, `record_tag_id`))", + "fields": [ + { + "fieldPath": "recordId", + "columnName": "record_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "recordTagId", + "columnName": "record_tag_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "record_id", + "record_tag_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "runningRecordToRecordTag", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`running_record_id` INTEGER NOT NULL, `record_tag_id` INTEGER NOT NULL, PRIMARY KEY(`running_record_id`, `record_tag_id`))", + "fields": [ + { + "fieldPath": "runningRecordId", + "columnName": "running_record_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "recordTagId", + "columnName": "record_tag_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "running_record_id", + "record_tag_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "activityFilters", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `selectedIds` TEXT NOT NULL, `type` INTEGER NOT NULL, `name` TEXT NOT NULL, `color` INTEGER NOT NULL, `color_int` TEXT NOT NULL, `selected` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "selectedIds", + "columnName": "selectedIds", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "colorInt", + "columnName": "color_int", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "selected", + "columnName": "selected", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "favouriteComments", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `comment` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "comment", + "columnName": "comment", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "recordTypeGoals", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type_id` INTEGER NOT NULL, `range` INTEGER NOT NULL, `type` INTEGER NOT NULL, `value` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "typeId", + "columnName": "type_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "range", + "columnName": "range", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '87a74039829f7642ea3ad2c7b1b517a2')" + ] + } +} \ No newline at end of file diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/database/AppDatabase.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/database/AppDatabase.kt index e256a3f6..40b4fed1 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/database/AppDatabase.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/database/AppDatabase.kt @@ -10,6 +10,7 @@ import com.example.util.simpletimetracker.data_local.model.RecordTagDBO import com.example.util.simpletimetracker.data_local.model.RecordToRecordTagDBO import com.example.util.simpletimetracker.data_local.model.RecordTypeCategoryDBO import com.example.util.simpletimetracker.data_local.model.RecordTypeDBO +import com.example.util.simpletimetracker.data_local.model.RecordTypeGoalDBO import com.example.util.simpletimetracker.data_local.model.RunningRecordDBO import com.example.util.simpletimetracker.data_local.model.RunningRecordToRecordTagDBO @@ -25,8 +26,9 @@ import com.example.util.simpletimetracker.data_local.model.RunningRecordToRecord RunningRecordToRecordTagDBO::class, ActivityFilterDBO::class, FavouriteCommentDBO::class, + RecordTypeGoalDBO::class, ], - version = 12, + version = 13, exportSchema = true, ) abstract class AppDatabase : RoomDatabase() { diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/database/AppDatabaseMigrations.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/database/AppDatabaseMigrations.kt index 49ad0f7c..9fb6e03b 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/database/AppDatabaseMigrations.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/database/AppDatabaseMigrations.kt @@ -19,6 +19,7 @@ class AppDatabaseMigrations { migration_9_10, migration_10_11, migration_11_12, + migration_12_13, ) private val migration_1_2 = object : Migration(1, 2) { @@ -27,15 +28,12 @@ class AppDatabaseMigrations { database.execSQL( "CREATE TABLE recordTypes_new (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT NOT NULL, icon TEXT NOT NULL, color INTEGER NOT NULL, hidden INTEGER NOT NULL)", ) - // Copy the data database.execSQL( "INSERT INTO recordTypes_new (id, name, icon, color, hidden) SELECT id, name, '', color, hidden FROM recordTypes", ) - // Remove the old table database.execSQL("DROP TABLE recordTypes") - // Change the table name to the correct one database.execSQL("ALTER TABLE recordTypes_new RENAME TO recordTypes") } @@ -150,5 +148,40 @@ class AppDatabaseMigrations { ) } } + + private val migration_12_13 = object : Migration(12, 13) { + override fun migrate(database: SupportSQLiteDatabase) { + // Create new table for goals + database.execSQL( + "CREATE TABLE IF NOT EXISTS `recordTypeGoals` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type_id` INTEGER NOT NULL, `range` INTEGER NOT NULL, `type` INTEGER NOT NULL, `value` INTEGER NOT NULL)", + ) + // Migrate goals + // session range = 0, daily range = 1, weekly range = 2, monthly range = 3 + database.execSQL( + "INSERT INTO recordTypeGoals (type_id, range, type, value) SELECT id, 0, 0, goal_time FROM recordTypes WHERE goal_time != 0", + ) + database.execSQL( + "INSERT INTO recordTypeGoals (type_id, range, type, value) SELECT id, 1, 0, daily_goal_time FROM recordTypes WHERE daily_goal_time != 0", + ) + database.execSQL( + "INSERT INTO recordTypeGoals (type_id, range, type, value) SELECT id, 2, 0, weekly_goal_time FROM recordTypes WHERE weekly_goal_time != 0", + ) + database.execSQL( + "INSERT INTO recordTypeGoals (type_id, range, type, value) SELECT id, 3, 0, monthly_goal_time FROM recordTypes WHERE monthly_goal_time != 0", + ) + // Create the new table + database.execSQL( + "CREATE TABLE `recordTypes_new` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `icon` TEXT NOT NULL, `color` INTEGER NOT NULL, `color_int` TEXT NOT NULL, `hidden` INTEGER NOT NULL)", + ) + // Copy the data + database.execSQL( + "INSERT INTO recordTypes_new (id, name, icon, color, color_int, hidden) SELECT id, name, icon, color, color_int, hidden FROM recordTypes", + ) + // Remove the old table + database.execSQL("DROP TABLE recordTypes") + // Change the table name to the correct one + database.execSQL("ALTER TABLE recordTypes_new RENAME TO recordTypes") + } + } } } \ No newline at end of file diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/mapper/RecordTypeDataLocalMapper.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/mapper/RecordTypeDataLocalMapper.kt index cf1d303c..b6426775 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/mapper/RecordTypeDataLocalMapper.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/mapper/RecordTypeDataLocalMapper.kt @@ -17,10 +17,10 @@ class RecordTypeDataLocalMapper @Inject constructor() { colorInt = dbo.colorInt ), hidden = dbo.hidden, - goalTime = dbo.goalTime, - dailyGoalTime = dbo.dailyGoalTime, - weeklyGoalTime = dbo.weeklyGoalTime, - monthlyGoalTime = dbo.monthlyGoalTime, + goalTime = 0, + dailyGoalTime = 0, + weeklyGoalTime = 0, + monthlyGoalTime = 0, ) } @@ -32,10 +32,6 @@ class RecordTypeDataLocalMapper @Inject constructor() { color = domain.color.colorId, colorInt = domain.color.colorInt, hidden = domain.hidden, - goalTime = domain.goalTime, - dailyGoalTime = domain.dailyGoalTime, - weeklyGoalTime = domain.weeklyGoalTime, - monthlyGoalTime = domain.monthlyGoalTime, ) } } \ No newline at end of file diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/model/RecordTypeDBO.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/model/RecordTypeDBO.kt index 4fb2cf4d..e2c330ae 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/model/RecordTypeDBO.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/model/RecordTypeDBO.kt @@ -25,20 +25,4 @@ data class RecordTypeDBO( @ColumnInfo(name = "hidden") val hidden: Boolean, - - // Seconds. - @ColumnInfo(name = "goal_time") - val goalTime: Long, - - // Seconds. - @ColumnInfo(name = "daily_goal_time") - val dailyGoalTime: Long, - - // Seconds. - @ColumnInfo(name = "weekly_goal_time") - val weeklyGoalTime: Long, - - // Seconds. - @ColumnInfo(name = "monthly_goal_time") - val monthlyGoalTime: Long, ) \ No newline at end of file diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/model/RecordTypeGoalDBO.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/model/RecordTypeGoalDBO.kt new file mode 100644 index 00000000..a29510ac --- /dev/null +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/model/RecordTypeGoalDBO.kt @@ -0,0 +1,32 @@ +package com.example.util.simpletimetracker.data_local.model + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "recordTypeGoals") +data class RecordTypeGoalDBO( + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + val id: Long, + + @ColumnInfo(name = "type_id") + val typeId: Long, + + // 0 - session + // 1 - daily + // 2 - weekly + // 3 - monthly + @ColumnInfo(name = "range") + val range: Long, + + // 0 - goal for records duration + // 1 - goal for records count + @ColumnInfo(name = "type") + val type: Long, + + // seconds if goal time + // count if goal count + @ColumnInfo(name = "value") + val value: Long, +) \ No newline at end of file diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/model/RecordTypeGoal.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/model/RecordTypeGoal.kt new file mode 100644 index 00000000..8baa6f08 --- /dev/null +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/model/RecordTypeGoal.kt @@ -0,0 +1,21 @@ +package com.example.util.simpletimetracker.domain.model + +data class RecordTypeGoal( + val id: Long = 0, + val typeId: Long, + val range: Range, + val type: Type, +) { + + sealed interface Range { + object Session : Range + object Daily : Range + object Weekly : Range + object Monthly : Range + } + + sealed interface Type { + data class Duration(val seconds: Long) : Type + data class Count(val times: Long) : Type + } +} \ No newline at end of file -- 2.51.2