From f1bb00ef09a23f5e7a496f000df18106158e07de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20P=C3=A9rez?= Date: Wed, 29 Oct 2025 16:45:20 +0100 Subject: [PATCH] add unique constraints --- service_a/internal/domains/meteo/domain.go | 1 + service_a/server/database/migrations/001_data.up.sql | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/service_a/internal/domains/meteo/domain.go b/service_a/internal/domains/meteo/domain.go index 26ac2a5..bfb20eb 100644 --- a/service_a/internal/domains/meteo/domain.go +++ b/service_a/internal/domains/meteo/domain.go @@ -66,6 +66,7 @@ var ( ErrCannotParseFile = errors.New("cannot parse file") ErrValidateRecord = errors.New("error validating record") ErrRecordNotValid = errors.New("record not valid") + ErrRecordAlreadyExists = errors.New("record already exists") ErrReadingCSVHeader = errors.New("error reading CSV header") ErrReadingCSVRow = errors.New("error reading CSV row") ErrMissingOrInvalidDate = errors.New("missing or invalid date") diff --git a/service_a/server/database/migrations/001_data.up.sql b/service_a/server/database/migrations/001_data.up.sql index 3162843..3c04c05 100644 --- a/service_a/server/database/migrations/001_data.up.sql +++ b/service_a/server/database/migrations/001_data.up.sql @@ -11,7 +11,7 @@ create table public.ingest_batch id serial primary key, elapsed_ms int not null default 0, - file_checksum text not null, + file_checksum text not null unique, created_at timestamp not null default now() ); @@ -33,7 +33,9 @@ create table public.meteo_data rainfall numeric(5, 2) not null, cloudiness int not null, - created_at timestamp not null default now() + created_at timestamp not null default now(), + + constraint uq_meteo_data_record unique (location_name_norm, date_of_register, max_temp, min_temp, rainfall, cloudiness) ); create index idx_meteo_data_location_name_norm on public.meteo_data (location_name_norm);