source: server/db/data_load.sql@ 9e6d8a2

main
Last change on this file since 9e6d8a2 was b715712, checked in by Stefan <trsunovstefan@…>, 8 weeks ago

Add the server side and configuration

  • Property mode set to 100644
File size: 9.3 KB
Line 
1-- data_load.sql
2-- EduBerza - sample data
3-- Course: Databases 2025/2026 Winter, FINKI UKIM
4--
5-- Idempotent. Truncates all tables in the `project` schema and reloads
6-- deterministic sample data. Run schema_creation.sql first if tables do
7-- not yet exist.
8--
9-- All sample users have the password: test123
10
11SET search_path TO project, public;
12
13TRUNCATE TABLE
14 project.watchlist_items,
15 project.watchlists,
16 project.market_candles,
17 project.market_trades,
18 project.transactions,
19 project.orders,
20 project.holdings,
21 project.markets,
22 project.crypto,
23 project.users
24RESTART IDENTITY CASCADE;
25
26-- ============================================================================
27-- CRYPTO
28-- ============================================================================
29INSERT INTO project.crypto (id, symbol, name) VALUES
30 ('11111111-1111-1111-1111-111111111111', 'BTC', 'Bitcoin'),
31 ('22222222-2222-2222-2222-222222222222', 'ETH', 'Ethereum'),
32 ('33333333-3333-3333-3333-333333333333', 'ADA', 'Cardano'),
33 ('44444444-4444-4444-4444-444444444444', 'SOL', 'Solana'),
34 ('55555555-5555-5555-5555-555555555555', 'DOGE', 'Dogecoin');
35
36-- ============================================================================
37-- MARKETS (all quoted in USD)
38-- ============================================================================
39INSERT INTO project.markets (id, crypto_id, quote_currency, is_active) VALUES
40 ('a1111111-1111-1111-1111-111111111111', '11111111-1111-1111-1111-111111111111', 'USD', true),
41 ('a2222222-2222-2222-2222-222222222222', '22222222-2222-2222-2222-222222222222', 'USD', true),
42 ('a3333333-3333-3333-3333-333333333333', '33333333-3333-3333-3333-333333333333', 'USD', true),
43 ('a4444444-4444-4444-4444-444444444444', '44444444-4444-4444-4444-444444444444', 'USD', true),
44 ('a5555555-5555-5555-5555-555555555555', '55555555-5555-5555-5555-555555555555', 'USD', true);
45
46-- ============================================================================
47-- USERS
48-- Password for all: test123 (stored as sha256 hex hash)
49-- ============================================================================
50INSERT INTO project.users (id, username, email, full_name, password_hash, available_balance, invested_balance) VALUES
51 ('b1111111-1111-1111-1111-111111111111', 'alice', 'alice@example.com', 'Alice Johnson',
52 encode(digest('test123', 'sha256'), 'hex'), 10000.0000, 0),
53 ('b2222222-2222-2222-2222-222222222222', 'bob', 'bob@example.com', 'Bob Smith',
54 encode(digest('test123', 'sha256'), 'hex'), 5000.0000, 0),
55 ('b3333333-3333-3333-3333-333333333333', 'charlie', 'charlie@example.com', 'Charlie Davis',
56 encode(digest('test123', 'sha256'), 'hex'), 2500.0000, 0);
57
58-- ============================================================================
59-- MARKET TRADES
60-- Recent simulated trades per market, used as price source.
61-- ============================================================================
62INSERT INTO project.market_trades (market_id, executed_at, price, quantity, side, source) VALUES
63 -- BTC/USD around $67,000
64 ('a1111111-1111-1111-1111-111111111111', now() - interval '10 min', 66850.250000, 0.120000, 'buy', 'simulation'),
65 ('a1111111-1111-1111-1111-111111111111', now() - interval '8 min', 66910.500000, 0.075000, 'sell', 'simulation'),
66 ('a1111111-1111-1111-1111-111111111111', now() - interval '5 min', 67020.750000, 0.200000, 'buy', 'simulation'),
67 ('a1111111-1111-1111-1111-111111111111', now() - interval '2 min', 67105.100000, 0.050000, 'buy', 'simulation'),
68 ('a1111111-1111-1111-1111-111111111111', now() - interval '30 second', 67140.000000, 0.030000, 'sell', 'simulation'),
69 -- ETH/USD around $3,500
70 ('a2222222-2222-2222-2222-222222222222', now() - interval '10 min', 3490.500000, 1.500000, 'buy', 'simulation'),
71 ('a2222222-2222-2222-2222-222222222222', now() - interval '6 min', 3502.750000, 0.800000, 'sell', 'simulation'),
72 ('a2222222-2222-2222-2222-222222222222', now() - interval '2 min', 3515.250000, 2.100000, 'buy', 'simulation'),
73 ('a2222222-2222-2222-2222-222222222222', now() - interval '30 second', 3520.000000, 0.650000, 'buy', 'simulation'),
74 -- ADA/USD around $0.45
75 ('a3333333-3333-3333-3333-333333333333', now() - interval '10 min', 0.446500, 500.000000, 'buy', 'simulation'),
76 ('a3333333-3333-3333-3333-333333333333', now() - interval '3 min', 0.452000, 1200.000000, 'buy', 'simulation'),
77 ('a3333333-3333-3333-3333-333333333333', now() - interval '30 second', 0.453750, 800.000000, 'sell', 'simulation'),
78 -- SOL/USD around $165
79 ('a4444444-4444-4444-4444-444444444444', now() - interval '10 min', 164.250000, 10.000000, 'buy', 'simulation'),
80 ('a4444444-4444-4444-4444-444444444444', now() - interval '4 min', 165.500000, 5.500000, 'sell', 'simulation'),
81 ('a4444444-4444-4444-4444-444444444444', now() - interval '30 second', 166.100000, 8.000000, 'buy', 'simulation'),
82 -- DOGE/USD around $0.12
83 ('a5555555-5555-5555-5555-555555555555', now() - interval '10 min', 0.118500, 10000.000000, 'buy', 'simulation'),
84 ('a5555555-5555-5555-5555-555555555555', now() - interval '3 min', 0.121250, 7500.000000, 'sell', 'simulation'),
85 ('a5555555-5555-5555-5555-555555555555', now() - interval '30 second', 0.122000, 12000.000000, 'buy', 'simulation');
86
87-- ============================================================================
88-- MARKET CANDLES (1h aggregates, last 5 hours per market)
89-- ============================================================================
90INSERT INTO project.market_candles (market_id, timeframe, open, high, low, close, volume, candle_time) VALUES
91 ('a1111111-1111-1111-1111-111111111111', '1h', 66200, 66500, 66050, 66400, 12.50, date_trunc('hour', now() - interval '5 hour')),
92 ('a1111111-1111-1111-1111-111111111111', '1h', 66400, 66800, 66380, 66700, 15.30, date_trunc('hour', now() - interval '4 hour')),
93 ('a1111111-1111-1111-1111-111111111111', '1h', 66700, 66950, 66650, 66900, 11.80, date_trunc('hour', now() - interval '3 hour')),
94 ('a1111111-1111-1111-1111-111111111111', '1h', 66900, 67100, 66800, 67050, 14.20, date_trunc('hour', now() - interval '2 hour')),
95 ('a1111111-1111-1111-1111-111111111111', '1h', 67050, 67200, 66900, 67140, 10.75, date_trunc('hour', now() - interval '1 hour')),
96 ('a2222222-2222-2222-2222-222222222222', '1h', 3460, 3490, 3450, 3485, 120.0, date_trunc('hour', now() - interval '5 hour')),
97 ('a2222222-2222-2222-2222-222222222222', '1h', 3485, 3510, 3480, 3500, 135.0, date_trunc('hour', now() - interval '4 hour')),
98 ('a2222222-2222-2222-2222-222222222222', '1h', 3500, 3520, 3495, 3515, 110.0, date_trunc('hour', now() - interval '3 hour')),
99 ('a2222222-2222-2222-2222-222222222222', '1h', 3515, 3525, 3500, 3520, 125.5, date_trunc('hour', now() - interval '2 hour')),
100 ('a2222222-2222-2222-2222-222222222222', '1h', 3520, 3530, 3510, 3520, 140.0, date_trunc('hour', now() - interval '1 hour'));
101
102-- ============================================================================
103-- EXAMPLE ORDERS, HOLDINGS AND TRANSACTIONS for alice
104-- Shows a fully-filled market buy and its resulting holding & ledger entry.
105-- ============================================================================
106INSERT INTO project.orders (id, user_id, market_id, side, type, status, quantity, price, placed_at, executed_at) VALUES
107 ('c1111111-1111-1111-1111-111111111111',
108 'b1111111-1111-1111-1111-111111111111',
109 'a2222222-2222-2222-2222-222222222222',
110 'buy', 'market', 'executed', 0.5000, 3500.000000,
111 now() - interval '1 hour', now() - interval '1 hour');
112
113INSERT INTO project.holdings (user_id, crypto_id, quantity, avg_price, updated_at) VALUES
114 ('b1111111-1111-1111-1111-111111111111',
115 '22222222-2222-2222-2222-222222222222',
116 0.5000, 3500.000000, now() - interval '1 hour');
117
118INSERT INTO project.transactions (user_id, type, amount, currency, related_order, description) VALUES
119 ('b1111111-1111-1111-1111-111111111111', 'deposit', 10000.0000, 'USD', NULL,
120 'Initial virtual deposit'),
121 ('b1111111-1111-1111-1111-111111111111', 'buy', -1750.0000, 'USD',
122 'c1111111-1111-1111-1111-111111111111',
123 'Market buy 0.5 ETH @ 3500.00');
124
125-- After the buy, alice's invested_balance reflects the used funds.
126UPDATE project.users
127 SET available_balance = 10000.0000 - 1750.0000,
128 invested_balance = 1750.0000,
129 updated_at = now()
130 WHERE id = 'b1111111-1111-1111-1111-111111111111';
131
132-- ============================================================================
133-- WATCHLISTS
134-- ============================================================================
135INSERT INTO project.watchlists (id, user_id, name) VALUES
136 ('d1111111-1111-1111-1111-111111111111', 'b1111111-1111-1111-1111-111111111111', 'Favorites'),
137 ('d2222222-2222-2222-2222-222222222222', 'b2222222-2222-2222-2222-222222222222', 'Bobs Picks');
138
139INSERT INTO project.watchlist_items (watchlist_id, crypto_id) VALUES
140 ('d1111111-1111-1111-1111-111111111111', '11111111-1111-1111-1111-111111111111'),
141 ('d1111111-1111-1111-1111-111111111111', '22222222-2222-2222-2222-222222222222'),
142 ('d1111111-1111-1111-1111-111111111111', '44444444-4444-4444-4444-444444444444'),
143 ('d2222222-2222-2222-2222-222222222222', '11111111-1111-1111-1111-111111111111'),
144 ('d2222222-2222-2222-2222-222222222222', '55555555-5555-5555-5555-555555555555');
Note: See TracBrowser for help on using the repository browser.