From: Sandro Santilli Date: Tue, 11 Sep 2018 09:19:58 +0000 (+0000) Subject: Check version before allowing to perform upgrade from unpackaged X-Git-Tag: 3.0.0alpha1~440 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d548adf38ca212ee9a78c6dd30d0b01e1ab41bf5;p=postgis Check version before allowing to perform upgrade from unpackaged git-svn-id: http://svn.osgeo.org/postgis/trunk@16747 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/extensions/postgis_raster/Makefile.in b/extensions/postgis_raster/Makefile.in index d9634a3da..8d3274429 100644 --- a/extensions/postgis_raster/Makefile.in +++ b/extensions/postgis_raster/Makefile.in @@ -58,8 +58,10 @@ CURV_big=@POSTGIS_MAJOR_VERSION@@POSTGIS_MINOR_VERSION@ all: sql/$(EXTENSION)--$(EXTVERSION).sql sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql -sql/$(EXTENSION).sql: $(EXTENSION_SCRIPTS) - mkdir -p sql +sql: + mkdir -p $@ + +sql/$(EXTENSION).sql: $(EXTENSION_SCRIPTS) | sql printf '\\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \\quit\n' > $@ cat $^ >> $@ @@ -70,29 +72,32 @@ $(EXTENSION).control: $(EXTENSION).control.in Makefile | sed -e 's|@MODULEPATH@|$(MODULEPATH)|g' \ > $@ -sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql - mkdir -p sql +sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql | sql cp $< $@ -sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) ../../utils/create_unpackaged.pl - mkdir -p sql - cat $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) | $(PERL) ../../utils/create_unpackaged.pl postgis_raster > $@ +sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) ../../utils/create_unpackaged.pl unpackaged_check.sql Makefile | sql + cat unpackaged_check.sql > $@ + cat $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) | $(PERL) ../../utils/create_unpackaged.pl postgis_raster >> $@ + +unpackaged_check.sql: unpackaged_check.sql.in Makefile + cat $< \ + | sed -e 's|@EXTVERSION@|$(EXTVERSION)|g' \ + > $@ #strip BEGIN/COMMIT since these are not allowed in extensions -sql/rtpostgis.sql: ../../raster/rt_pg/rtpostgis_for_extension.sql - mkdir -p sql +sql/rtpostgis.sql: ../../raster/rt_pg/rtpostgis_for_extension.sql | sql $(PERL) -pe 's/BEGIN\;//g ; s/COMMIT\;//g' $< > $@ -sql/rtpostgis_upgrade.sql: ../../raster/rt_pg/rtpostgis_upgrade_for_extension.sql +sql/rtpostgis_upgrade.sql: ../../raster/rt_pg/rtpostgis_upgrade_for_extension.sql | sql $(PERL) -pe "s/BEGIN\;//g ; s/COMMIT\;//g; s/^(DROP .*)\;/SELECT postgis_extension_drop_if_exists('$(EXTENSION)', '\1');\n\1\;/" $< > $@ ../../doc/raster_comments.sql: $(MAKE) -C ../../doc comments -sql/raster_comments.sql: ../../doc/raster_comments.sql +sql/raster_comments.sql: ../../doc/raster_comments.sql | sql cp $< $@ -sql/postgis_extension_upgrade_minor.sql: $(EXTENSION_UPGRADE_SCRIPTS) +sql/postgis_extension_upgrade_minor.sql: $(EXTENSION_UPGRADE_SCRIPTS) | sql printf '\\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \\quit\n' > $@ cat $^ >> $@ diff --git a/extensions/postgis_raster/unpackaged_check.sql.in b/extensions/postgis_raster/unpackaged_check.sql.in new file mode 100644 index 000000000..63433e1e5 --- /dev/null +++ b/extensions/postgis_raster/unpackaged_check.sql.in @@ -0,0 +1,14 @@ +DO $$ +DECLARE + ver TEXT; +BEGIN + ver := split_part(postgis_raster_scripts_installed(), ' ', 1); + IF ver != '@EXTVERSION@' THEN + RAISE EXCEPTION 'Installed PostGIS Raster version is %', ver + USING HINT = 'Try `CREATE EXTENSION postgis_raster VERSION ''' + || ver || ''' from unpackaged`,' + ' or source rtpostgis_upgrade.sql`'; + END IF; +END; +$$ LANGUAGE 'plpgsql'; +