create extension citext; -- noqa

create table public.ingest_batch
(
    id serial primary key,

    elapsed_ms int not null default 0,
    file_checksum text not null,

    created_at timestamp not null default now()
);

create index idx_ingest_batch_file_checksum on public.ingest_batch (
    file_checksum
);

create table public.meteo_data
(
    id serial primary key,
    batch_id int not null references public.ingest_batch (id),

    location_name citext not null,
    date_of_register date not null,
    max_temp numeric(5, 2) not null,
    min_temp numeric(5, 2) not null,
    rainfall numeric(5, 2) not null,
    cloudiness int not null,

    created_at timestamp not null default now()
);

create index idx_meteo_data_location_name on public.meteo_data (location_name);

create table public.rejected_data
(
    id serial primary key,
    batch_id int not null references public.ingest_batch (id),

    raw_data text not null,
    reason text default null,

    created_at timestamp not null default now()
)
