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.
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.
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/>.
16 -- migrate from revision 41 to revision 58
19 create table profiles_new(
23 use_authentication integer not null,
26 order_no integer not null,
27 permit_posting integer not null default 0,
28 theme integer not null default -1,
29 preferred_accounts_filter varchar,
30 future_dates integer not null,
31 api_version integer not null,
32 show_commodity_by_default integer not null default 0,
33 default_commodity text,
34 show_comments_by_default integer not null default 1,
35 detected_version_pre_1_19 integer not null,
36 detected_version_major integer not null,
37 detected_version_minor integer not null,
40 insert into profiles_new(
41 uuid, name, url, use_authentication, auth_user, auth_password, order_no,
42 permit_posting, theme, preferred_accounts_filter, future_dates, api_version,
43 show_commodity_by_default, default_commodity, show_comments_by_default,
44 detected_version_pre_1_19, detected_version_major, detected_version_minor)
45 select uuid, name, url, use_authentication, auth_user, auth_password, order_no,
46 permit_posting, theme, preferred_accounts_filter, future_dates, api_version,
47 show_commodity_by_default, default_commodity, show_comments_by_default,
48 coalesce(detected_version_pre_1_19,0), coalesce(detected_version_major,0),
49 coalesce(detected_version_minor,0)
53 create table options_new(profile varchar not null, name varchar not null, value varchar, primary key(profile, name));
55 insert into options_new(profile, name, value)
56 select profile, name, value from options;
59 create table accounts_new(
60 profile varchar not null,
61 name varchar not null,
62 name_upper varchar not null,
63 level integer not null,
65 expanded integer not null default 1,
66 amounts_expanded integer not null default 0,
67 generation integer not null default 0,
68 primary key(profile, name));
70 insert into accounts_new(profile, name, name_upper, level, parent_name,
71 expanded, amounts_expanded, generation)
72 select profile, name, name_upper, level, parent_name, expanded,
73 amounts_expanded, generation from accounts;
76 create table account_values_new(
77 profile varchar not null,
78 account varchar not null,
79 currency varchar not null default '',
81 generation integer not null default 0,
82 primary key(profile, account, currency));
84 insert into account_values_new(
85 profile, account, currency, value, generation)
86 select profile, account, currency, value, generation
89 -- description_history
90 create table description_history_new(
91 description varchar collate NOCASE not null,
92 description_upper varchar not null,
93 generation integer not null default 0,
94 primary key(description));
96 insert into description_history_new(description, description_upper, generation)
97 select description, description_upper, generation from description_history;
100 create table transactions_new(
101 profile varchar not null,
103 data_hash varchar not null,
104 year integer not null,
105 month integer not null,
106 day integer not null,
107 description varchar collate NOCASE not null,
109 generation integer not null default 0,
110 primary key(profile,id));
112 insert into transactions_new(profile, id, data_hash, year, month, day, description,
114 select profile, id, data_hash, year, month, day, description,
118 -- transaction_accounts
119 create table transaction_accounts_new(
120 profile varchar not null,
121 transaction_id integer not null,
122 order_no integer not null,
123 account_name varchar not null,
124 currency varchar not null default '',
125 amount real not null,
127 generation integer not null default 0,
128 primary key(profile, transaction_id, order_no),
129 foreign key (profile,account_name) references accounts(profile,name)
130 on delete cascade on update restrict,
131 foreign key(profile, transaction_id) references transactions(profile,id)
132 on delete cascade on update restrict);
134 insert into transaction_accounts_new(profile, transaction_id, order_no, account_name,
135 currency, amount, comment, generation)
136 select profile, transaction_id, order_no, account_name,
137 currency, amount, comment, generation
138 from transaction_accounts;
141 create table currencies_new(id integer not null primary key, name varchar not null,
142 position varchar not null, has_gap integer not null);
144 insert into currencies_new(id, name, position, has_gap)
145 select id, name, position, has_gap
150 drop table transaction_accounts;
151 drop table transactions;
152 drop table account_values;
154 drop table description_history;
157 drop table currencies;
160 alter table options_new rename to options;
161 alter table profiles_new rename to profiles;
162 alter table accounts_new rename to accounts;
163 alter table account_values_new rename to account_values;
164 alter table description_history_new rename to description_history;
165 alter table transactions_new rename to transactions;
166 alter table transaction_accounts_new rename to transaction_accounts;
167 alter table currencies_new rename to currencies;
170 create index fk_tran_acc_prof_acc on transaction_accounts(profile, account_name);
171 create unique index un_transactions_data_hash on transactions(profile,data_hash);
172 create index idx_transaction_description on transactions(description);
176 CREATE TABLE templates (
177 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
179 regular_expression TEXT NOT NULL,
181 transaction_description TEXT,
182 transaction_description_match_group INTEGER,
183 transaction_comment TEXT,
184 transaction_comment_match_group INTEGER,
186 date_year_match_group INTEGER,
188 date_month_match_group INTEGER,
190 date_day_match_group INTEGER,
191 is_fallback INTEGER NOT NULL DEFAULT 0);
192 CREATE TABLE template_accounts(
193 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
194 template_id INTEGER NOT NULL,
196 position INTEGER NOT NULL,
197 acc_match_group INTEGER,
199 currency_match_group INTEGER,
201 amount_match_group INTEGER,
203 comment_match_group INTEGER,
204 negate_amount INTEGER,
205 FOREIGN KEY(template_id) REFERENCES templates(id) ON UPDATE RESTRICT ON DELETE CASCADE,
206 FOREIGN KEY(currency) REFERENCES currencies(id) ON UPDATE RESTRICT ON DELETE RESTRICT);
207 create index fk_template_accounts_template on template_accounts(template_id);
208 create index fk_template_accounts_currency on template_accounts(currency);