-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathinit.sql
40 lines (35 loc) · 1.04 KB
/
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
34
35
36
37
38
39
40
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE UNLOGGED TABLE IF NOT EXISTS clientes
(
id BIGSERIAL NOT NULL,
limite BIGINT NOT NULL,
saldo BIGINT NOT NULL,
CONSTRAINT pk_clientes PRIMARY KEY (id)
);
create index clientes_id_idx
on clientes (id);
CREATE UNLOGGED TABLE transacoes
(
id BIGSERIAL NOT NULL,
valor BIGINT NOT NULL,
tipo CHAR NOT NULL,
descricao VARCHAR(10) NOT NULL,
realizacao TIMESTAMP WITHOUT TIME ZONE NOT NULL,
cliente_id BIGINT NOT NULL,
CONSTRAINT pk_transacoes PRIMARY KEY (id)
);
ALTER TABLE transacoes
ADD CONSTRAINT FK_TRANSACOES_ON_CLIENTE FOREIGN KEY (cliente_id) REFERENCES clientes (id);
truncate table transacoes cascade;
truncate table clientes cascade;
DO
$$
BEGIN
INSERT INTO clientes (limite, saldo)
VALUES (1000 * 100, 0),
(800 * 100, 0),
(10000 * 100, 0),
(100000 * 100, 0),
(5000 * 100, 0);
END;
$$;