1+ DROP DATABASE IF EXISTS banking;
2+
3+ CREATE DATABASE banking ;
4+
5+ \c banking;
6+
7+
8+ CREATE TABLE IF NOT EXISTS " account" (
9+ " id" bigserial PRIMARY KEY ,
10+ " net_salary" double precision ,
11+ " account_number" varchar (255 ) UNIQUE,
12+ " firstname" varchar (255 ),
13+ " account_type" text ,
14+ " bank" varchar (255 ),
15+ " birthdate" date ,
16+ " updated_at" timestamp DEFAULT now(),
17+ " lastname" varchar (255 )
18+ );
19+
20+ CREATE TABLE IF NOT EXISTS " account_balance" (
21+ " id" bigserial PRIMARY KEY ,
22+ " checked_at" timestamp DEFAULT now(),
23+ " id_account" bigint NOT NULL REFERENCES " account" (id) ON DELETE CASCADE ,
24+ " current_balance" double precision
25+ );
26+
27+ CREATE TABLE IF NOT EXISTS " category" (
28+ " id" bigserial PRIMARY KEY ,
29+ " only_on" text NOT NULL ,
30+ " comments" text ,
31+ " name" varchar (255 ) NOT NULL UNIQUE,
32+ " id_account" bigint REFERENCES " account" (id) ON DELETE CASCADE
33+ );
34+
35+
36+ CREATE TABLE IF NOT EXISTS " interest" (
37+ " id" bigserial PRIMARY KEY ,
38+ " id_account" bigint NOT NULL REFERENCES " account" (id) ON DELETE CASCADE ,
39+ " effective_interest" integer ,
40+ " first_interest" integer NOT NULL ,
41+ " deadline" timestamp
42+ );
43+
44+ CREATE TABLE IF NOT EXISTS " transactiongroup" (
45+ " id" bigserial PRIMARY KEY ,
46+ " id_account" bigint NOT NULL REFERENCES " account" (id) ON DELETE CASCADE ,
47+ " updated_at" timestamp DEFAULT now(),
48+ " label" varchar (255 ) NOT NULL
49+ );
50+
51+ CREATE TABLE IF NOT EXISTS " transaction" (
52+ " effect_date" date DEFAULT now(),
53+ " amount" double precision NOT NULL ,
54+ " receiver" bigint REFERENCES " account" (id) ON DELETE CASCADE ,
55+ " created_at" timestamp DEFAULT now(),
56+ " label" varchar (255 ),
57+ " type" text ,
58+ " id" bigserial PRIMARY KEY ,
59+ " reference" varchar (255 ) UNIQUE,
60+ " id_account" bigint NOT NULL REFERENCES " account" (id) ON DELETE CASCADE ,
61+ " planed_at" timestamp ,
62+ " category" bigint REFERENCES " category" (id) ON DELETE CASCADE ,
63+ " id_group" bigint REFERENCES " transactiongroup" (id) ON DELETE CASCADE ,
64+ " status" text
65+ );
0 commit comments