-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_seed_data.sql
More file actions
467 lines (416 loc) · 15.8 KB
/
05_seed_data.sql
File metadata and controls
467 lines (416 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
-- ============================================================================
-- Finance Analytics Database - Seed Data
-- ============================================================================
-- Description: Populates database with realistic sample data
-- Note: I also inserted myself into the database.
INSERT INTO users (email, first_name, last_name) VALUES
('adamfarahx@email.com', 'Adam', 'Farah'),
('jane.smith@email.com', 'Jane', 'Smith'),
('mike.johnson@email.com', 'Mike', 'Johnson');
-- Main categories
INSERT INTO categories (category_name, category_type, description) VALUES
-- Income categories
('Salary', 'income', 'Regular employment income'),
('Freelance', 'income', 'Freelance or contract work'),
('Investment Income', 'income', 'Dividends, interest, capital gains'),
('Other Income', 'income', 'Miscellaneous income'),
-- Expense categories - Housing
('Housing', 'expense', 'Housing-related expenses'),
('Utilities', 'expense', 'Utilities and services'),
('Internet & Phone', 'expense', 'Communication services'),
-- Expense categories - Food
('Food & Dining', 'expense', 'Food-related expenses'),
('Transportation', 'expense', 'Transportation costs'),
('Healthcare', 'expense', 'Medical and health expenses'),
('Entertainment', 'expense', 'Entertainment and leisure'),
('Shopping', 'expense', 'General shopping'),
('Personal Care', 'expense', 'Personal care and grooming'),
('Education', 'expense', 'Educational expenses'),
('Insurance', 'expense', 'Insurance premiums'),
('Savings & Investments', 'expense', 'Savings and investment contributions'),
('Debt Payments', 'expense', 'Loan and credit card payments'),
('Miscellaneous', 'expense', 'Other expenses');
-- Subcategories (using parent_category_id)
INSERT INTO categories (category_name, category_type, parent_category_id, description)
SELECT 'Rent', 'expense', category_id, 'Monthly rent payments'
FROM categories WHERE category_name = 'Housing';
INSERT INTO categories (category_name, category_type, parent_category_id, description)
SELECT 'Mortgage', 'expense', category_id, 'Mortgage payments'
FROM categories WHERE category_name = 'Housing';
INSERT INTO categories (category_name, category_type, parent_category_id, description)
SELECT 'Groceries', 'expense', category_id, 'Grocery shopping'
FROM categories WHERE category_name = 'Food & Dining';
INSERT INTO categories (category_name, category_type, parent_category_id, description)
SELECT 'Restaurants', 'expense', category_id, 'Dining out'
FROM categories WHERE category_name = 'Food & Dining';
INSERT INTO categories (category_name, category_type, parent_category_id, description)
SELECT 'Gas', 'expense', category_id, 'Vehicle fuel'
FROM categories WHERE category_name = 'Transportation';
INSERT INTO categories (category_name, category_type, parent_category_id, description)
SELECT 'Public Transit', 'expense', category_id, 'Bus, train, subway'
FROM categories WHERE category_name = 'Transportation';
-- Accounts for Adam Farah
INSERT INTO accounts (user_id, account_name, account_type, balance, institution_name, account_number_last4)
SELECT user_id, 'Barclays Current Account', 'checking', 5430.25, 'Barclays', '4892'
FROM users WHERE email = 'adamfarahx@email.com';
INSERT INTO accounts (user_id, account_name, account_type, balance, institution_name, account_number_last4)
SELECT user_id, 'Barclays Saving Account', 'savings', 15000.00, 'Barclays', '7731'
FROM users WHERE email = 'adamfarahx@email.com';
INSERT INTO accounts (user_id, account_name, account_type, balance, institution_name, account_number_last4)
SELECT user_id, 'Natwest Credit Card', 'credit_card', -1250.80, 'NatWest', '3421'
FROM users WHERE email = 'mike.johnson@email.com';
-- Accounts for Jane Smith
INSERT INTO accounts (user_id, account_name, account_type, balance, institution_name, account_number_last4)
SELECT user_id, 'Llyods Current Account', 'checking', 8920.50, 'Lloyds', '5566'
FROM users WHERE email = 'jane.smith@email.com';
INSERT INTO accounts (user_id, account_name, account_type, balance, institution_name, account_number_last4)
SELECT user_id, 'Santander Investment', 'investment', 45000.00, 'Santander', '8899'
FROM users WHERE email = 'jane.smith@email.com';
-- Accounts for Mike Johnson
INSERT INTO accounts (user_id, account_name, account_type, balance, institution_name, account_number_last4)
SELECT user_id, 'Halifax Current Account', 'checking', 3250.75, 'Halifax', '1122'
FROM users WHERE email = 'mike.johnson@email.com';
-- John's salary (monthly income)
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
DATE '2024-01-01',
5500.00,
'credit',
'Monthly salary deposit',
'Amazon'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Salary';
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
DATE '2024-02-01',
5500.00,
'credit',
'Monthly salary deposit',
'Amazon'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Salary';
-- John's rent payments
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
DATE '2024-01-01',
1800.00,
'debit',
'Monthly rent payment',
'Quintain Living Ltd'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Rent';
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
DATE '2024-02-01',
1800.00,
'debit',
'Monthly rent payment',
'Quintain Living Ltd'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Rent';
-- Groceries (multiple transactions)
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
CURRENT_DATE - (random() * 90)::INTEGER,
(random() * 150 + 30)::DECIMAL(12,2),
'debit',
'Grocery shopping',
CASE (random() * 3)::INTEGER
WHEN 0 THEN 'Waitrose'
WHEN 1 THEN 'Tesco'
ELSE 'Sainsburys'
END
FROM accounts a
CROSS JOIN categories c
CROSS JOIN generate_series(1, 20)
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Groceries';
-- Restaurant dining
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
CURRENT_DATE - (random() * 90)::INTEGER,
(random() * 80 + 15)::DECIMAL(12,2),
'debit',
'Dining out',
CASE (random() * 5)::INTEGER
WHEN 0 THEN 'Subway'
WHEN 1 THEN 'Olive Garden'
WHEN 2 THEN 'Starbucks'
WHEN 3 THEN 'Swiss Butter'
ELSE 'Pizza Hut'
END
FROM accounts a
CROSS JOIN categories c
CROSS JOIN generate_series(1, 15)
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Restaurants';
-- Gas/Transportation
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
CURRENT_DATE - (random() * 90)::INTEGER,
(random() * 60 + 30)::DECIMAL(12,2),
'debit',
'Fuel purchase',
CASE (random() * 3)::INTEGER
WHEN 0 THEN 'Shell Gas Station'
WHEN 1 THEN 'Esso'
ELSE 'BP Gas'
END
FROM accounts a
CROSS JOIN categories c
CROSS JOIN generate_series(1, 12)
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Gas';
-- Utilities
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
DATE '2024-01-15',
125.50,
'debit',
'Electric bill',
'British Gas Ltd'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Utilities';
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
DATE '2024-01-15',
89.99,
'debit',
'Internet service',
'Virgin Media Ltd'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Internet & Phone';
-- Entertainment/Shopping
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
CURRENT_DATE - (random() * 90)::INTEGER,
(random() * 100 + 10)::DECIMAL(12,2),
'debit',
'Online purchase',
CASE (random() * 4)::INTEGER
WHEN 0 THEN 'Argos'
WHEN 1 THEN 'H&M'
WHEN 2 THEN 'Currys'
ELSE 'Apple Store'
END
FROM accounts a
CROSS JOIN categories c
CROSS JOIN generate_series(1, 10)
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Shopping';
-- Credit card transactions for John
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
CURRENT_DATE - (random() * 60)::INTEGER,
(random() * 200 + 20)::DECIMAL(12,2),
'debit',
'Credit card purchase',
'Various Merchants'
FROM accounts a
CROSS JOIN categories c
CROSS JOIN generate_series(1, 8)
WHERE a.account_name = 'Natwest Credit Card'
AND c.category_name = 'Shopping';
-- Jane's transactions
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
DATE '2024-02-01',
7200.00,
'credit',
'Monthly salary',
'JP Morgan'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Llyods Current Account'
AND c.category_name = 'Salary';
INSERT INTO transactions (account_id, category_id, transaction_date, amount, transaction_type, description, merchant_name)
SELECT
a.account_id,
c.category_id,
CURRENT_DATE - (random() * 90)::INTEGER,
(random() * 120 + 40)::DECIMAL(12,2),
'debit',
'Grocery shopping',
'Waitrose'
FROM accounts a
CROSS JOIN categories c
CROSS JOIN generate_series(1, 15)
WHERE a.account_name = 'Llyods Current Account'
AND c.category_name = 'Groceries';
-- John's budgets for current month
INSERT INTO budgets (user_id, category_id, amount, start_date, end_date)
SELECT
u.user_id,
c.category_id,
600.00,
DATE_TRUNC('month', CURRENT_DATE)::DATE,
(DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month - 1 day')::DATE
FROM users u
CROSS JOIN categories c
WHERE u.email = 'adamfarahx@email.com'
AND c.category_name = 'Groceries';
INSERT INTO budgets (user_id, category_id, amount, start_date, end_date)
SELECT
u.user_id,
c.category_id,
300.00,
DATE_TRUNC('month', CURRENT_DATE)::DATE,
(DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month - 1 day')::DATE
FROM users u
CROSS JOIN categories c
WHERE u.email = 'adamfarahx@email.com'
AND c.category_name = 'Restaurants';
INSERT INTO budgets (user_id, category_id, amount, start_date, end_date)
SELECT
u.user_id,
c.category_id,
200.00,
DATE_TRUNC('month', CURRENT_DATE)::DATE,
(DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month - 1 day')::DATE
FROM users u
CROSS JOIN categories c
WHERE u.email = 'adamfarahx@email.com'
AND c.category_name = 'Gas';
INSERT INTO budgets (user_id, category_id, amount, start_date, end_date)
SELECT
u.user_id,
c.category_id,
250.00,
DATE_TRUNC('month', CURRENT_DATE)::DATE,
(DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month - 1 day')::DATE
FROM users u
CROSS JOIN categories c
WHERE u.email = 'adamfarahx@email.com'
AND c.category_name = 'Entertainment';
-- Jane's budgets
INSERT INTO budgets (user_id, category_id, amount, start_date, end_date)
SELECT
u.user_id,
c.category_id,
800.00,
DATE_TRUNC('month', CURRENT_DATE)::DATE,
(DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month - 1 day')::DATE
FROM users u
CROSS JOIN categories c
WHERE u.email = 'jane.smith@email.com'
AND c.category_name = 'Groceries';
-- John's recurring bills
INSERT INTO recurring_transactions (account_id, category_id, amount, description, frequency, start_date, next_occurrence, merchant_name)
SELECT
a.account_id,
c.category_id,
1800.00,
'Monthly rent payment',
'monthly',
DATE '2024-01-01',
DATE_TRUNC('month', CURRENT_DATE)::DATE + INTERVAL '1 month',
'Quintain Living Ltd'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Rent';
INSERT INTO recurring_transactions (account_id, category_id, amount, description, frequency, start_date, next_occurrence, merchant_name)
SELECT
a.account_id,
c.category_id,
89.99,
'Internet service',
'monthly',
DATE '2024-01-01',
DATE_TRUNC('month', CURRENT_DATE)::DATE + INTERVAL '1 month',
'Virgin Media Ltd'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Internet & Phone';
INSERT INTO recurring_transactions (account_id, category_id, amount, description, frequency, start_date, next_occurrence, merchant_name)
SELECT
a.account_id,
c.category_id,
14.99,
'Netflix subscription',
'monthly',
DATE '2024-01-01',
DATE_TRUNC('month', CURRENT_DATE)::DATE + INTERVAL '1 month',
'Netflix'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Entertainment';
INSERT INTO recurring_transactions (account_id, category_id, amount, description, frequency, start_date, next_occurrence, merchant_name)
SELECT
a.account_id,
c.category_id,
9.99,
'Spotify Premium',
'monthly',
DATE '2024-01-01',
DATE_TRUNC('month', CURRENT_DATE)::DATE + INTERVAL '1 month',
'Spotify'
FROM accounts a
CROSS JOIN categories c
WHERE a.account_name = 'Barclays Current Account'
AND c.category_name = 'Entertainment';
DO $$
DECLARE
user_count INTEGER;
category_count INTEGER;
account_count INTEGER;
transaction_count INTEGER;
budget_count INTEGER;
recurring_count INTEGER;
BEGIN
SELECT COUNT(*) INTO user_count FROM users;
SELECT COUNT(*) INTO category_count FROM categories;
SELECT COUNT(*) INTO account_count FROM accounts;
SELECT COUNT(*) INTO transaction_count FROM transactions;
SELECT COUNT(*) INTO budget_count FROM budgets;
SELECT COUNT(*) INTO recurring_count FROM recurring_transactions;
RAISE NOTICE '════════════════════════════════════════════════════════';
RAISE NOTICE '✓ Sample data loaded successfully!';
RAISE NOTICE '════════════════════════════════════════════════════════';
RAISE NOTICE 'Data Summary:';
RAISE NOTICE ' • Users: %', user_count;
RAISE NOTICE ' • Categories: %', category_count;
RAISE NOTICE ' • Accounts: %', account_count;
RAISE NOTICE ' • Transactions: %', transaction_count;
RAISE NOTICE ' • Budgets: %', budget_count;
RAISE NOTICE ' • Recurring Transactions: %', recurring_count;
RAISE NOTICE '════════════════════════════════════════════════════════';
END $$;