Add dev-prod harmonize tool for bidirectional catalog and image sync.

Schema migrates dev to prod only; catalog rows merge by updated_at and images by mtime with union merge and conflict reporting.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Danila Khodjaef
2026-07-15 11:02:17 +03:00
co-authored by Cursor
parent 81ebad2120
commit f247b418d8
21 changed files with 1336 additions and 4 deletions
+39
View File
@@ -0,0 +1,39 @@
-- Catalog row timestamps for dev/prod harmonize (last-write-wins merge).
-- Idempotent: safe to re-run on existing databases.
CREATE OR REPLACE FUNCTION sync_touch_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DO $$
DECLARE
tbl TEXT;
BEGIN
FOREACH tbl IN ARRAY ARRAY[
'historical_eras',
'art_movements',
'artists',
'artist_periods',
'paintings',
'painting_influences',
'painting_influence_sources',
'painting_annotations'
]
LOOP
EXECUTE format(
'ALTER TABLE %I ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT now()',
tbl
);
EXECUTE format('DROP TRIGGER IF EXISTS %I ON %I', tbl || '_updated_at', tbl);
EXECUTE format(
'CREATE TRIGGER %I BEFORE UPDATE ON %I FOR EACH ROW EXECUTE PROCEDURE sync_touch_updated_at()',
tbl || '_updated_at',
tbl
);
END LOOP;
END $$;