forked from zanfranceschi/rinha-de-backend-2024-q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
40 lines (33 loc) · 937 Bytes
/
schema.sql
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
CREATE UNLOGGED TABLE clients (
id SERIAL PRIMARY KEY,
balance INTEGER NOT NULL DEFAULT 0,
credit_limit INTEGER NOT NULL DEFAULT 0
);
CREATE UNLOGGED TABLE transactions (
id SERIAL PRIMARY KEY,
client_id INTEGER NOT NULL,
amount INTEGER NOT NULL,
transaction_type VARCHAR(1) NOT NULL,
description VARCHAR(10) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT current_timestamp,
CONSTRAINT fk_transactions_client_id FOREIGN KEY (client_id) REFERENCES clients (id)
);
ALTER TABLE
transactions DISABLE ROW LEVEL SECURITY;
ALTER TABLE
transactions
SET
(autovacuum_enabled = FALSE);
CREATE INDEX IF NOT EXISTS transactions_client_id_idx ON transactions(client_id ASC);
---
DO $$ BEGIN
INSERT INTO
clients (id, credit_limit, balance)
VALUES
(1, 100000, 0),
(2, 80000, 0),
(3, 1000000, 0),
(4, 10000000, 0),
(5, 500000, 0);
END;
$$