banque
This commit is contained in:
@@ -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')
|
||||
);
|
||||
|
||||
/*
|
||||
@@ -48,7 +48,7 @@ create table currency (
|
||||
create table exchange_rate (
|
||||
"currency_code" text references currency(code) on delete cascade,
|
||||
"date" date ,
|
||||
"rate" decimal,
|
||||
"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'))
|
||||
);
|
||||
|
||||
@@ -357,8 +357,8 @@ erDiagram
|
||||
}
|
||||
|
||||
account_holder {
|
||||
bigint account_id FK
|
||||
bigint holder_id FK
|
||||
bigint account_id PK,FK
|
||||
bigint holder_id PK,FK
|
||||
decimal share
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ erDiagram
|
||||
|
||||
exchange_rate {
|
||||
date date PK
|
||||
text currency_code PK
|
||||
text currency_code PK,FK
|
||||
decimal rate
|
||||
}
|
||||
|
||||
|
||||
63
banque.proc.sql
Normal file
63
banque.proc.sql
Normal file
@@ -0,0 +1,63 @@
|
||||
create or replace procedure add_person (
|
||||
p_firstname text,
|
||||
p_lastname text,
|
||||
p_birthdate date
|
||||
)
|
||||
language plpgsql
|
||||
as $$
|
||||
declare
|
||||
v_holder_id bigint;
|
||||
begin
|
||||
|
||||
insert into holder(type) values ('PERSON')
|
||||
returning id into v_holder_id;
|
||||
|
||||
insert into person(id, firstname, lastname, birthdate)
|
||||
values (v_holder_id, p_firstname, p_lastname, p_birthdate);
|
||||
|
||||
raise notice 'Titulaire créé : % = % %',
|
||||
v_holder_id, p_firstname, p_lastname;
|
||||
end;
|
||||
$$;
|
||||
|
||||
create or replace procedure add_bank (
|
||||
name text
|
||||
)
|
||||
language plpgsql
|
||||
as $$
|
||||
declare
|
||||
v_holder_id bigint;
|
||||
begin
|
||||
|
||||
insert into holder(type) values ('BANK')
|
||||
returning id into v_holder_id;
|
||||
|
||||
insert into bank(id, name)
|
||||
values (v_holder_id, p_name);
|
||||
|
||||
raise notice 'Titulaire créé : % = %',
|
||||
v_holder_id, p_name;
|
||||
end;
|
||||
$$;
|
||||
|
||||
create or replace procedure add_company (
|
||||
p_name text,
|
||||
p_registration_number text,
|
||||
p_created_at date
|
||||
)
|
||||
language plpgsql
|
||||
as $$
|
||||
declare
|
||||
v_holder_id bigint;
|
||||
begin
|
||||
|
||||
insert into holder(type) values ('COMPANY')
|
||||
returning id into v_holder_id;
|
||||
|
||||
insert into company(id, name, registration_number, created_at)
|
||||
values (v_holder_id, p_name, p_registration_number, p_created_at);
|
||||
|
||||
raise notice 'Titulaire créé : % = % %',
|
||||
v_holder_id, p_name, p_registration_number;
|
||||
end;
|
||||
$$;
|
||||
Reference in New Issue
Block a user