-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathscript.sql
27 lines (24 loc) · 840 Bytes
/
script.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
CREATE UNLOGGED TABLE clientes (
id BIGINT PRIMARY KEY,
limite INTEGER NOT NULL,
saldo INTEGER NOT NULL DEFAULT 0
);
CREATE UNLOGGED TABLE transacoes (
id SERIAL PRIMARY KEY,
valor INTEGER NOT NULL,
cliente_id BIGINT NOT NULL,
tipo CHAR(1) NOT NULL,
descricao VARCHAR(10) NOT NULL,
realizada_em TIMESTAMP,
CONSTRAINT fk_cliente_transacoes_id
FOREIGN KEY (cliente_id) REFERENCES clientes(id)
);
CREATE INDEX idx_clientes_id ON clientes (id) INCLUDE (limite, saldo);
CREATE INDEX idx_transacoes_clientes_id ON transacoes (cliente_id);
CREATE INDEX idx_transacoes_clientes_id_realizda_em ON transacoes (cliente_id, realizada_em DESC);
DO $$
BEGIN
INSERT INTO clientes (id, limite)
VALUES (1, 1000 * 100), (2, 800 * 100), (3, 10000 * 100), (4, 100000 * 100), (5, 5000 * 100);
END;
$$;