From: Damyan Ivanov Date: Fri, 19 Feb 2021 16:31:28 +0000 (+0000) Subject: describe transactions to Room X-Git-Tag: v0.17.0~75 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=32ef1438acbd5328433be04668362402e26095cb;p=mobile-ledger.git describe transactions to Room --- diff --git a/app/src/main/java/net/ktnx/mobileledger/db/Transaction.java b/app/src/main/java/net/ktnx/mobileledger/db/Transaction.java new file mode 100644 index 00000000..f6808f94 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/db/Transaction.java @@ -0,0 +1,113 @@ +/* + * 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; +import androidx.room.Index; + +/* +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 +collate NOCASE not null, comment varchar, generation integer default 0, primary key(profile,id)); +create unique index un_transactions_data_hash on transactions(profile,data_hash); +create index idx_transaction_description on transactions(description); + */ +@Entity(tableName = "transactions", primaryKeys = {"profile", "id"}, indices = { + @Index(name = "un_transactions_data_hash", unique = true, value = {"profile", "data_hash"}), + @Index(name = "idx_transaction_description", value = "description") +}) +public class Transaction { + @ColumnInfo + @NonNull + private String profile; + @ColumnInfo + private int id; + @ColumnInfo(name = "data_hash") + @NonNull + private String dataHash; + @ColumnInfo + private int year; + @ColumnInfo + private int month; + @ColumnInfo + private int day; + @ColumnInfo(collate = ColumnInfo.NOCASE) + @NonNull + private String description; + @ColumnInfo + private String comment; + @ColumnInfo + private int generation = 0; + public String getProfile() { + return profile; + } + public void setProfile(String profile) { + this.profile = profile; + } + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public String getDataHash() { + return dataHash; + } + public void setDataHash(String dataHash) { + this.dataHash = dataHash; + } + public int getYear() { + return year; + } + public void setYear(int year) { + this.year = year; + } + public int getMonth() { + return month; + } + public void setMonth(int month) { + this.month = month; + } + public int getDay() { + return day; + } + public void setDay(int day) { + this.day = day; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } + 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 9a0ccbd6..62582672 100644 --- a/app/src/main/res/raw/create_db.sql +++ b/app/src/main/res/raw/create_db.sql @@ -52,10 +52,20 @@ create table description_history(description varchar collate NOCASE 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 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 collate NOCASE not null, + comment varchar, + generation integer not null default 0, + primary key(profile,id)); create unique index un_transactions_data_hash on transactions(profile,data_hash); create index idx_transaction_description on transactions(description); + create table transaction_accounts(profile varchar not null, transaction_id integer not null, order_no integer not null, account_name varchar not null, currency varchar not null default '', amount decimal not null, comment varchar, generation integer default 0, constraint fk_transaction_accounts_acc foreign key(profile,account_name) references accounts(profile,name), constraint fk_transaction_accounts_trn foreign key(profile, transaction_id) references transactions(profile,id)); create unique index un_transaction_accounts_order on transaction_accounts(profile, transaction_id, order_no); create table currencies(id integer not null primary key, name varchar not null, position varchar not null, has_gap integer not null); diff --git a/app/src/main/res/raw/sql_58.sql b/app/src/main/res/raw/sql_58.sql index ab3d0886..b2b687c5 100644 --- a/app/src/main/res/raw/sql_58.sql +++ b/app/src/main/res/raw/sql_58.sql @@ -93,6 +93,33 @@ select description, description_upper, generation from description_history; drop table description_history; alter table description_history_new rename to description_history; +-- transactions + +create table transactions_new( + 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 collate NOCASE not null, + comment varchar, + generation integer not null default 0, + primary key(profile,id)); + +insert into transactions_new(profile, id, data_hash, year, month, day, description, + comment, generation) +select profile, id, data_hash, year, month, day, description, + comment, generation +from transactions; + +drop table transactions; +alter table transactions_new rename to transactions; + +create unique index un_transactions_data_hash on transactions(profile,data_hash); +create index idx_transaction_description on transactions(description); + + COMMIT TRANSACTION; PRAGMA foreign_keys = ON; \ No newline at end of file