-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove left over references in geometry columns #139
Merged
margrietpalm
merged 25 commits into
margriet_schema_300_leftovers
from
margriet_107_left_over_references_in_geometry_columns
Nov 26, 2024
Merged
Remove left over references in geometry columns #139
margrietpalm
merged 25 commits into
margriet_schema_300_leftovers
from
margriet_107_left_over_references_in_geometry_columns
Nov 26, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…emoving of conflicitng tables to actually conflicting tables
margrietpalm
changed the title
WIP: remove left over references in geometry columns
Remove left over references in geometry columns
Nov 22, 2024
margrietpalm
commented
Nov 22, 2024
Comment on lines
+1
to
+32
from typing import List | ||
|
||
import sqlalchemy as sa | ||
|
||
|
||
def drop_geo_table(op, table_name: str): | ||
""" | ||
|
||
Safely drop table, taking into account geometry columns | ||
|
||
Parameters: | ||
op : object | ||
An object representing the database operation. | ||
table_name : str | ||
The name of the table to be dropped. | ||
""" | ||
op.execute(sa.text(f"SELECT DropTable(NULL, '{table_name}');")) | ||
|
||
|
||
def drop_conflicting(op, new_tables: List[str]): | ||
""" | ||
Drop tables from database that conflict with new tables | ||
|
||
Parameters: | ||
op: The SQLAlchemy operation context to interact with the database. | ||
new_tables: A list of new table names to be checked for conflicts with existing tables. | ||
""" | ||
connection = op.get_bind() | ||
existing_tables = [item[0] for item in connection.execute( | ||
sa.text("SELECT name FROM sqlite_master WHERE type='table';")).fetchall()] | ||
for table_name in set(existing_tables).intersection(new_tables): | ||
drop_geo_table(op, table_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this is the right place to put this. I may move other functions here to prevent changing the same functionality multiple times in migrations 222 to 228.
…ver_references_in_geometry_columns
margrietpalm
changed the title
Remove left over references in geometry columns
WIP Remove left over references in geometry columns
Nov 22, 2024
…and implement fallback in case that doesn't work for unknown reasons
…of github.com:nens/threedi-schema into margriet_107_left_over_references_in_geometry_columns
…ver_references_in_geometry_columns
margrietpalm
changed the title
WIP Remove left over references in geometry columns
Remove left over references in geometry columns
Nov 26, 2024
…ver_references_in_geometry_columns
elisalle
reviewed
Nov 26, 2024
elisalle
reviewed
Nov 26, 2024
elisalle
reviewed
Nov 26, 2024
elisalle
approved these changes
Nov 26, 2024
margrietpalm
deleted the
margriet_107_left_over_references_in_geometry_columns
branch
November 26, 2024 13:17
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR was build upon #137 which should be reviewed first!
Changed how tables are dropped such that spatialite related references are automatically removed.
Note that this requires spatialite 5 or newer! Therefore, ubuntu 20.04 has been removed from the tests. This is no problem for our servers or the modellers interface.