From e28b8296d155c404cc5a702b3b477c41915d73dc Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 18 Feb 2021 22:37:25 +0200 Subject: [PATCH] describe options to Room --- .../net.ktnx.mobileledger.db.DB/58.json | 37 +++++++++++- .../java/net/ktnx/mobileledger/db/DB.java | 2 +- .../java/net/ktnx/mobileledger/db/Option.java | 59 +++++++++++++++++++ app/src/main/res/raw/create_db.sql | 4 +- app/src/main/res/raw/sql_58.sql | 15 +++++ 5 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/net/ktnx/mobileledger/db/Option.java diff --git a/app/schemas/net.ktnx.mobileledger.db.DB/58.json b/app/schemas/net.ktnx.mobileledger.db.DB/58.json index fca67449..0bcd3c7f 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": "ba63bc73720c33314f20ec5312984ab4", + "identityHash": "44f57b04fd657bffc7f36554b678696f", "entities": [ { "tableName": "templates", @@ -461,12 +461,45 @@ }, "indices": [], "foreignKeys": [] + }, + { + "tableName": "options", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`profile` TEXT NOT NULL, `name` TEXT NOT NULL, `value` TEXT, PRIMARY KEY(`profile`, `name`))", + "fields": [ + { + "fieldPath": "profile", + "columnName": "profile", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "profile", + "name" + ], + "autoGenerate": false + }, + "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, 'ba63bc73720c33314f20ec5312984ab4')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '44f57b04fd657bffc7f36554b678696f')" ] } } \ 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 dadf9b8a..b4587c21 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,7 @@ import net.ktnx.mobileledger.utils.MobileLedgerDatabase; @Database(version = 58, entities = {TemplateHeader.class, TemplateAccount.class, Currency.class, Account.class, - Profile.class + Profile.class, Option.class }) abstract public class DB extends RoomDatabase { private static DB instance; diff --git a/app/src/main/java/net/ktnx/mobileledger/db/Option.java b/app/src/main/java/net/ktnx/mobileledger/db/Option.java new file mode 100644 index 00000000..2b8f6a3c --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/db/Option.java @@ -0,0 +1,59 @@ +/* + * 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 = "options", primaryKeys = {"profile", "name"}) +public class Option { + @NonNull + @ColumnInfo + private String profile = "invalid"; + @NonNull + @ColumnInfo + private String name = ""; + @ColumnInfo + private String value; + @NonNull + public String getProfile() { + return profile; + } + public void setProfile(@NonNull String profile) { + this.profile = profile; + } + @NonNull + public String getName() { + return name; + } + public void setName(@NonNull String name) { + this.name = name; + } + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } + @NonNull + @Override + public String toString() { + return getName(); + } +} diff --git a/app/src/main/res/raw/create_db.sql b/app/src/main/res/raw/create_db.sql index a4a42eaf..96a5bf43 100644 --- a/app/src/main/res/raw/create_db.sql +++ b/app/src/main/res/raw/create_db.sql @@ -37,8 +37,8 @@ create table profiles( primary key(uuid)); create table accounts(profile varchar not null, name varchar not null, name_upper varchar not null, level integer not null, parent_name varchar, expanded integer not null default 1, amounts_expanded integer not null default 0, generation integer not null default 0, primary key(profile, name)); -create table options(profile varchar not null, name varchar not null, value varchar); -create unique index un_options on options(profile,name); +create table options(profile varchar not null, name varchar not null, value varchar, primary key(profile, name)); + create table account_values(profile varchar not null, account varchar not null, currency varchar not null default '', value decimal not null, generation integer default 0 ); create unique index un_account_values on account_values(profile,account,currency); create table description_history(description varchar not null primary key, description_upper varchar, generation integer default 0); diff --git a/app/src/main/res/raw/sql_58.sql b/app/src/main/res/raw/sql_58.sql index 4c99be22..066f2283 100644 --- a/app/src/main/res/raw/sql_58.sql +++ b/app/src/main/res/raw/sql_58.sql @@ -50,6 +50,21 @@ select uuid, name, url, use_authentication, auth_user, auth_password, order_no, detected_version_pre_1_19, detected_version_major, detected_version_minor from profiles; +drop table profiles; + +alter table profiles_new +rename to profiles; + +create table options_new(profile varchar not null, name varchar not null, value varchar, primary key(profile, name)); + +insert into options_new(profile, name, value) +select profile, name, value from options; + +drop table options; + +alter table options_new +rename to options; + COMMIT TRANSACTION; PRAGMA foreign_keys = ON; \ No newline at end of file -- 2.39.2