From 5e8ccc6be174fcb4ebbd44af33189624b5d2f19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20P=C3=A9rez?= Date: Thu, 23 Oct 2025 17:07:53 +0200 Subject: [PATCH] remove location table --- service_a/internal/domains/meteo/repository.go | 7 ++----- service_a/server/database/migrations/001_data.up.sql | 11 +++-------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/service_a/internal/domains/meteo/repository.go b/service_a/internal/domains/meteo/repository.go index 74c2556..28be5b3 100644 --- a/service_a/internal/domains/meteo/repository.go +++ b/service_a/internal/domains/meteo/repository.go @@ -23,11 +23,9 @@ func NewPGXRepo(pool *pgxpool.Pool) Repository { } } -const insertAcceptedMeteoData = `insert into public.meteo_data (location_id, max_temp, min_temp, rainfall, cloudiness, created_at) values ($1, $2, $3, $4, $5, $6) returning id` +const insertAcceptedMeteoData = `insert into public.meteo_data (location_name, max_temp, min_temp, rainfall, cloudiness, created_at) values ($1, $2, $3, $4, $5, $6) returning id` func (pgx *pgxRepo) InsertAcceptedMeteoData(ctx context.Context, data []MeteoData) (int, error) { - // TODO pass context - // TODO improve transaction tx, err := pgx.Begin(ctx) if err != nil { return 0, fmt.Errorf("error starting transaction: %w", err) @@ -37,8 +35,7 @@ func (pgx *pgxRepo) InsertAcceptedMeteoData(ctx context.Context, data []MeteoDat batch := &b.Batch{} for _, d := range data { - // TODO get city id before insert! - batch.Queue(insertAcceptedMeteoData, 1, d.MaxTemp, d.MinTemp, d.Rainfall, d.Cloudiness, d.Timestamp) + batch.Queue(insertAcceptedMeteoData, d.Location, d.MaxTemp, d.MinTemp, d.Rainfall, d.Cloudiness, d.Timestamp) } results := tx.SendBatch(ctx, batch) diff --git a/service_a/server/database/migrations/001_data.up.sql b/service_a/server/database/migrations/001_data.up.sql index f8ba382..7395d13 100644 --- a/service_a/server/database/migrations/001_data.up.sql +++ b/service_a/server/database/migrations/001_data.up.sql @@ -1,15 +1,8 @@ -create table public.locations -( - id serial primary key, - location_name varchar(255) not null unique -); - - create table public.meteo_data ( id serial primary key, - location_id int not null references public.locations (id), + location_name citext not null, max_temp float not null, min_temp float not null, rainfall float not null, @@ -18,6 +11,8 @@ create table public.meteo_data 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,