From bbbe5c7c60bdba41467e1bddfefa2b61e8e80450 Mon Sep 17 00:00:00 2001 From: medina5 Date: Sat, 15 Nov 2025 14:50:03 +0100 Subject: [PATCH] operations --- banque.md | 1 - banque.tables.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/banque.md b/banque.md index ac8176e..6c976dd 100644 --- a/banque.md +++ b/banque.md @@ -59,7 +59,6 @@ Il existe deux méthodes pour gérer le type. 2. utiliser une énumération `enum`. - #### 1.2 Vérifications - Lister tous les titulaires. Pour réutiliser rapidement la requête enregistrer la dans une vue. diff --git a/banque.tables.md b/banque.tables.md index 718d95a..7291ce2 100644 --- a/banque.tables.md +++ b/banque.tables.md @@ -56,3 +56,60 @@ create table bank ( "name" text ); ``` + +## 2. Les monnaies + +```sql +create table currency ( + "code" text primary key +); +``` + +```sql +create table exchange_rate ( + "currency_code" text references currency(code) on delete cascade, + "date" date , + "rate" decimal not null, + primary key (currency_code, date) +); +``` + +## 3. Les comptes + +```sql +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, + "currency_code" text not null references currency (code) +); +``` + +```sql +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) not null default 1 check (share > 0 and share <= 1), + primary key (account_id, holder_id) +); +``` + +### 4. Les transactions + +```sql +create table transaction ( + "id" bigint primary key generated always as identity, + "transaction_date" timestamp not null default current_timestamp, + amount decimal not null check (amount > 0) +); +``` + +```sql +create table operation ( + "id" bigint primary key generated always as identity, + "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')) +); +```