Skip to content

Commit

Permalink
Fix incorrect fix
Browse files Browse the repository at this point in the history
  • Loading branch information
margrietpalm committed Jan 23, 2025
1 parent e9ae001 commit 0191620
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ def rename_columns(table_name: str, columns: List[Tuple[str, str]]):
if entry['name'] in ["geom", "id"]:
entry_string += f" NOT NULL"
new_columns_list_sql_formatted.append(entry_string)

temp_name = f'_temp_225_{uuid.uuid4().hex}'
create_table_query = f"""CREATE TABLE {temp_name} ({', '.join(new_columns_list_sql_formatted)});"""
op.execute(sa.text(create_table_query))
op.execute(sa.text(f"INSERT INTO {temp_name} ({','.join(new_columns_list)}) SELECT {','.join(old_columns_list)} from {table_name};"))
drop_geo_table(op, table_name)
op.execute(sa.text(f"ALTER TABLE {temp_name} RENAME TO {table_name};"))

for entry in new_columns:
if entry["name"] == "geom":
op.execute(sa.text(f"""SELECT RecoverGeometryColumn('{table_name}', '{GEOMETRY_TYPES[table_name]}', 4326, '{entry["type"]}', 'XY')"""))
if table_name is not GEOMETRY_TYPES:
op.execute(sa.text(f"""SELECT RecoverGeometryColumn('{table_name}', 'geom', 4326, '{GEOMETRY_TYPES[table_name]}', 'XY')"""))



Expand Down
1 change: 1 addition & 0 deletions threedi_schema/migrations/versions/0228_upgrade_db_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def modify_table(old_table_name, new_table_name):
old_col_names.append('the_geom')
new_col_names.append('geom')
new_col_types.append(f'{geom_type} NOT NULL')
print(new_table_name, geom_type)
# Create new table (temp), insert data, drop original and rename temp to table_name
new_col_str = ','.join(['id INTEGER PRIMARY KEY NOT NULL'] + [f'{cname} {ctype}' for cname, ctype in
zip(new_col_names, new_col_types)])
Expand Down

0 comments on commit 0191620

Please sign in to comment.