-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathinit.sql
30 lines (27 loc) · 928 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
CREATE UNLOGGED TABLE "customers" (
"id" SERIAL NOT NULL PRIMARY KEY,
"limite" INTEGER NOT NULL,
"saldo" BIGINT NOT NULL DEFAULT 0
);
CREATE UNLOGGED TABLE "transactions" (
"id" SERIAL NOT NULL PRIMARY KEY,
"customer_id" INTEGER NOT NULL,
"tipo" CHARACTER(1) NOT NULL,
"valor" BIGINT NOT NULL,
"descricao" VARCHAR(10) NOT NULL,
"realizada_em" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "fk_clientes_transacoes_id"
FOREIGN KEY ("customer_id") REFERENCES customers ("id")
);
CREATE INDEX "fk_transactions_customer_id" ON "public"."transactions" ("customer_id");
DO
$$
BEGIN
INSERT INTO customers (limite, saldo)
VALUES (1000 * 100, 0),
(800 * 100, 0),
(10000 * 100, 0),
(100000 * 100, 0),
(5000 * 100, 0);
END;
$$;