]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/res/raw/sql_58.sql
describe transaction_accounts to Room
[mobile-ledger.git] / app / src / main / res / raw / sql_58.sql
1 -- Copyright © 2021 Damyan Ivanov.
2 -- This file is part of MoLe.
3 -- MoLe is free software: you can distribute it and/or modify it
4 -- under the term of the GNU General Public License as published by
5 -- the Free Software Foundation, either version 3 of the License, or
6 -- (at your opinion), any later version.
7 --
8 -- MoLe is distributed in the hope that it will be useful,
9 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
10 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 -- GNU General Public License terms for details.
12 --
13 -- You should have received a copy of the GNU General Public License
14 -- along with MoLe. If not, see <https://www.gnu.org/licenses/>.
15
16 -- profiles ground for  Room
17
18 PRAGMA foreign_keys = OFF;
19 BEGIN TRANSACTION;
20
21 create table profiles(
22  uuid text not null,
23  name text not null,
24  url text not null,
25  use_authentication integer not null,
26  auth_user text,
27  auth_password text,
28  order_no integer not null,
29  permit_posting integer not null default 0,
30  theme integer not null default -1,
31  preferred_accounts_filter varchar,
32  future_dates integer not null,
33  api_version integer not null,
34  show_commodity_by_default integer not null default 0,
35  default_commodity text,
36  show_comments_by_default integer not null default 1,
37  detected_version_pre_1_19 integer not null,
38  detected_version_major integer not null,
39  detected_version_minor integer not null,
40  primary key(uuid));
41
42 insert into profiles_new(
43  uuid, name, url, use_authentication, auth_user, auth_password, order_no,
44  permit_posting, theme, preferred_accounts_filter, future_dates, api_version,
45  show_commodity_by_default, default_commodity, show_comments_by_default,
46  detected_version_pre_1_19, detected_version_major, detected_version_minor)
47 select uuid, name, url, use_authentication, auth_user, auth_password, order_no,
48  permit_posting, theme, preferred_accounts_filter, future_dates, api_version,
49  show_commodity_by_default, default_commodity, show_comments_by_default,
50  detected_version_pre_1_19, detected_version_major, detected_version_minor
51 from profiles;
52
53 drop table profiles;
54
55 alter table profiles_new
56 rename to profiles;
57
58 create table options_new(profile varchar not null, name varchar not null, value varchar, primary key(profile, name));
59
60 insert into options_new(profile, name, value)
61 select profile, name, value from options;
62
63 drop table options;
64
65 alter table options_new
66 rename to options;
67
68 create table account_values_new(
69  profile varchar not null,
70  account varchar not null,
71  currency varchar not null default '',
72  value real not null,
73  generation integer not null default 0,
74  primary key(profile, account, currency));
75
76 insert into account_values_new(
77  profile, account, currency, value, generation)
78 select profile, account, currency, value, generation
79 from account_values;
80
81 drop table account_values;
82 alter table account_values_new rename to account_values;
83
84 create table description_history_new(
85  description varchar collate NOCASE not null primary key,
86  description_upper varchar not null,
87  generation integer not null default 0,
88  primary key(description));
89
90 insert into description_history_new(description, description_upper, generation)
91 select description, description_upper, generation from description_history;
92
93 drop table description_history;
94 alter table description_history_new rename to description_history;
95
96 -- transactions
97
98 create table transactions_new(
99  profile varchar not null,
100  id integer not null,
101  data_hash varchar not null,
102  year integer not null,
103  month integer not null,
104  day integer not null,
105  description varchar collate NOCASE not null,
106  comment varchar,
107  generation integer not null default 0,
108  primary key(profile,id));
109
110 insert into transactions_new(profile, id, data_hash, year, month, day, description,
111  comment, generation)
112 select profile, id, data_hash, year, month, day, description,
113        comment, generation
114 from transactions;
115
116 drop table transactions;
117 alter table transactions_new rename to transactions;
118
119 create unique index un_transactions_data_hash on transactions(profile,data_hash);
120 create index idx_transaction_description on transactions(description);
121
122 -- transaction_accounts
123
124 create table transaction_accounts_new(
125  profile varchar not null,
126  transaction_id integer not null,
127  order_no integer not null,
128  account_name varchar not null,
129  currency varchar not null default '',
130  amount real not null,
131  comment varchar,
132  generation integer not null default 0,
133  primary key(profile, transaction_id, order_no),
134  foreign key (profile,account_name) references accounts(profile,name)
135   on delete cascade on update restrict,
136  foreign key(profile, transaction_id) references transactions(profile,id)
137   on delete cascade on update restrict);
138
139 insert into transaction_accounts_new(profile, transaction_id, order_no, account_name,
140  currency, amount, comment, generation)
141 select profile, transaction_id, order_no, account_name,
142        currency, amount, comment, generation
143 from transaction_accounts;
144
145 drop table transaction_accounts;
146 alter table transaction_accounts_new rename to transaction_accounts;
147
148 COMMIT TRANSACTION;
149
150 PRAGMA foreign_keys = ON;