diff --git a/backend/migrations/000012_discovered_markets.down.sql b/backend/migrations/000012_discovered_markets.down.sql new file mode 100644 index 0000000..af5140d --- /dev/null +++ b/backend/migrations/000012_discovered_markets.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS discovered_markets; diff --git a/backend/migrations/000012_discovered_markets.up.sql b/backend/migrations/000012_discovered_markets.up.sql new file mode 100644 index 0000000..0f72c55 --- /dev/null +++ b/backend/migrations/000012_discovered_markets.up.sql @@ -0,0 +1,30 @@ +CREATE TABLE discovered_markets ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + bucket_id uuid NOT NULL REFERENCES discovery_buckets(id) ON DELETE CASCADE, + markt_name text NOT NULL, + stadt text NOT NULL, + bundesland text, + land text NOT NULL, + start_datum date, + end_datum date, + website text, + quellen text[] NOT NULL DEFAULT '{}', + extraktion text, + hinweis text, + name_normalized text NOT NULL, + matched_series_id uuid REFERENCES market_series(id) ON DELETE SET NULL, + status text NOT NULL DEFAULT 'pending' + CHECK (status IN ('pending', 'accepted', 'rejected')), + discovered_at timestamptz NOT NULL DEFAULT now(), + reviewed_at timestamptz, + reviewed_by uuid REFERENCES users(id) ON DELETE SET NULL, + created_edition_id uuid REFERENCES market_editions(id) ON DELETE SET NULL +); + +CREATE INDEX idx_discovered_markets_pending + ON discovered_markets (status, discovered_at) + WHERE status = 'pending'; + +CREATE INDEX idx_discovered_markets_dedup + ON discovered_markets (name_normalized, stadt, start_datum) + WHERE status = 'pending';