metalfrom.eu/apps/api/migrations/003_geocode_tables.sql
Nicolas Fryder d2fcafc6be feat(db): système de migrations SQL + refonte schéma
- apps/api/migrations/ : 4 migrations numérotées idempotentes
  001 : schéma initial (bands, trigger geom, indexes)
  002 : colonnes manquantes (enriched, themes, geocode_*) + fix trigger
        → updated_at mis à jour sur toute UPDATE (pas seulement lat/lon)
  003 : geocode_queue et geocode_cache (formalisées)
  004 : tracking crawl (crawled_at, crawled_hash, ma_created_at,
        ma_modified_at, first_seen_at) + crawl_run + crawl_checkpoint
- apps/api/src/migrate.js : runner qui s applique au démarrage de l api
- apps/api/Dockerfile : CMD lance migrate.js avant server.js
- infra/init.sql : remplacé par notice de redirection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-27 15:09:35 +02:00

26 lines
932 B
SQL

CREATE TABLE IF NOT EXISTS geocode_queue (
ma_id BIGINT PRIMARY KEY REFERENCES bands(ma_id) ON DELETE CASCADE,
query TEXT NOT NULL,
country TEXT,
status TEXT NOT NULL DEFAULT 'queued', -- queued | processing | done | error
tries INT NOT NULL DEFAULT 0,
next_run_at TIMESTAMPTZ NOT NULL DEFAULT now(),
last_error TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_geocode_queue_status_next
ON geocode_queue (status, next_run_at)
WHERE status IN ('queued', 'error');
CREATE TABLE IF NOT EXISTS geocode_cache (
query TEXT PRIMARY KEY,
provider TEXT,
lat DOUBLE PRECISION,
lon DOUBLE PRECISION,
geom GEOGRAPHY(Point, 4326),
raw JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);