diff --git a/db/schemas/com.readrops.db.Database/3.json b/db/schemas/com.readrops.db.Database/3.json index cfd61c7c..464e5f8b 100644 --- a/db/schemas/com.readrops.db.Database/3.json +++ b/db/schemas/com.readrops.db.Database/3.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 3, - "identityHash": "a1f1be38bb62d3d52c1563c7a2472a4c", + "identityHash": "3c36644243041ad4676b32310d961ca9", "entities": [ { "tableName": "Feed", @@ -423,7 +423,7 @@ }, { "tableName": "ItemStateChange", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `read_change` INTEGER NOT NULL, `star_change` INTEGER NOT NULL, `account_id` INTEGER NOT NULL, PRIMARY KEY(`id`))", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `read_change` INTEGER NOT NULL, `star_change` INTEGER NOT NULL, `account_id` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`account_id`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", "fields": [ { "fieldPath": "id", @@ -457,11 +457,23 @@ "autoGenerate": false }, "indices": [], - "foreignKeys": [] + "foreignKeys": [ + { + "table": "Account", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "account_id" + ], + "referencedColumns": [ + "id" + ] + } + ] }, { "tableName": "ItemState", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `read` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `remote_id` TEXT NOT NULL, `account_id` INTEGER NOT NULL)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `read` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `remote_id` TEXT NOT NULL, `account_id` INTEGER NOT NULL, FOREIGN KEY(`account_id`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", "fields": [ { "fieldPath": "id", @@ -501,13 +513,25 @@ "autoGenerate": true }, "indices": [], - "foreignKeys": [] + "foreignKeys": [ + { + "table": "Account", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "account_id" + ], + "referencedColumns": [ + "id" + ] + } + ] } ], "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, 'a1f1be38bb62d3d52c1563c7a2472a4c')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3c36644243041ad4676b32310d961ca9')" ] } } \ No newline at end of file diff --git a/db/src/main/java/com/readrops/db/entities/ItemState.kt b/db/src/main/java/com/readrops/db/entities/ItemState.kt index 96f719a9..aebca1de 100644 --- a/db/src/main/java/com/readrops/db/entities/ItemState.kt +++ b/db/src/main/java/com/readrops/db/entities/ItemState.kt @@ -2,9 +2,12 @@ package com.readrops.db.entities import androidx.room.ColumnInfo import androidx.room.Entity +import androidx.room.ForeignKey import androidx.room.PrimaryKey +import com.readrops.db.entities.account.Account -@Entity +@Entity(foreignKeys = [ForeignKey(entity = Account::class, parentColumns = ["id"], + childColumns = ["account_id"], onDelete = ForeignKey.CASCADE)]) data class ItemStateChange( @PrimaryKey val id: Int = 0, @ColumnInfo(name = "read_change") val readChange: Boolean = false, @@ -12,7 +15,8 @@ data class ItemStateChange( @ColumnInfo(name = "account_id") val accountId: Int, ) -@Entity +@Entity(foreignKeys = [ForeignKey(entity = Account::class, parentColumns = ["id"], + childColumns = ["account_id"], onDelete = ForeignKey.CASCADE)]) data class ItemState( @PrimaryKey(autoGenerate = true) val id: Int = 0, val read: Boolean = false,