[SCM] PostGIS branch master updated. 3.4.0rc1-1124-g762e6c82b
git at osgeo.org
git at osgeo.org
Fri May 24 09:14:06 PDT 2024
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".
The branch, master has been updated
via 762e6c82b36588c7ffd1367ab67bfc5dce1e6f7d (commit)
from ca40cf9a70e6225f5e07a167f10ce3341b90ff7d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 762e6c82b36588c7ffd1367ab67bfc5dce1e6f7d
Author: Sandro Santilli <strk at kbt.io>
Date: Fri May 24 18:12:35 2024 +0200
Simplify upgrade of postgis databases
Adds new commands: list-all and list-enabled.
Allow passing no argument to commands "status" and "upgrade" to
perform the operation on all databases.
diff --git a/NEWS b/NEWS
index afe3a39f5..55cab590e 100644
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,12 @@ Andreas Schild (German Team)
* New Features *
+ - Improvements in the 'postgis' script:
+ - new command list-enabled
+ - new command list-all
+ - command upgrade upgrades all databases that need to be
+ - command status reports status of all databases
+ (Sandro Santilli)
- #5721, Allow sharing sequences between different topologies (Lars Opsahl)
- #5667, TopoGeo_LoadGeometry (Sandro Santilli)
- #5055, add explicit <> geometry operator to prevent non-unique
diff --git a/loader/postgis.pl b/loader/postgis.pl
index 553e22162..c8973d7e7 100644
--- a/loader/postgis.pl
+++ b/loader/postgis.pl
@@ -18,9 +18,11 @@ sub usage
print qq{Usage: $0 <command> [<args>]
Commands:
help print this message and exits
- enable <database> enable PostGIS in given database
- upgrade <database> upgrade PostGIS in given database
- status <database> print PostGIS status in given database
+ list-all list all databases
+ list-enabled list PostGIS-enabled databases
+ enable <db>... enable PostGIS in given databases
+ upgrade [<db>...] upgrade PostGIS in given databases (or all)
+ status [<db>...] print PostGIS status in given databases (or all)
install-extension-upgrades [--pg_sharedir <dir>] [--extension <name>] [<from>...]
Ensure files required to upgrade PostGIS from
the given version are installed on the system.
@@ -174,6 +176,35 @@ sub install_extension_upgrades
}
+sub get_all_databases
+{
+ my $ALL = `psql -qXtAc 'select datname from pg_database where datallowconn' template1`;
+ return split("\n", $ALL);
+}
+
+sub list_all_databases
+{
+ my @ALL = get_all_databases();
+ foreach (@ALL)
+ {
+ print $_ . "\n";
+ }
+}
+
+sub list_enabled_databases
+{
+ my @ALL = get_all_databases();
+ my $sql = "
+ SELECT proname
+ FROM pg_proc
+ WHERE proname = 'postgis_full_version'
+ ";
+ foreach my $db (@ALL)
+ {
+ my $enabled = `psql -qXtAc "${sql}" ${db}`;
+ print $db . "\n" if $enabled ne '';
+ }
+}
sub enable
{
@@ -185,11 +216,14 @@ sub enable
sub upgrade
{
- die "Please specify at least a database name" unless @_;
+ my @DB = @_;
- foreach my $db (@_)
+ #die "Please specify at least a database name" unless @DB;
+ @DB = get_all_databases() unless @DB;
+
+ foreach my $db (@DB)
{
- print "upgrading db $db if needed\n";
+ print "upgrading PostGIS in db $db if needed\n";
open(my $SESSION, "| psql -qXtA ${db} |") || die "Could not connect to database ${db}";
print $SESSION <<'EOF';
DO $BODY$
@@ -217,9 +251,11 @@ EOF
sub status
{
- die "Please specify at least a database name" unless @_;
+ my @DB = @_;
- foreach my $db (@_)
+ @DB = get_all_databases() unless @DB;
+
+ foreach my $db (@DB)
{
my $sql = "
SELECT n.nspname
@@ -284,6 +320,12 @@ if ( $cmd eq "help" ) {
elsif ( $cmd eq "enable" ) {
exit enable(@ARGV);
}
+elsif ( $cmd eq "list-all" ) {
+ exit list_all_databases(@ARGV);
+}
+elsif ( $cmd eq "list-enabled" ) {
+ exit list_enabled_databases(@ARGV);
+}
elsif ( $cmd eq "upgrade" ) {
exit upgrade(@ARGV);
}
-----------------------------------------------------------------------
Summary of changes:
NEWS | 6 ++++++
loader/postgis.pl | 58 +++++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 56 insertions(+), 8 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list