[postgis-tickets] r16747 - Check version before allowing to perform upgrade from unpackaged

Sandro Santilli strk at kbt.io
Tue Sep 11 02:19:58 PDT 2018


Author: strk
Date: 2018-09-11 02:19:58 -0700 (Tue, 11 Sep 2018)
New Revision: 16747

Added:
   trunk/extensions/postgis_raster/unpackaged_check.sql.in
Modified:
   trunk/extensions/postgis_raster/Makefile.in
Log:
Check version before allowing to perform upgrade from unpackaged

Modified: trunk/extensions/postgis_raster/Makefile.in
===================================================================
--- trunk/extensions/postgis_raster/Makefile.in	2018-09-11 09:19:52 UTC (rev 16746)
+++ trunk/extensions/postgis_raster/Makefile.in	2018-09-11 09:19:58 UTC (rev 16747)
@@ -58,8 +58,10 @@
 
 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 @@
 		| 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 $^ >> $@
 

Added: trunk/extensions/postgis_raster/unpackaged_check.sql.in
===================================================================
--- trunk/extensions/postgis_raster/unpackaged_check.sql.in	                        (rev 0)
+++ trunk/extensions/postgis_raster/unpackaged_check.sql.in	2018-09-11 09:19:58 UTC (rev 16747)
@@ -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';
+



More information about the postgis-tickets mailing list