From: Damyan Ivanov Date: Fri, 19 Feb 2021 16:15:47 +0000 (+0000) Subject: describe account_values to Room X-Git-Tag: v0.17.0~78 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=522a56b74819e88afddb0d2172f1136c766dd66b describe account_values to Room --- diff --git a/app/schemas/net.ktnx.mobileledger.db.DB/58.json b/app/schemas/net.ktnx.mobileledger.db.DB/58.json index 0bcd3c7f..5ea56419 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": "44f57b04fd657bffc7f36554b678696f", + "identityHash": "ce42602c9c1d3edae4cb67fa54bc6f76", "entities": [ { "tableName": "templates", @@ -494,12 +494,60 @@ }, "indices": [], "foreignKeys": [] + }, + { + "tableName": "account_values", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`profile` TEXT NOT NULL, `account` TEXT NOT NULL, `currency` TEXT NOT NULL DEFAULT '', `value` REAL NOT NULL, `generation` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`profile`, `account`, `currency`))", + "fields": [ + { + "fieldPath": "profile", + "columnName": "profile", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "account", + "columnName": "account", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true, + "defaultValue": "''" + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "generation", + "columnName": "generation", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + } + ], + "primaryKey": { + "columnNames": [ + "profile", + "account", + "currency" + ], + "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, '44f57b04fd657bffc7f36554b678696f')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ce42602c9c1d3edae4cb67fa54bc6f76')" ] } } \ No newline at end of file diff --git a/app/src/main/java/net/ktnx/mobileledger/db/AccountValue.java b/app/src/main/java/net/ktnx/mobileledger/db/AccountValue.java new file mode 100644 index 00000000..f41b0e73 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/db/AccountValue.java @@ -0,0 +1,77 @@ +/* + * 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; + +/* +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); + */ +@Entity(tableName = "account_values", primaryKeys = {"profile", "account", "currency"}) +public class AccountValue { + @ColumnInfo + @NonNull + private String profile; + @ColumnInfo + @NonNull + private String account; + @NonNull + @ColumnInfo(defaultValue = "") + private String currency = ""; + @ColumnInfo + private float value; + @ColumnInfo(defaultValue = "0") + private int generation = 0; + @NonNull + public String getProfile() { + return profile; + } + public void setProfile(@NonNull String profile) { + this.profile = profile; + } + @NonNull + public String getAccount() { + return account; + } + public void setAccount(@NonNull String account) { + this.account = account; + } + @NonNull + public String getCurrency() { + return currency; + } + public void setCurrency(@NonNull String currency) { + this.currency = currency; + } + public float getValue() { + return value; + } + public void setValue(float value) { + this.value = value; + } + public int getGeneration() { + return generation; + } + public void setGeneration(int generation) { + this.generation = generation; + } +} 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 b4587c21..b66552fb 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, Option.class + Profile.class, Option.class, AccountValue.class }) abstract public class DB extends RoomDatabase { private static DB instance; diff --git a/app/src/main/res/raw/create_db.sql b/app/src/main/res/raw/create_db.sql index 96a5bf43..c05216a7 100644 --- a/app/src/main/res/raw/create_db.sql +++ b/app/src/main/res/raw/create_db.sql @@ -39,8 +39,14 @@ create table profiles( 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, 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 account_values( + profile varchar not null, + account varchar not null, + currency varchar not null default '', + value real not null, + 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 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); diff --git a/app/src/main/res/raw/sql_58.sql b/app/src/main/res/raw/sql_58.sql index 066f2283..23f6502a 100644 --- a/app/src/main/res/raw/sql_58.sql +++ b/app/src/main/res/raw/sql_58.sql @@ -65,6 +65,23 @@ drop table options; alter table options_new rename to options; +create table account_values_new( + profile varchar not null, + account varchar not null, + currency varchar not null default '', + value real not null, + generation integer not null default 0, + primary key(profile, account, currency)); + +insert into account_values_new( + profile, account, currency, value, generation) +select profile, account, currency, value, generation +from account_values; + +drop table account_values; +alter table account_values_new rename to account_values; + + COMMIT TRANSACTION; PRAGMA foreign_keys = ON; \ No newline at end of file