From: Damyan Ivanov Date: Sun, 21 Mar 2021 20:20:31 +0000 (+0200) Subject: another step towards surrogate ID db objects X-Git-Tag: v0.18.0~106 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=87a1e58f79757bb0257c911e9bd77eb5d77a3e40;p=mobile-ledger.git another step towards surrogate ID db objects rename profile's uuid column to catch (and remove) all its usages use default theme id for the initial theme id --- diff --git a/app/schemas/net.ktnx.mobileledger.db.DB/59.json b/app/schemas/net.ktnx.mobileledger.db.DB/59.json index 3ebd83f9..414bfbe2 100644 --- a/app/schemas/net.ktnx.mobileledger.db.DB/59.json +++ b/app/schemas/net.ktnx.mobileledger.db.DB/59.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 59, - "identityHash": "a56d86c03528ece865d81fd8171c819f", + "identityHash": "0ab4d8a73295b6337c52ea561994b1c8", "entities": [ { "tableName": "templates", @@ -375,7 +375,7 @@ }, { "tableName": "profiles", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `use_authentication` INTEGER NOT NULL, `auth_user` TEXT, `auth_password` TEXT, `order_no` INTEGER NOT NULL, `permit_posting` INTEGER NOT NULL, `theme` INTEGER NOT NULL DEFAULT -1, `preferred_accounts_filter` TEXT, `future_dates` INTEGER NOT NULL, `api_version` INTEGER NOT NULL, `show_commodity_by_default` INTEGER NOT NULL, `default_commodity` TEXT, `show_comments_by_default` INTEGER NOT NULL DEFAULT 1, `detected_version_pre_1_19` INTEGER NOT NULL, `detected_version_major` INTEGER NOT NULL, `detected_version_minor` INTEGER NOT NULL)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `deprecated_uuid` TEXT, `url` TEXT NOT NULL, `use_authentication` INTEGER NOT NULL, `auth_user` TEXT, `auth_password` TEXT, `order_no` INTEGER NOT NULL, `permit_posting` INTEGER NOT NULL, `theme` INTEGER NOT NULL DEFAULT -1, `preferred_accounts_filter` TEXT, `future_dates` INTEGER NOT NULL, `api_version` INTEGER NOT NULL, `show_commodity_by_default` INTEGER NOT NULL, `default_commodity` TEXT, `show_comments_by_default` INTEGER NOT NULL DEFAULT 1, `detected_version_pre_1_19` INTEGER NOT NULL, `detected_version_major` INTEGER NOT NULL, `detected_version_minor` INTEGER NOT NULL)", "fields": [ { "fieldPath": "id", @@ -389,6 +389,12 @@ "affinity": "TEXT", "notNull": true }, + { + "fieldPath": "deprecatedUUID", + "columnName": "deprecated_uuid", + "affinity": "TEXT", + "notNull": false + }, { "fieldPath": "url", "columnName": "url", @@ -499,11 +505,11 @@ }, { "tableName": "options", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`profile` INTEGER NOT NULL, `name` TEXT NOT NULL, `value` TEXT, PRIMARY KEY(`profile`, `name`))", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`profile_id` INTEGER NOT NULL, `name` TEXT NOT NULL, `value` TEXT, PRIMARY KEY(`profile_id`, `name`))", "fields": [ { - "fieldPath": "profile", - "columnName": "profile", + "fieldPath": "profileId", + "columnName": "profile_id", "affinity": "INTEGER", "notNull": true }, @@ -522,7 +528,7 @@ ], "primaryKey": { "columnNames": [ - "profile", + "profile_id", "name" ], "autoGenerate": false @@ -641,7 +647,7 @@ }, { "tableName": "transactions", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `profile_id` INTEGER NOT NULL, `data_hash` TEXT NOT NULL, `year` INTEGER NOT NULL, `month` INTEGER NOT NULL, `day` INTEGER NOT NULL, `description` TEXT NOT NULL COLLATE NOCASE, `comment` TEXT, `generation` INTEGER NOT NULL, FOREIGN KEY(`profile_id`) REFERENCES `profiles`(`id`) ON UPDATE RESTRICT ON DELETE CASCADE )", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `ledger_id` INTEGER NOT NULL, `profile_id` INTEGER NOT NULL, `data_hash` TEXT NOT NULL, `year` INTEGER NOT NULL, `month` INTEGER NOT NULL, `day` INTEGER NOT NULL, `description` TEXT NOT NULL COLLATE NOCASE, `comment` TEXT, `generation` INTEGER NOT NULL, FOREIGN KEY(`profile_id`) REFERENCES `profiles`(`id`) ON UPDATE RESTRICT ON DELETE CASCADE )", "fields": [ { "fieldPath": "id", @@ -649,6 +655,12 @@ "affinity": "INTEGER", "notNull": true }, + { + "fieldPath": "ledgerId", + "columnName": "ledger_id", + "affinity": "INTEGER", + "notNull": true + }, { "fieldPath": "profileId", "columnName": "profile_id", @@ -706,13 +718,13 @@ }, "indices": [ { - "name": "un_transactions_data_hash", + "name": "un_transactions_ledger_id", "unique": true, "columnNames": [ "profile_id", - "data_hash" + "ledger_id" ], - "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `un_transactions_data_hash` ON `${TABLE_NAME}` (`profile_id`, `data_hash`)" + "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `un_transactions_ledger_id` ON `${TABLE_NAME}` (`profile_id`, `ledger_id`)" }, { "name": "idx_transaction_description", @@ -808,12 +820,12 @@ }, "indices": [ { - "name": "fk_tran_acc_trans", + "name": "fk_trans_acc_trans", "unique": false, "columnNames": [ "transaction_id" ], - "createSql": "CREATE INDEX IF NOT EXISTS `fk_tran_acc_trans` ON `${TABLE_NAME}` (`transaction_id`)" + "createSql": "CREATE INDEX IF NOT EXISTS `fk_trans_acc_trans` ON `${TABLE_NAME}` (`transaction_id`)" }, { "name": "un_transaction_accounts", @@ -843,7 +855,7 @@ "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, 'a56d86c03528ece865d81fd8171c819f')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0ab4d8a73295b6337c52ea561994b1c8')" ] } } \ No newline at end of file diff --git a/app/src/main/java/net/ktnx/mobileledger/dao/OptionDAO.java b/app/src/main/java/net/ktnx/mobileledger/dao/OptionDAO.java new file mode 100644 index 00000000..f6ee035b --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/dao/OptionDAO.java @@ -0,0 +1,46 @@ +/* + * Copyright © 2021 Damyan Ivanov. + * This file is part of MoLe. + * MoLe is free software: you can distribute it and/or modify it + * under the term of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. + * + * MoLe 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 General Public License terms for details. + * + * You should have received a copy of the GNU General Public License + * along with MoLe. If not, see . + */ + +package net.ktnx.mobileledger.dao; + +import androidx.lifecycle.LiveData; +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.OnConflictStrategy; +import androidx.room.Query; +import androidx.room.Update; + +import net.ktnx.mobileledger.db.Option; + +@Dao +public abstract class OptionDAO extends BaseDAO