operations
This commit is contained in:
@@ -59,7 +59,6 @@ Il existe deux méthodes pour gérer le type.
|
|||||||
2. utiliser une énumération `enum`.
|
2. utiliser une énumération `enum`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### 1.2 Vérifications
|
#### 1.2 Vérifications
|
||||||
|
|
||||||
- Lister tous les titulaires. Pour réutiliser rapidement la requête enregistrer la dans une vue.
|
- Lister tous les titulaires. Pour réutiliser rapidement la requête enregistrer la dans une vue.
|
||||||
|
|||||||
@@ -56,3 +56,60 @@ create table bank (
|
|||||||
"name" text
|
"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'))
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user