forked from zanfranceschi/rinha-de-backend-2024-q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
34 lines (27 loc) · 864 Bytes
/
init.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
GRANT ALL PRIVILEGES ON DATABASE rinha_db TO postgres;
CREATE UNLOGGED TABLE clients
(
id SERIAL PRIMARY KEY,
name varchar(10) NOT NULL,
max_limit integer NOT NULL,
balance integer NOT NULL CHECK (balance + max_limit >= 0)
);
CREATE UNLOGGED TABLE transactions
(
id SERIAL PRIMARY KEY,
client_id integer NOT NULL,
value integer NOT NULL,
type char NOT NULL CHECK (type IN ('c', 'd')),
description varchar(10) NOT NULL,
"timestamp" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
CONSTRAINT fk_client_id FOREIGN KEY (client_id)
REFERENCES public.clients (id) MATCH SIMPLE
)
;
CREATE INDEX idx_client_id ON transactions (client_id);
INSERT INTO clients(name, max_limit, balance)
VALUES ('one', 100000, 0),
('two', 80000, 0),
('three', 1000000, 0),
('four', 10000000, 0),
('five', 500000, 0);