[postgis-tickets] [SCM] PostGIS branch stable-3.1 updated. 3.1.5-4-gf3fa9aafb

git at osgeo.org git at osgeo.org
Fri Mar 18 16:42:55 PDT 2022


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, stable-3.1 has been updated
       via  f3fa9aafbff591e83db75d6af60752a9a4878cd6 (commit)
      from  f1e799c7ee4a76f0d1029f91983f9dd2e05db8fe (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 f3fa9aafbff591e83db75d6af60752a9a4878cd6
Author: Sandro Santilli <strk at kbt.io>
Date:   Fri Mar 18 21:32:36 2022 +0100

    Execute pending constraints before dropping topology
    
    References #5115 in 3.1 branch (3.1.6dev)
    Includes test and NEWS item

diff --git a/NEWS b/NEWS
index c0f0071b7..32ae9a69c 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ PostGIS 3.1.6
 * Bug Fixes
   - #5076, Avoid log storm installed with pgaudit enabled (Paul Ramsey)
   - #5100, Stop using pg_atoi, removed in PG 15 (Laurenz Albe)
+  - #5115, Allow dropping topologies with pending constraints (Sandro Santilli)
 
 PostGIS 3.1.5
 2022/02/01
diff --git a/topology/test/regress/droptopology.sql b/topology/test/regress/droptopology.sql
index 0b63a6d71..7f12a2b34 100644
--- a/topology/test/regress/droptopology.sql
+++ b/topology/test/regress/droptopology.sql
@@ -31,6 +31,14 @@ INSERT INTO t3.f(g) VALUES (toTopoGeom('POINT(0 0)', 't3', 1));
 --SELECT topology.DropTopoGeometryColumn('t3', 'f', 'g');
 SELECT topology.DropTopology('t3');
 
+-- Test DropTopology with pending deferred triggers
+-- See https://trac.osgeo.org/postgis/ticket/5115
+BEGIN;
+SELECT 't5115.create' FROM topology.CreateTopology('t5115');
+SELECT 't5115.addline' FROM topology.TopoGeo_addLineString('t5115', 'LINESTRING(0 0, 10 0)');
+SELECT 't5115.drop' FROM topology.DropTopology('t5115');
+ROLLBACK;
+
 -- Exceptions
 SELECT topology.DropTopology('topology');
 SELECT topology.DropTopology('doesnotexist');
diff --git a/topology/test/regress/droptopology_expected b/topology/test/regress/droptopology_expected
index 37905a4d3..3c5f8570a 100644
--- a/topology/test/regress/droptopology_expected
+++ b/topology/test/regress/droptopology_expected
@@ -1,5 +1,8 @@
 Topology 't1' dropped
 Topology 't2' dropped
 Topology 't3' dropped
+t5115.create
+t5115.addline
+t5115.drop
 ERROR:  Topology 'topology' does not exist
 ERROR:  Topology 'doesnotexist' does not exist
diff --git a/topology/topology.sql.in b/topology/topology.sql.in
index 11fb1f3b8..075965ed7 100644
--- a/topology/topology.sql.in
+++ b/topology/topology.sql.in
@@ -2009,6 +2009,9 @@ $$
 DECLARE
   topoid integer;
   rec RECORD;
+  sql TEXT;
+  toposchema REGNAMESPACE;
+  deferred_constraints TEXT[];
 BEGIN
   -- Get topology id
   SELECT id INTO topoid
@@ -2040,10 +2043,37 @@ BEGIN
     || topoid;
 
   -- Drop the schema (if it exists)
-  FOR rec IN SELECT * FROM pg_namespace WHERE text(nspname) = atopology
-  LOOP
-    EXECUTE 'DROP SCHEMA '||quote_ident(atopology)||' CASCADE';
-  END LOOP;
+  SELECT oid FROM pg_namespace WHERE text(nspname) = atopology
+  INTO toposchema;
+
+  IF toposchema IS NOT NULL THEN --{
+
+    -- Give immediate execution to pending constraints
+    -- in the topology schema.
+    --
+    -- See https://trac.osgeo.org/postgis/ticket/5115
+    SELECT array_agg(format('%I.%I', atopology, conname))
+    FROM pg_constraint c
+    WHERE connamespace = toposchema AND condeferred
+    INTO deferred_constraints;
+
+    IF deferred_constraints IS NOT NULL THEN --{
+      sql := format(
+        'SET constraints %s IMMEDIATE',
+        array_to_string(deferred_constraints, ',')
+      );
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+      RAISE DEBUG 'Executing: %', sql;
+#endif
+      EXECUTE sql;
+    END IF; --}
+
+    sql := format('DROP SCHEMA %I CASCADE', atopology);
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+    RAISE DEBUG 'Executing: %', sql;
+#endif
+    EXECUTE sql;
+  END IF; --}
 
   RETURN 'Topology ' || quote_literal(atopology) || ' dropped';
 END

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                        |  1 +
 topology/test/regress/droptopology.sql      |  8 ++++++
 topology/test/regress/droptopology_expected |  3 +++
 topology/topology.sql.in                    | 38 ++++++++++++++++++++++++++---
 4 files changed, 46 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list