-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathschema.sql
47 lines (40 loc) · 1.38 KB
/
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
41
42
43
44
45
46
47
CREATE TABLE clientes
(
id INT PRIMARY KEY,
limite INTEGER NOT NULL
);
CREATE INDEX id_cliente ON clientes USING HASH (id);
INSERT INTO clientes (id, limite)
VALUES (1, 100000),
(2, 80000),
(3, 1000000),
(4, 10000000),
(5, 500000);
CREATE TABLE saldos
(
cliente_id INTEGER NOT NULL,
balanco INTEGER NOT NULL DEFAULT 0,
limite INTEGER NOT NULL DEFAULT 0,
criado_em TIMESTAMP NOT NULL DEFAULT NOW(),
CHECK (balanco >= (limite * -1))
);
CREATE INDEX saldos_cliente_id_idx ON public.saldos USING btree (cliente_id, criado_em DESC);
INSERT INTO saldos (cliente_id, limite)
SELECT id, limite FROM clientes;
CREATE TABLE transacoes
(
cliente_id INTEGER NOT NULL,
valor INTEGER NOT NULL,
operacao CHAR(1) NOT NULL,
descricao VARCHAR(10) NOT NULL,
criado_em TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE INDEX transacoes_cliente_id_idx ON public.transacoes (cliente_id,criado_em DESC);
CREATE USER api01 WITH PASSWORD 'api01_pass';
CREATE USER api02 WITH PASSWORD 'api02_pass';
GRANT ALL ON DATABASE rinha_db TO api01;
GRANT ALL ON ALL TABLES IN SCHEMA public TO api01;
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO api01;
GRANT ALL ON DATABASE rinha_db TO api02;
GRANT ALL ON ALL TABLES IN SCHEMA public TO api02;
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO api02;