Skip to content
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

Conversation

margrietpalm
Copy link
Contributor

@margrietpalm margrietpalm commented Nov 21, 2024

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.

@margrietpalm margrietpalm changed the title WIP: remove left over references in geometry columns Remove left over references in geometry columns 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)
Copy link
Contributor Author

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.

@margrietpalm margrietpalm changed the title Remove left over references in geometry columns WIP Remove left over references in geometry columns Nov 22, 2024
@margrietpalm margrietpalm removed the request for review from elisalle November 22, 2024 09:48
@margrietpalm margrietpalm changed the title WIP Remove left over references in geometry columns Remove left over references in geometry columns Nov 26, 2024
@margrietpalm margrietpalm merged commit 287b6db into margriet_schema_300_leftovers Nov 26, 2024
5 checks passed
@margrietpalm 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants