create table cartridges
(
    id         uuid primary key,
    name       varchar(255)                        not null,
    created_at timestamp default current_timestamp not null,
    meta       json                                not null
);

create table loads
(
    id           uuid primary key,
    cartridge_id uuid                                not null,
    col          float4                              not null,
    powder_id    uuid                                not null,
    powder_gr    float4                              not null,
    primer_id    uuid                                not null,
    bullet_id    uuid                                not null,
    photo        bytea                               not null,
    created_at   timestamp default current_timestamp not null,
    meta         json                                not null,
    constraint loads_bullets_id_fk
        foreign key (bullet_id) references bullets (id),
    constraint loads_powders_id_fk
        foreign key (powder_id) references powders (id),
    constraint loads_primers_id_fk
        foreign key (primer_id) references primers (id),
    constraint loads_cartridges_id_fk
        foreign key (cartridge_id) references cartridges (id)
);

create table bullets
(
    id              uuid primary key,
    name            varchar(255)            not null,
    weight          int                     not null,
    diameter        int                     not null,
    meta            json,
    photo           bytea,
    manufacturer_id uuid                    not null,
    created_at      timestamp default NOW() not null
);


create table manufacturers
(
    id         uuid primary key,
    name       varchar(255)            not null,
    url        varchar(255),
    created_at timestamp default NOW() not null
);

create table powders
(
    id              uuid primary key,
    name            varchar(255)            not null,
    meta            json,
    photo           bytea,
    manufacturer_id uuid                    not null,
    created_at      timestamp default NOW() not null,
    constraint powders_manufacturers_id_fk
        foreign key (manufacturer_id) references manufacturers (id)
);
create table primers
(
    id              uuid primary key,
    name            varchar(255)            not null,
    meta            json,
    photo           bytea,
    manufacturer_id uuid                    not null,
    created_at      timestamp default NOW() not null,
    constraint primers_manufacturers_id_fk
        foreign key (manufacturer_id) references manufacturers (id)
);
