@@ -10,6 +10,16 @@ CREATE TABLE IF NOT EXISTS CategoryTypes(
10
10
description IN ('fixed', 'variable', 'seasonal')
11
11
)
12
12
);
13
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_category_types__description ON CategoryTypes(description);
14
+ CREATE TRIGGER IF NOT EXISTS prevent_update_CategoryTypes
15
+ BEFORE UPDATE OF description ON CategoryTypes
16
+ BEGIN
17
+ SELECT RAISE(
18
+ ABORT,
19
+ 'Update of description is not allowed in CategoryTypes'
20
+ );
21
+ END;
22
+
13
23
CREATE UNIQUE INDEX IF NOT EXISTS idx_category_types_description ON CategoryTypes(description);
14
24
INSERT INTO CategoryTypes(description)
15
25
VALUES ('fixed'), ('variable'), ('seasonal');
@@ -22,7 +32,9 @@ CREATE TABLE IF NOT EXISTS Suggestions(
22
32
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
23
33
FOREIGN KEY(type_id) REFERENCES CategoryTypes(id)
24
34
);
25
- CREATE INDEX IF NOT EXISTS idx_suggestions_type_isexpense ON Suggestions(type_id, is_expense);
35
+ CREATE INDEX IF NOT EXISTS idx_suggestions__is_expense ON Suggestions(is_expense);
36
+ CREATE INDEX IF NOT EXISTS idx_suggestions__type_id ON Suggestions(type_id);
37
+
26
38
CREATE TRIGGER IF NOT EXISTS prevent_update_Suggestions
27
39
BEFORE UPDATE OF created_at ON Suggestions
28
40
BEGIN
@@ -31,54 +43,60 @@ BEGIN
31
43
'Update of created_at is not allowed in Suggestions'
32
44
);
33
45
END;
34
- -- Insert fixed suggestions
46
+ -- Insert fixed expense suggestions
35
47
INSERT INTO Suggestions(name, type_id, is_expense)
36
- SELECT 'rent ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
48
+ SELECT 'rent_or_mortgage ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
37
49
38
50
INSERT INTO Suggestions(name, type_id, is_expense)
39
- SELECT 'electricity ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
51
+ SELECT 'property_taxes ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
40
52
41
53
INSERT INTO Suggestions(name, type_id, is_expense)
42
- SELECT 'internet ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
54
+ SELECT 'health_insurance ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
43
55
44
56
INSERT INTO Suggestions(name, type_id, is_expense)
45
- SELECT 'cell_phone_bill ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
57
+ SELECT 'car_insurance ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
46
58
47
59
INSERT INTO Suggestions(name, type_id, is_expense)
48
- SELECT 'tv_streaming ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
60
+ SELECT 'public_transport ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
49
61
50
62
INSERT INTO Suggestions(name, type_id, is_expense)
51
- SELECT 'music_streaming ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
63
+ SELECT 'home_insurance ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
52
64
53
65
INSERT INTO Suggestions(name, type_id, is_expense)
54
- SELECT 'health_insurance ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
66
+ SELECT 'loan_payments ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
55
67
56
68
INSERT INTO Suggestions(name, type_id, is_expense)
57
- SELECT 'insurance ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
69
+ SELECT 'internet_subscription ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
58
70
59
71
INSERT INTO Suggestions(name, type_id, is_expense)
60
- SELECT 'mortgage ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
72
+ SELECT 'cell_phone_plan ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
61
73
62
74
INSERT INTO Suggestions(name, type_id, is_expense)
63
- SELECT 'property_taxes', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
75
+ SELECT 'cable_or_streaming_services', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
76
+
77
+ INSERT INTO Suggestions(name, type_id, is_expense)
78
+ SELECT 'music_streaming_services', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
64
79
65
80
INSERT INTO Suggestions(name, type_id, is_expense)
66
- SELECT 'salaries ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
81
+ SELECT 'magazine_or_newspaper_subscriptions ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
67
82
68
83
INSERT INTO Suggestions(name, type_id, is_expense)
69
84
SELECT 'gym', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
70
85
71
86
INSERT INTO Suggestions(name, type_id, is_expense)
72
- SELECT 'personal_education ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
87
+ SELECT 'association_fees ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
73
88
74
89
INSERT INTO Suggestions(name, type_id, is_expense)
75
- SELECT 'children_school', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
90
+ SELECT 'private_retirement_plans', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
91
+
92
+ INSERT INTO Suggestions(name, type_id, is_expense)
93
+ SELECT 'personal_education', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
76
94
77
95
INSERT INTO Suggestions(name, type_id, is_expense)
78
- SELECT 'car_maintenance ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
96
+ SELECT 'children_school ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
79
97
80
98
INSERT INTO Suggestions(name, type_id, is_expense)
81
- SELECT 'transport ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
99
+ SELECT 'childcare ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'fixed';
82
100
83
101
-- Insert variable suggestions
84
102
INSERT INTO Suggestions(name, type_id, is_expense)
@@ -88,43 +106,40 @@ INSERT INTO Suggestions(name, type_id, is_expense)
88
106
SELECT 'dining_out', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
89
107
90
108
INSERT INTO Suggestions(name, type_id, is_expense)
91
- SELECT 'entertainment', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
92
-
93
- INSERT INTO Suggestions(name, type_id, is_expense)
94
- SELECT 'clothing', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
109
+ SELECT 'food_delivery', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
95
110
96
111
INSERT INTO Suggestions(name, type_id, is_expense)
97
- SELECT 'transportation ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
112
+ SELECT 'weekday_lunch ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
98
113
99
114
INSERT INTO Suggestions(name, type_id, is_expense)
100
- SELECT 'fuel ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
115
+ SELECT 'coffee_snacks ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
101
116
102
117
INSERT INTO Suggestions(name, type_id, is_expense)
103
- SELECT 'healthcare ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
118
+ SELECT 'transportation_fuel ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
104
119
105
120
INSERT INTO Suggestions(name, type_id, is_expense)
106
- SELECT 'personal_care ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
121
+ SELECT 'public_transport_tickets ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
107
122
108
123
INSERT INTO Suggestions(name, type_id, is_expense)
109
- SELECT 'subscriptions ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
124
+ SELECT 'cinema ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
110
125
111
126
INSERT INTO Suggestions(name, type_id, is_expense)
112
- SELECT 'education ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
127
+ SELECT 'sports_tickets ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
113
128
114
129
INSERT INTO Suggestions(name, type_id, is_expense)
115
- SELECT 'gifts ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
130
+ SELECT 'eletronic_games ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
116
131
117
132
INSERT INTO Suggestions(name, type_id, is_expense)
118
- SELECT 'vacations ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
133
+ SELECT 'bars ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
119
134
120
135
INSERT INTO Suggestions(name, type_id, is_expense)
121
- SELECT 'hobbies ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
136
+ SELECT 'night_clubs ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
122
137
123
138
INSERT INTO Suggestions(name, type_id, is_expense)
124
- SELECT 'pets ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
139
+ SELECT 'household_supplies ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
125
140
126
141
INSERT INTO Suggestions(name, type_id, is_expense)
127
- SELECT 'repairs ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
142
+ SELECT 'fitness_recreation ', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'variable';
128
143
129
144
-- Insert fixed incomes
130
145
INSERT INTO Suggestions(name, type_id, is_expense)
@@ -136,6 +151,7 @@ SELECT 'pension', types.id, 0 FROM CategoryTypes AS types WHERE types.descriptio
136
151
INSERT INTO Suggestions(name, type_id, is_expense)
137
152
SELECT 'rental_income', types.id, 0 FROM CategoryTypes AS types WHERE types.description = 'fixed';
138
153
154
+ -- Insert seasonal suggestions
139
155
INSERT INTO Suggestions(name, type_id, is_expense)
140
156
SELECT 'holiday_gifts', types.id, 1 FROM CategoryTypes AS types WHERE types.description = 'seasonal';
141
157
174
190
175
191
/**
176
192
* A category is a group of balance movements.
177
- * This is the main table of the database, storing the categories of the user and helping to organize the balance movements.
193
+ * This is the main table of the database, storing the categories of the user and helping to organize
194
+ * the balance movements.
178
195
*/
179
196
CREATE TABLE IF NOT EXISTS Categories(
180
197
id INTEGER PRIMARY KEY,
@@ -187,7 +204,10 @@ CREATE TABLE IF NOT EXISTS Categories(
187
204
FOREIGN KEY(linked_suggestion_id) REFERENCES Suggestions(id)
188
205
);
189
206
CREATE INDEX IF NOT EXISTS idx_categories__description ON Categories(name);
190
- CREATE INDEX IF NOT EXISTS idx_categories_amount ON Categories(amount DESC);
207
+ CREATE INDEX IF NOT EXISTS idx_categories__is_expense ON Categories(is_expense);
208
+ CREATE INDEX IF NOT EXISTS idx_categories__linked_suggestion_id ON Categories(
209
+ linked_suggestion_id
210
+ );
191
211
192
212
CREATE TRIGGER IF NOT EXISTS prevent_update_Categories
193
213
BEFORE UPDATE OF created_at ON Categories
@@ -208,7 +228,8 @@ CREATE TABLE IF NOT EXISTS FixedRecurrences(
208
228
FOREIGN KEY(category_id) REFERENCES Categories(id) ON DELETE CASCADE,
209
229
UNIQUE(category_id, day_of_month)
210
230
);
211
- CREATE UNIQUE INDEX IF NOT EXISTS idx_fixed_recurrent_category_day_of_month ON FixedRecurrences(category_id, day_of_month);
231
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_fixed_recurrece__category_id_X_day_of_month
232
+ ON FixedRecurrences(category_id, day_of_month);
212
233
213
234
/**
214
235
* A variable balance movement is a balance movement that happens every week.
@@ -220,10 +241,8 @@ CREATE TABLE IF NOT EXISTS VariableRecurrences(
220
241
FOREIGN KEY (category_id) REFERENCES Categories(id) ON DELETE CASCADE,
221
242
UNIQUE(category_id, day_of_week)
222
243
);
223
- CREATE UNIQUE INDEX IF NOT EXISTS idx_variable_recurrence_dayofweek ON VariableRecurrences(
224
- category_id,
225
- day_of_week
226
- );
244
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_variable_recurrence__category_id_X_day_of_week
245
+ ON VariableRecurrences(category_id, day_of_week);
227
246
228
247
/**
229
248
* A seasonal balance movement is a balance movement that happens every year.
@@ -236,11 +255,8 @@ CREATE TABLE IF NOT EXISTS SeasonalRecurrences(
236
255
FOREIGN KEY(category_id) REFERENCES Categories(id) ON DELETE CASCADE,
237
256
UNIQUE(category_id, month, day)
238
257
);
239
- CREATE UNIQUE INDEX IF NOT EXISTS idx_seasonal_balance_movement_monthday ON SeasonalRecurrences(
240
- category_id,
241
- month,
242
- day
243
- );
258
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_seasonal_recurrences__category_id_X_month_X_day
259
+ ON SeasonalRecurrences(category_id, month, day);
244
260
245
261
CREATE TRIGGER IF NOT EXISTS ensure_reference_id_in_one_table_FixedRecurrences
246
262
BEFORE INSERT ON FixedRecurrences
0 commit comments