[postgis-tickets] r17294 - Simplify opt_out.sh code, allow writing to stdout

Sandro Santilli strk at kbt.io
Wed Mar 6 07:03:02 PST 2019


Author: strk
Date: 2019-03-06 07:03:02 -0800 (Wed, 06 Mar 2019)
New Revision: 17294

Modified:
   trunk/extensions/opt_out.sh
Log:
Simplify opt_out.sh code, allow writing to stdout

Modified: trunk/extensions/opt_out.sh
===================================================================
--- trunk/extensions/opt_out.sh	2019-03-06 14:57:42 UTC (rev 17293)
+++ trunk/extensions/opt_out.sh	2019-03-06 15:03:02 UTC (rev 17294)
@@ -1,72 +1,39 @@
 #!/bin/sh
 
 test -n "$1" || {
-  echo "Usage: $0 <dbname>"
+  echo "Usage: $0 { <dbname> | - }"
   exit 1
 }
 
 db="$1"
 
-psql -XtA ${db} <<'EOF' | psql -XtA ${db}
+EXTENSIONS="postgis_sfcgal postgis_raster postgis_topology postgis"
 
------------------
--- for sfcgal
------------------
+(
+  for ext in $EXTENSIONS; do
+    cat <<EOF
 
-SELECT 'ALTER EXTENSION ' || extname || ' DROP ' || regexp_replace(
-    regexp_replace(pg_catalog.pg_describe_object(d.classid, d.objid, 0), E'cast from (.*) to (.*)', E'cast\(\\1 as \\2\)'),
-    E'(.*) for access method (.*)', E'\\1 using \\2') || ';' AS sqladd
+SELECT 'ALTER EXTENSION ' || extname || ' DROP ' ||
+  regexp_replace(
+    regexp_replace(
+      pg_catalog.pg_describe_object(d.classid, d.objid, 0),
+      E'cast from (.*) to (.*)',
+      E'cast\(\\1 as \\2\)'),
+      E'(.*) for access method (.*)',
+      E'\\1 using \\2'
+  ) || ';' AS sqladd
 FROM pg_catalog.pg_depend AS d
 INNER JOIN pg_extension AS e ON (d.refobjid = e.oid)
 WHERE d.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass
-AND deptype = 'e' AND e.extname = 'postgis_sfcgal'
-ORDER BY sqladd;
+AND deptype = 'e' AND e.extname = '${ext}' ORDER BY sqladd;
 
-SELECT 'DROP EXTENSION postgis_sfcgal;';
+SELECT 'DROP EXTENSION ${ext};';
 
------------------
--- for raster
------------------
-
-SELECT 'ALTER EXTENSION ' || extname || ' DROP ' || regexp_replace(
-    regexp_replace(pg_catalog.pg_describe_object(d.classid, d.objid, 0), E'cast from (.*) to (.*)', E'cast\(\\1 as \\2\)'),
-    E'(.*) for access method (.*)', E'\\1 using \\2') || ';' AS sqladd
-FROM pg_catalog.pg_depend AS d
-INNER JOIN pg_extension AS e ON (d.refobjid = e.oid)
-WHERE d.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass
-AND deptype = 'e' AND e.extname = 'postgis_raster'
-ORDER BY sqladd;
-
-SELECT 'DROP EXTENSION postgis_raster;';
-
------------------
--- for topology
------------------
-
-SELECT 'ALTER EXTENSION ' || extname || ' DROP ' || regexp_replace(
-    regexp_replace(pg_catalog.pg_describe_object(d.classid, d.objid, 0), E'cast from (.*) to (.*)', E'cast\(\\1 as \\2\)'),
-    E'(.*) for access method (.*)', E'\\1 using \\2') || ';' AS sqladd
-FROM pg_catalog.pg_depend AS d
-INNER JOIN pg_extension AS e ON (d.refobjid = e.oid)
-WHERE d.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass
-AND deptype = 'e' AND e.extname = 'postgis_topology'
-ORDER BY sqladd;
-
-SELECT 'DROP EXTENSION postgis_topology;';
-
---------------------
--- for postgis core
---------------------
-
-SELECT 'ALTER EXTENSION ' || extname || ' DROP ' || regexp_replace(
-    regexp_replace(pg_catalog.pg_describe_object(d.classid, d.objid, 0), E'cast from (.*) to (.*)', E'cast\(\\1 as \\2\)'),
-    E'(.*) for access method (.*)', E'\\1 using \\2') || ';' AS sqladd
-FROM pg_catalog.pg_depend AS d
-INNER JOIN pg_extension AS e ON (d.refobjid = e.oid)
-WHERE d.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass
-AND deptype = 'e' AND e.extname = 'postgis'
-ORDER BY sqladd;
-
-SELECT 'DROP EXTENSION postgis;';
-
 EOF
+  done
+) |
+if test ${db} = '-'; then
+  cat
+else
+  psql -XtA ${db}
+fi



More information about the postgis-tickets mailing list