-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathscript.sql
44 lines (38 loc) · 1016 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
CREATE TABLE clients (
"id" SERIAL NOT NULL,
"limit" INTEGER NOT NULL,
CONSTRAINT "clients_pkey" PRIMARY KEY ("id")
);
CREATE TABLE "balances" (
"id" SERIAL NOT NULL,
"client_id" INTEGER NOT NULL,
"value" INTEGER NOT NULL,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT timezone('America/Sao_Paulo', now()),
CONSTRAINT "balances_pkey" PRIMARY KEY ("id")
);
CREATE TABLE "transactions" (
"id" SERIAL NOT NULL,
"value" INTEGER NOT NULL,
"client_id" INTEGER NOT NULL,
"operation_type" CHAR(1) NOT NULL,
"description" VARCHAR(10) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE DEFAULT timezone('America/Sao_Paulo', now()),
CONSTRAINT "transactions_pkey" PRIMARY KEY ("id"),
FOREIGN KEY (client_id) REFERENCES clients (id)
);
CREATE UNIQUE INDEX "balances_client_id" ON "balances" ("client_id");
INSERT INTO
"clients" ("limit")
VALUES
(100000),
(80000),
(1000000),
(10000000),
(500000);
INSERT INTO
"balances" ("client_id", "value")
SELECT
"id",
0
FROM
"clients";