From b2f4ea6b9b96cda1c04afc54c152049025d99d80 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 19 Feb 2021 16:20:13 +0000 Subject: [PATCH] describe description_history to Room --- .../net.ktnx.mobileledger.db.DB/58.json | 124 +++++++++++++++++- .../java/net/ktnx/mobileledger/db/DB.java | 3 +- .../mobileledger/db/DescriptionHistory.java | 54 ++++++++ app/src/main/res/raw/create_db.sql | 7 +- app/src/main/res/raw/sql_58.sql | 11 ++ 5 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/net/ktnx/mobileledger/db/DescriptionHistory.java diff --git a/app/schemas/net.ktnx.mobileledger.db.DB/58.json b/app/schemas/net.ktnx.mobileledger.db.DB/58.json index 5ea56419..c4e61313 100644 --- a/app/schemas/net.ktnx.mobileledger.db.DB/58.json +++ b/app/schemas/net.ktnx.mobileledger.db.DB/58.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 58, - "identityHash": "ce42602c9c1d3edae4cb67fa54bc6f76", + "identityHash": "00d9b541473347c65a90e47ce9072436", "entities": [ { "tableName": "templates", @@ -542,12 +542,132 @@ }, "indices": [], "foreignKeys": [] + }, + { + "tableName": "description_history", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`description` TEXT NOT NULL COLLATE NOCASE, `description_upper` TEXT NOT NULL, `generation` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`description`))", + "fields": [ + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "descriptionUpper", + "columnName": "description_upper", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "generation", + "columnName": "generation", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + } + ], + "primaryKey": { + "columnNames": [ + "description" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "transactions", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`profile` TEXT NOT NULL, `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, PRIMARY KEY(`profile`, `id`))", + "fields": [ + { + "fieldPath": "profile", + "columnName": "profile", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "dataHash", + "columnName": "data_hash", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "year", + "columnName": "year", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "month", + "columnName": "month", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "day", + "columnName": "day", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "comment", + "columnName": "comment", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "generation", + "columnName": "generation", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "profile", + "id" + ], + "autoGenerate": false + }, + "indices": [ + { + "name": "un_transactions_data_hash", + "unique": true, + "columnNames": [ + "profile", + "data_hash" + ], + "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `un_transactions_data_hash` ON `${TABLE_NAME}` (`profile`, `data_hash`)" + }, + { + "name": "idx_transaction_description", + "unique": false, + "columnNames": [ + "description" + ], + "createSql": "CREATE INDEX IF NOT EXISTS `idx_transaction_description` ON `${TABLE_NAME}` (`description`)" + } + ], + "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, 'ce42602c9c1d3edae4cb67fa54bc6f76')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '00d9b541473347c65a90e47ce9072436')" ] } } \ No newline at end of file diff --git a/app/src/main/java/net/ktnx/mobileledger/db/DB.java b/app/src/main/java/net/ktnx/mobileledger/db/DB.java index b66552fb..630c5b27 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/DB.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/DB.java @@ -33,7 +33,8 @@ import net.ktnx.mobileledger.utils.MobileLedgerDatabase; @Database(version = 58, entities = {TemplateHeader.class, TemplateAccount.class, Currency.class, Account.class, - Profile.class, Option.class, AccountValue.class + Profile.class, Option.class, AccountValue.class, DescriptionHistory.class, + Transaction.class }) abstract public class DB extends RoomDatabase { private static DB instance; diff --git a/app/src/main/java/net/ktnx/mobileledger/db/DescriptionHistory.java b/app/src/main/java/net/ktnx/mobileledger/db/DescriptionHistory.java new file mode 100644 index 00000000..0e3b246a --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/db/DescriptionHistory.java @@ -0,0 +1,54 @@ +/* + * 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.db; + +import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; +import androidx.room.Entity; + +@Entity(tableName = "description_history", primaryKeys = {"description"}) +public class DescriptionHistory { + @ColumnInfo(collate = ColumnInfo.NOCASE) + @NonNull + private String description; + @ColumnInfo(name = "description_upper") + @NonNull + private String descriptionUpper; + @ColumnInfo(defaultValue = "0") + private int generation = 0; + @NonNull + public String getDescription() { + return description; + } + public void setDescription(@NonNull String description) { + this.description = description; + } + @NonNull + public String getDescriptionUpper() { + return descriptionUpper; + } + public void setDescriptionUpper(@NonNull String descriptionUpper) { + this.descriptionUpper = descriptionUpper; + } + public int getGeneration() { + return generation; + } + public void setGeneration(int generation) { + this.generation = generation; + } +} diff --git a/app/src/main/res/raw/create_db.sql b/app/src/main/res/raw/create_db.sql index c05216a7..9a0ccbd6 100644 --- a/app/src/main/res/raw/create_db.sql +++ b/app/src/main/res/raw/create_db.sql @@ -47,8 +47,11 @@ create table account_values( generation integer not null default 0, primary key(profile, account, currency)); -create table description_history(description varchar not null primary key, description_upper varchar, generation integer default 0); -create unique index un_description_history on description_history(description_upper); +create table description_history(description varchar collate NOCASE not null, + description_upper varchar not null, + generation integer not null default 0, + primary key(description)); + create table transactions(profile varchar not null, id integer not null, data_hash varchar not null, year integer not null, month integer not null, day integer not null, description varchar not null, comment varchar, generation integer default 0); create unique index un_transactions_id on transactions(profile,id); create unique index un_transactions_data_hash on transactions(profile,data_hash); diff --git a/app/src/main/res/raw/sql_58.sql b/app/src/main/res/raw/sql_58.sql index 23f6502a..ab3d0886 100644 --- a/app/src/main/res/raw/sql_58.sql +++ b/app/src/main/res/raw/sql_58.sql @@ -81,6 +81,17 @@ from account_values; drop table account_values; alter table account_values_new rename to account_values; +create table description_history_new( + description varchar collate NOCASE not null primary key, + description_upper varchar not null, + generation integer not null default 0, + primary key(description)); + +insert into description_history_new(description, description_upper, generation) +select description, description_upper, generation from description_history; + +drop table description_history; +alter table description_history_new rename to description_history; COMMIT TRANSACTION; -- 2.39.2