]> granicus.if.org Git - postgis/commitdiff
Check version before allowing to perform upgrade from unpackaged
authorSandro Santilli <strk@kbt.io>
Tue, 11 Sep 2018 09:19:58 +0000 (09:19 +0000)
committerSandro Santilli <strk@kbt.io>
Tue, 11 Sep 2018 09:19:58 +0000 (09:19 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@16747 b70326c6-7e19-0410-871a-916f4a2858ee

extensions/postgis_raster/Makefile.in
extensions/postgis_raster/unpackaged_check.sql.in [new file with mode: 0644]

index d9634a3daf64ed665727052aa9bdf72527ad7cff..8d3274429f312259154a97d6f6afabd954aaf494 100644 (file)
@@ -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 (file)
index 0000000..63433e1
--- /dev/null
@@ -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';
+