Skip to content

Commit fc372b3

Browse files
committed
Correctly use tmp_geom column
1 parent 43d59f3 commit fc372b3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

threedi_schema/migrations/versions/0223_upgrade_db_inflow.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
"""
88
import json
9+
import sqlite3
910
from pathlib import Path
1011
from typing import Dict, List, Tuple
1112

@@ -202,8 +203,16 @@ def fix_src_geometry(src_table: str, tmp_geom: str, radius_expr: str):
202203
srid = get_global_srid()
203204
# create columns to store the derived geometries to
204205
op.execute(sa.text(f"SELECT AddGeometryColumn('{src_table}', '{tmp_geom}', 4326, 'POLYGON', 'XY', 0);"))
205-
# copy existing geometries to new columns
206206
op.execute(sa.text(f"UPDATE {src_table} SET {tmp_geom} = the_geom;"))
207+
# copy existing geometries to new columns
208+
# try:
209+
# op.execute(sa.text(f"UPDATE {src_table} SET {tmp_geom} = the_geom;"))
210+
# except:
211+
# op.execute(sa.text(f"UPDATE {src_table} SET {tmp_geom} = NULL;"))
212+
# except:
213+
# print('Could not copy existing geometries')
214+
# op.execute(sa.text(f"UPDATE {src_table} SET {tmp_geom} = NULL;"))
215+
207216
# create missing geometries
208217
query_str = f"""
209218
UPDATE {src_table} AS surface
@@ -215,7 +224,7 @@ def fix_src_geometry(src_table: str, tmp_geom: str, radius_expr: str):
215224
FROM {src_table}_map
216225
JOIN {src_table} ON {src_table}_map.{src_table.strip('v2_')}_id = {src_table}.id
217226
JOIN v2_connection_nodes ON v2_connection_nodes.id = {src_table}_map.connection_node_id
218-
WHERE {src_table}.sur_geom IS NULL
227+
WHERE {src_table}.{tmp_geom} IS NULL
219228
GROUP BY {src_table}.id, {src_table}.area
220229
) AS subquery
221230
WHERE surface.id = subquery.surface_id

0 commit comments

Comments
 (0)