postgis.git / summary / log / commit / refs

commit    bb3842bfeef613f32e5dd032cad85599159ffb76
Author:   Sandro Santilli <strk@kbt.io>
Date:     Mon Mar 28 12:30:39 2022 +0000

    Allow dropping topologies with missing layer topogeom sequences
    
    Closes #5118 in master branch
    Includes regression test


NEWS | 2 ++ topology/test/regress/droptopogeometrycolumn.sql | 28 ++++++++++++++++------ .../test/regress/droptopogeometrycolumn_expected | 6 ++--- topology/topology.sql.in | 19 +++++++-------- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/NEWS b/NEWS index deaefa28a..173815cd2 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PostGIS 3.3.0dev - Drop support for PostgreSQL 9.6 and 10 (Regina Obe) * Enhancements * + - #5118, Allow dropping topologies with missing topogeometry sequences + (Sandro Santilli) - #5111, faster topology face MBR computation (Sandro Santilli) - postgis_extensions_upgrade() support for upgrades from any PostGIS version, including yet to be released ones (Sandro Santilli) diff --git a/topology/test/regress/droptopogeometrycolumn.sql b/topology/test/regress/droptopogeometrycolumn.sql index 77046b4f9..19ad43699 100644 --- a/topology/test/regress/droptopogeometrycolumn.sql +++ b/topology/test/regress/droptopogeometrycolumn.sql @@ -1,10 +1,24 @@ set client_min_messages to ERROR; + -- Drop corrupted topology (with missing layer tables) -- See http://trac.osgeo.org/postgis/ticket/3016 -SELECT topology.CreateTopology('t1') > 0; -CREATE TABLE t1f (id int); -SELECT topology.AddTopoGeometryColumn('t1', 'public', 't1f', 'geom_t1', 'LINE') > 0; -DROP TABLE t1.relation; -SELECT topology.DropTopoGeometryColumn('public','t1f','geom_t1'); -DROP TABLE t1f; -SELECT topology.DropTopology('t1'); +SELECT NULL FROM topology.CreateTopology('t3016'); +CREATE TABLE t3016f (id int); +SELECT NULL FROM topology.AddTopoGeometryColumn('t3016', 'public', 't3016f', 'g', 'LINE'); +DROP TABLE t3016.relation; +SELECT 't3016.drop', topology.DropTopoGeometryColumn('public','t3016f','g'); +SELECT 't3016', 'UNEXPECTED LAYER', * FROM topology.layer WHERE table_name = 't5118f'; +DROP TABLE t3016f; +SELECT NULL FROM topology.DropTopology('t3016'); + +-- Drop corrupted topology (with missing layer sequence) +-- See http://trac.osgeo.org/postgis/ticket/5118 +SELECT NULL FROM topology.CreateTopology('t5118'); +CREATE TABLE t5118f (id int); +SELECT NULL FROM topology.AddTopoGeometryColumn('t5118', 'public', 't5118f', 'g', 'LINE'); +INSERT INTO t5118f(g) SELECT toTopoGeom('LINESTRING(0 0, 10 0)', 't5118', 1); +DROP SEQUENCE t5118.topogeo_s_1; +SELECT 't5118.drop', topology.DropTopoGeometryColumn('public','t5118f','g'); +SELECT 't5118', 'UNEXPECTED LAYER', * FROM topology.layer WHERE table_name = 't5118f'; +DROP TABLE t5118f; +SELECT NULL FROM topology.DropTopology('t5118'); diff --git a/topology/test/regress/droptopogeometrycolumn_expected b/topology/test/regress/droptopogeometrycolumn_expected index 65dc643d9..cc45dde87 100644 --- a/topology/test/regress/droptopogeometrycolumn_expected +++ b/topology/test/regress/droptopogeometrycolumn_expected @@ -1,4 +1,2 @@ -t -t -Layer 1 (public.t1f.geom_t1) dropped -Topology 't1' dropped +t3016.drop|Layer 1 (public.t3016f.g) dropped +t5118.drop|Layer 1 (public.t5118f.g) dropped diff --git a/topology/topology.sql.in b/topology/topology.sql.in index a522cbcf2..c7f4e3063 100644 --- a/topology/topology.sql.in +++ b/topology/topology.sql.in @@ -749,22 +749,13 @@ BEGIN schema,tbl,col; END IF; - -- Clean up the topology schema + -- Cleanup the relation table (if it exists) BEGIN - -- Cleanup the relation table sql := format( 'DELETE FROM %I.relation WHERE layer_id = $1', lyrinfo.toponame ); EXECUTE sql USING lyrinfo.layer_id; - - -- Drop the sequence for topogeoms in this layer - sql := format( - 'DROP SEQUENCE %I.topogeo_s_%s', - lyrinfo.toponame, - lyrinfo.layer_id - ); - EXECUTE sql; EXCEPTION WHEN UNDEFINED_TABLE THEN RAISE NOTICE '%', SQLERRM; @@ -772,6 +763,14 @@ BEGIN RAISE EXCEPTION 'Got % (%)', SQLERRM, SQLSTATE; END; + -- Drop the sequence for topogeoms in this layer + sql := format( + 'DROP SEQUENCE IF EXISTS %I.topogeo_s_%s', + lyrinfo.toponame, + lyrinfo.layer_id + ); + EXECUTE sql; + ok = false; FOR rec IN SELECT * FROM pg_namespace n, pg_class c, pg_attribute a WHERE text(n.nspname) = schema [parent: 1ba6bccae13b]