create table arenda
(
id serial not null
constraint arenda_pkey
primary key,
client_id integer
)
;
create unique index arenda_id_uindex
on arenda (id)
;
create table torg_ploshad
(
id serial not null
constraint torg_ploshad_pkey
primary key,
arenda_id integer not null
constraint torg_ploshad_arenda_id_fk
references arenda,
tt_id integer not null,
begin_datetime timestamp not null,
end_datetime timestamp not null
)
;
create unique index torg_ploshad_id_uindex
on torg_ploshad (id)
;
create table tt
(
id serial not null
constraint tt_pkey
primary key,
etaj integer not null,
ploshad double precision not null,
conditioner boolean not null,
cost money not null
)
;
create unique index tt_id_uindex
on tt (id)
;
alter table torg_ploshad
add constraint torg_ploshad_tt_id_fk
foreign key (tt_id) references tt
;
create table client
(
id serial not null
constraint client_pkey
primary key,
name text not null,
rekvesit text not null,
address text not null,
telephone text not null
)
;
create unique index client_id_uindex
on client (id)
;
alter table arenda
add constraint arenda_client_id_fk
foreign key (client_id) references client
;
create table payment
(
id serial not null
constraint payment_pkey
primary key,
client_id integer not null
constraint payment_client_id_fk
references client,
date date not null,
cost money not null
)
;
create unique index payment_id_uindex
on payment (id)
;