From 25310dcb360b76bd1d3cb1a7327ada63792b246f Mon Sep 17 00:00:00 2001 From: Ramya Ragupathy Date: Fri, 19 Apr 2019 17:45:43 +0530 Subject: [PATCH] #1470 Del proj w/ invalid geometries --- .../migration-tm2-tm3-postgres.sql} | 0 devops/database-scripts/proj-geom-cleanup.sql | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+) rename devops/{tm2-pg-migration/migrationscripts.sql => database-scripts/migration-tm2-tm3-postgres.sql} (100%) create mode 100644 devops/database-scripts/proj-geom-cleanup.sql diff --git a/devops/tm2-pg-migration/migrationscripts.sql b/devops/database-scripts/migration-tm2-tm3-postgres.sql similarity index 100% rename from devops/tm2-pg-migration/migrationscripts.sql rename to devops/database-scripts/migration-tm2-tm3-postgres.sql diff --git a/devops/database-scripts/proj-geom-cleanup.sql b/devops/database-scripts/proj-geom-cleanup.sql new file mode 100644 index 0000000000..067a6e8a64 --- /dev/null +++ b/devops/database-scripts/proj-geom-cleanup.sql @@ -0,0 +1,34 @@ + +SELECT + projects.id +INTO TEMPORARY TABLE + project_list +FROM + projects +WHERE ST_XMin(geometry) < -180 + or ST_XMax(geometry) > 180 + or ST_YMin(geometry) < -90 + or ST_YMax(geometry) > 90; + + +CREATE OR REPLACE FUNCTION delete_results() + RETURNS SETOF text AS +$func$ +DECLARE + elem int; +BEGIN + FOR elem IN + SELECT * FROM project_list + LOOP + DELETE FROM public.project_info WHERE project_id = elem; + DELETE FROM public.project_chat WHERE project_id = elem; + DELETE FROM public.task_history WHERE project_id = elem; + DELETE FROM public.task_invalidation_history WHERE project_id = elem; + DELETE FROM public.tasks WHERE project_id = elem; + RETURN NEXT elem; + RAISE NOTICE 'Project: %', elem; + END LOOP; +END +$func$ LANGUAGE plpgsql; + +SELECT * from delete_results()