From e7e778690c6920e3ba7b74ced6f314f6a9a5479d Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 11 Sep 2018 09:18:48 +0000 Subject: [PATCH] Drop raster objects from postgis extension on upgrade git-svn-id: http://svn.osgeo.org/postgis/trunk@16734 b70326c6-7e19-0410-871a-916f4a2858ee --- extensions/postgis/Makefile.in | 17 +++++++++++- utils/create_extension_unpackage.pl | 43 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 utils/create_extension_unpackage.pl diff --git a/extensions/postgis/Makefile.in b/extensions/postgis/Makefile.in index b18b73353..7b2865c5e 100644 --- a/extensions/postgis/Makefile.in +++ b/extensions/postgis/Makefile.in @@ -32,7 +32,7 @@ DATA_built = \ # Scripts making up the extension file # NOTE: order matters EXTENSION_SCRIPTS = \ - sql/postgis.sql \ + ../../postgis/postgis_for_extension.sql \ ../../doc/postgis_comments.sql \ sql/spatial_ref_sys_config_dump.sql \ sql/spatial_ref_sys.sql @@ -43,6 +43,7 @@ EXTENSION_UPGRADE_SCRIPTS = \ ../postgis_extension_helper.sql \ sql/postgis_upgrade.sql \ ../../doc/postgis_comments.sql \ + sql/raster_unpackage.sql \ ../postgis_extension_helper_uninstall.sql # Scripts making up the extension upgrade-from-unpackaged file @@ -50,6 +51,11 @@ EXTENSION_UPGRADE_SCRIPTS = \ EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS = \ sql/postgis.sql +RASTER_DROP_SCRIPTS = \ + ../../raster/rt_pg/rtpostgis_upgrade_cleanup.sql \ + ../../raster/rt_pg/rtpostgis_drop.sql \ + ../../raster/rt_pg/uninstall_rtpostgis.sql + #DOCS = $(wildcard ../../doc/html/*.html) PG_CONFIG = @PG_CONFIG@ @@ -71,6 +77,15 @@ $(EXTENSION).control: $(EXTENSION).control.in Makefile | sed -e 's|@MODULEPATH@|$(MODULEPATH)|g' \ > $@ +$(RASTER_DROP_SCRIPTS): + $(MAKE) -C ../../raster + +sql/raster_unpackage.sql: $(RASTER_DROP_SCRIPTS) ../../utils/create_extension_unpackage.pl Makefile | sql + cat $(RASTER_DROP_SCRIPTS) \ + | ../../utils/create_extension_unpackage.pl postgis > $@ + +sql/raster_unpackage.sql: Makefile + sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql | sql cp $< $@ diff --git a/utils/create_extension_unpackage.pl b/utils/create_extension_unpackage.pl new file mode 100755 index 000000000..6d27ff041 --- /dev/null +++ b/utils/create_extension_unpackage.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +# +# PostGIS - Spatial Types for PostgreSQL +# http://postgis.net +# +# Copyright (C) 2017 Sandro Santilli +# +# This is free software; you can redistribute and/or modify it under +# the terms of the GNU General Public Licence. See the COPYING file. +# + +use warnings; +use strict; +use POSIX 'strftime'; + +eval "exec perl -w $0 $@" + if (0); + + +die "Usage: perl $0 []\n" + . " Prints SQL to drop objects dropped by given SQL file\n" + . " from extension with given name.\n" +unless @ARGV; + +my $extname = shift(@ARGV); + +while(<>) +{ + /^DROP/i or next; + s/ IF EXISTS//i; + s/ CASCADE//i; + chop; + print 'DO $$ BEGIN ALTER EXTENSION ' . $extname + . ' ' . $_ . 'EXCEPTION ' + . 'WHEN object_not_in_prerequisite_state OR undefined_function OR undefined_object THEN ' + . " RAISE NOTICE '%', SQLERRM; " + . 'WHEN OTHERS THEN ' + . " RAISE EXCEPTION 'Got % - %', SQLSTATE, SQLERRM; " + . 'END $$ LANGUAGE ' . "'plpgsql';\n"; +} + +1; -- 2.40.0