From f659c1ee11637c891bf680c1f3e424498e1dddd2 Mon Sep 17 00:00:00 2001 From: Dennis Smith Date: Fri, 15 Nov 2024 19:00:54 -0500 Subject: [PATCH] fix: migrations failing due to dependent views --- api/migrations/schema/V1.14.00__uploader.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/migrations/schema/V1.14.00__uploader.sql b/api/migrations/schema/V1.14.00__uploader.sql index 25aeafee..8b1bd2fc 100644 --- a/api/migrations/schema/V1.14.00__uploader.sql +++ b/api/migrations/schema/V1.14.00__uploader.sql @@ -1,3 +1,20 @@ +DO $$ +DECLARE drop_views_query text; +BEGIN + SELECT 'DROP VIEW ' || string_agg (table_name, ', ') || ' CASCADE;' + FROM information_schema.views + INTO drop_views_query + WHERE table_schema = 'midas' + AND table_name LIKE 'v_%'; + + IF (drop_views_query IS NULL) THEN + RAISE NOTICE 'not dropping views on schema midas -- no views found to drop'; + ELSE + EXECUTE drop_views_query; + END IF; +END +$$; + -- checked db and there are no null instrument geometries ALTER TABLE instrument ALTER COLUMN "geometry" TYPE geometry(Point, 4326); ALTER TABLE instrument ALTER COLUMN "geometry" SET NOT NULL;