forked from zanfranceschi/rinha-de-backend-2024-q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
75 lines (59 loc) · 1.97 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
SET default_tablespace = '';
SET default_table_access_method = heap;
CREATE TABLE public."Clientes" (
"Id" integer NOT NULL,
"Limite" integer NOT NULL,
"Saldo" integer NOT NULL
);
ALTER TABLE public."Clientes" OWNER TO postgres;
ALTER TABLE public."Clientes" ALTER COLUMN "Id" ADD GENERATED BY DEFAULT AS IDENTITY (
SEQUENCE NAME public."Clientes_Id_seq"
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
CREATE TABLE public."Transacoes" (
"Id" integer NOT NULL,
"Valor" integer NOT NULL,
"Tipo" character(1) NOT NULL,
"Descricao" text NOT NULL,
"Realizada_Em" timestamp with time zone NOT NULL,
"ClienteId" integer NOT NULL
);
ALTER TABLE public."Transacoes" OWNER TO postgres;
ALTER TABLE public."Transacoes" ALTER COLUMN "Id" ADD GENERATED BY DEFAULT AS IDENTITY (
SEQUENCE NAME public."Transacoes_Id_seq"
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
COPY public."Clientes" ("Id", "Limite", "Saldo") FROM stdin;
1 100000 0
2 80000 0
3 1000000 0
4 10000000 0
5 500000 0
\.
SELECT pg_catalog.setval('public."Clientes_Id_seq"', 1, false);
SELECT pg_catalog.setval('public."Transacoes_Id_seq"', 1, false);
ALTER TABLE ONLY public."Clientes"
ADD CONSTRAINT "PK_Clientes" PRIMARY KEY ("Id");
ALTER TABLE ONLY public."Transacoes"
ADD CONSTRAINT "PK_Transacaoes" PRIMARY KEY ("Id");
CREATE INDEX "IX_Transacaos_ClienteId" ON public."Transacoes" USING btree ("ClienteId");
ALTER TABLE ONLY public."Transacoes"
ADD CONSTRAINT "FK_Transacoes_Clientes_ClienteId" FOREIGN KEY ("ClienteId") REFERENCES public."Clientes"("Id") ON DELETE CASCADE;