This commit is contained in:
2025-11-07 21:29:15 +01:00
parent 6971d03d71
commit 3c78b69a23
3 changed files with 78 additions and 17 deletions

View File

@@ -9,7 +9,7 @@ create type holder_type as enum ('BANK', 'PERSON', 'COMPANY');
create table holder (
"id" bigint primary key generated always as identity, -- identifiant unique
"type" holder_type not null,
"type" holder_type not null,
"created_at" timestamp not null default current_timestamp -- date et heure de création
);
@@ -28,7 +28,7 @@ create table person (
"id" bigint primary key references holder(id) on delete cascade,
"firstname" text not null,
"lastname" text not null,
"birthdate" date not null
"birthdate" date not null check (birthdate <= current_date - interval '15 years')
);
/*
@@ -47,8 +47,8 @@ create table currency (
create table exchange_rate (
"currency_code" text references currency(code) on delete cascade,
"date" date,
"rate" decimal,
"date" date ,
"rate" decimal not null,
primary key (currency_code, date)
);
/*
@@ -59,7 +59,7 @@ create table account (
"id" bigint primary key generated always as identity,
"opened_at" date not null default current_date,
"balance" numeric(18,6) not null default 0 check (balance >= 0),
"currency_code" text references currency (code)
"currency_code" text not null references currency (code)
);
/*
@@ -71,23 +71,21 @@ create table account (
create table account_holder (
"account_id" int not null references account(id) on delete cascade,
"holder_id" int not null references holder(id) on delete cascade,
"share" decimal(4,3) default 1 check (share > 0 and share <= 1),
"share" decimal(4,3) not null default 1 check (share > 0 and share <= 1),
primary key (account_id, holder_id)
);
create table transaction (
"id" bigint primary key generated always as identity,
"transaction_date" timestamp default current_timestamp,
amount decimal check (amount > 0)
"transaction_date" timestamp not null default current_timestamp,
amount decimal not null check (amount > 0)
);
create table operation (
"id" bigint primary key generated always as identity,
"transaction_id" bigint references transaction(id),
"account_id" bigint references account(id),
amount decimal check (amount > 0),
direction text check (direction in ('DEBIT', 'CREDIT'))
"transaction_id" bigint not null references transaction(id),
"account_id" bigint not null references account(id),
amount decimal not null check (amount > 0),
direction text not null check (direction in ('DEBIT', 'CREDIT'))
);