[postgis-tickets] r16046 - Check version matching upon creating extension from unpackaged

Sandro Santilli strk at kbt.io
Sun Oct 22 11:41:36 PDT 2017


Author: strk
Date: 2017-10-22 11:41:36 -0700 (Sun, 22 Oct 2017)
New Revision: 16046

Added:
   trunk/extensions/postgis/unpackaged_check.sql.in
Modified:
   trunk/NEWS
   trunk/extensions/postgis/Makefile.in
Log:
Check version matching upon creating extension from unpackaged

Closes #3892

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2017-10-22 17:54:09 UTC (rev 16045)
+++ trunk/NEWS	2017-10-22 18:41:36 UTC (rev 16046)
@@ -19,6 +19,8 @@
   - Topology population robustness improvements (Sandro Santilli)
     #1855, #1946, #3718 #3838
   - #3234, Do not accept EMPTY points as topology nodes (Sandro Santilli)
+  - #3892, Prevent version mixup when creating extension from unpackaged
+           (Sandro Santilli)
 
 PostGIS 2.4.0
 2017/09/30

Modified: trunk/extensions/postgis/Makefile.in
===================================================================
--- trunk/extensions/postgis/Makefile.in	2017-10-22 17:54:09 UTC (rev 16045)
+++ trunk/extensions/postgis/Makefile.in	2017-10-22 18:41:36 UTC (rev 16046)
@@ -79,9 +79,19 @@
 sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql | sql
 	cp $< $@
 
-sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) ../../utils/create_unpackaged.pl | sql
+sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) ../../utils/create_unpackaged.pl unpackaged_check.sql Makefile | sql
 	cat $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) | $(PERL) ../../utils/create_unpackaged.pl postgis > $@
+	# Ensure version is correct
+	cat unpackaged_check.sql > $@
+	cat $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) \
+		| $(PERL) ../../utils/create_unpackaged.pl postgis \
+		>> $@
 
+unpackaged_check.sql: unpackaged_check.sql.in Makefile
+	cat $< \
+		| sed -e 's|@EXTVERSION@|$(EXTVERSION)|g' \
+		> $@
+
 sql:
 	mkdir -p $@
 

Added: trunk/extensions/postgis/unpackaged_check.sql.in
===================================================================
--- trunk/extensions/postgis/unpackaged_check.sql.in	                        (rev 0)
+++ trunk/extensions/postgis/unpackaged_check.sql.in	2017-10-22 18:41:36 UTC (rev 16046)
@@ -0,0 +1,13 @@
+DO $$
+DECLARE
+	ver TEXT;
+BEGIN
+	ver := split_part(postgis_scripts_installed(), ' ', 1);
+	IF ver != '@EXTVERSION@' THEN
+		RAISE EXCEPTION 'Installed PostGIS version is %', ver
+		USING HINT = 'Try `CREATE EXTENSION postgis VERSION ''@EXTVERSION@'' from unpackaged`,'
+		            'or source postgis_upgrade.sql`';
+	END IF;
+END;
+$$ LANGUAGE 'plpgsql';
+



More information about the postgis-tickets mailing list