forked from zanfranceschi/rinha-de-backend-2024-q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
33 lines (29 loc) · 875 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
SET client_encoding = 'UTF8';
SET client_min_messages = warning;
SET row_security = off;
CREATE UNLOGGED TABLE IF NOT EXISTS clientes(
id SERIAL PRIMARY KEY,
nome VARCHAR(255) NOT NULL,
limite INTEGER NOT NULL,
saldo INTEGER DEFAULT 0 NOT NULL
);
CREATE UNLOGGED TABLE IF NOT EXISTS transacoes(
id SERIAL PRIMARY KEY,
cliente_id INTEGER NOT NULL REFERENCES clientes (id),
valor INTEGER NOT NULL,
tipo CHAR(1) NOT NULL,
descricao VARCHAR(10),
realizada_em TIMESTAMP DEFAULT current_timestamp
);
CREATE INDEX transacoes_cliente_id_idx ON transacoes (cliente_id, realizada_em DESC);
DO $$
BEGIN
INSERT INTO clientes (nome, limite)
VALUES
('o barato sai caro', 1000 * 100),
('zan corp ltda', 800 * 100),
('les cruders', 10000 * 100),
('padaria joia de cocaia', 100000 * 100),
('kid mais', 5000 * 100);
END;
$$;