<gh_stars>0
create table public.accountants
(
    id int8 generated by default as identity,
    create_at timestamp not null,
    firs_name varchar(255) not null,
    last_name varchar(255) not null,
    patronymic varchar(255) not null,
    status varchar(255) not null,
    update_at timestamp not null,
    primary key (id)
);

create table public.aliases
(
    id int8 generated by default as identity,
    create_at timestamp not null,
    status varchar(255) not null,
    update_at timestamp not null,
    user_id uuid not null,
    bill_id int8 not null,
    primary key (id)
);

create table public.assets
(
    id int8 generated by default as identity,
    asset_type varchar(255) not null,
    create_at timestamp not null,
    full_name varchar(255) not null,
    name varchar(255) not null,
    owner varchar(255) not null,
    pow int4 not null,
    status varchar(255) not null,
    update_at timestamp not null,
    primary key (id)
);

create table public.bills
(
    id int8 generated by default as identity,
    address varchar(255) not null,
    amount numeric(19, 2) not null,
    amount_paid numeric(19, 2) not null,
    create_at timestamp not null,
    order_id int8 not null,
    status varchar(255) not null,
    update_at timestamp not null,
    asset_id int8,
    payment_type_id int8,
    who_id int8,
    whom_id int8,
    primary key (id)
);

create table public.current_rates
(
    id int8 generated by default as identity,
    asset_name varchar(255) not null,
    create_at timestamp not null,
    status varchar(255) not null,
    update_at timestamp not null,
    primary key (id)
);

create table public.payment_type
(
    id int8 generated by default as identity,
    alias varchar(255) not null,
    create_at timestamp not null,
    status varchar(255) not null,
    update_at timestamp not null,
    primary key (id)
);

create table public.rates
(
    id int8 generated by default as identity,
    asset_name_quote varchar(255) not null,
    create_at timestamp not null,
    rate DECIMAL(32, 13) not null,
    status varchar(255) not null,
    time varchar(255) not null,
    update_at timestamp not null,
    rate_id int8,
    primary key (id)
);

create table public.whoms
(
    id int8 generated by default as identity,
    create_at timestamp not null,
    firs_name varchar(150) not null,
    last_name varchar(150) not null,
    patronymic varchar(150) not null,
    status varchar(255) not null,
    update_at timestamp not null,
    primary key (id)
);

create table public.whos
(
    id int8 generated by default as identity,
    create_at timestamp not null,
    firs_name varchar(150) not null,
    last_name varchar(150) not null,
    patronymic varchar(150) not null,
    status varchar(255) not null,
    update_at timestamp not null,
    primary key (id)
);

create index alias_user_id_idx on public.aliases (user_id);

alter table if exists public.aliases drop constraint if exists uk_alias_user_id_login;

alter table if exists public.aliases add constraint uk_alias_user_id_login unique (user_id);

create index asset_name_idx on public.assets (name);

alter table if exists public.assets drop constraint if exists uk_asset_name;

alter table if exists public.assets add constraint uk_asset_name unique (name);

alter table if exists public.assets drop constraint if exists uk_asset_full_name;

alter table if exists public.assets add constraint uk_asset_full_name unique (full_name);

create index payment_types_alias_idx on public.payment_type (alias);

alter table if exists public.payment_type drop constraint if exists uk_payment_types_alias;

alter table if exists public.payment_type add constraint uk_payment_types_alias unique (alias);

create table bill_transfers (bill_id int8 not null, transfers varchar(255));

alter table if exists public.aliases add constraint alias_bill_fk foreign key (bill_id) references public.bills;

alter table if exists public.bills add constraint asset_bill_fk foreign key (asset_id) references public.assets;

alter table if exists public.bills add constraint bill_payment_type_fk foreign key (payment_type_id) references public.payment_type;

alter table if exists public.bills add constraint bill_who_fk foreign key (who_id) references public.whos;

alter table if exists public.bills add constraint bill_whom_fk foreign key (whom_id) references public.whoms;

alter table if exists public.rates add constraint current_rates_rate_fk foreign key (rate_id) references public.current_rates;

alter table if exists bill_transfers add constraint biil_transfer_fk foreign key (bill_id) references public.bills;
