push weather
This commit is contained in:
18
database/migrations/add_unique_constraint_weather_data.sql
Normal file
18
database/migrations/add_unique_constraint_weather_data.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- Ensure weather_data upsert works by providing a unique index
|
||||
-- Safe to run multiple times
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM pg_indexes
|
||||
WHERE schemaname = 'public' AND indexname = 'idx_weather_data_property_date'
|
||||
) THEN
|
||||
DROP INDEX IF EXISTS idx_weather_data_property_date;
|
||||
END IF;
|
||||
EXCEPTION WHEN undefined_table THEN
|
||||
-- table may not exist yet in some environments; ignore
|
||||
NULL;
|
||||
END $$;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_weather_data_property_date
|
||||
ON weather_data(property_id, date);
|
||||
|
||||
Reference in New Issue
Block a user