operations

This commit is contained in:
2025-11-15 14:50:03 +01:00
parent 110a6cd4b6
commit bbbe5c7c60
2 changed files with 57 additions and 1 deletions

View File

@@ -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.

View File

@@ -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'))
);
```