Skip to content

Commit

Permalink
🐛 [BUG] Handle PGRouting fields to reset (refs #4070)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Jan 14, 2025
1 parent e2359b7 commit ca5f1b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions geotrek/core/path_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@

class PathRouter:
def __init__(self):
self.set_pgrouting_fields_to_null()
self.set_path_network_topology()

def set_pgrouting_fields_to_null(self):
with connection.cursor() as cursor:
cursor.execute("""
UPDATE core_path
SET source = NULL, target = NULL
WHERE id IN (SELECT path_id FROM pgrouting_paths_to_set_to_null)
""")
cursor.execute("""
TRUNCATE pgrouting_paths_to_set_to_null
""")

def set_path_network_topology(self):
""" Builds or updates the paths graph (pgRouting network topology) """
cursor = connection.cursor()
Expand Down
2 changes: 1 addition & 1 deletion geotrek/core/templates/core/sql/post_40_paths.sql
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ FOR EACH ROW EXECUTE PROCEDURE path_latest_updated_d();
CREATE FUNCTION {{ schema_geotrek }}.set_pgrouting_values_to_null() RETURNS trigger SECURITY DEFINER AS $$
DECLARE
BEGIN
UPDATE core_path SET source = NULL, target = NULL WHERE id = NEW.id;
INSERT INTO pgrouting_paths_to_set_to_null (path_id) VALUES (NEW.id) ON CONFLICT (path_id) DO NOTHING;
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
Expand Down
5 changes: 5 additions & 0 deletions geotrek/core/templates/core/sql/pre_10_cleanup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ DROP FUNCTION IF EXISTS ft_merge_path(integer,integer) CASCADE;
-- 80

DROP FUNCTION IF EXISTS path_deletion() CASCADE;

CREATE TABLE IF NOT EXISTS pgrouting_paths_to_set_to_null(
id SERIAL PRIMARY KEY,
path_id INTEGER UNIQUE
);

0 comments on commit ca5f1b4

Please sign in to comment.