nens / threedi-schema

The schema of 3Di schematization files
MIT License
0 stars 0 forks source link

[0.226.4] Many geometry column references are not removed by the migration #107

Open leendertvanwolfswinkel opened 1 month ago

leendertvanwolfswinkel commented 1 month ago

See for example the Boezemmodel__neerslag schematisation

elisalle commented 1 month ago

When I run the migrations with threedi-schema 0.226.4 on Boezemmodel__neerslag, all of the tables you mention are gone after the migration. Can we look at this together when you have time?

elisalle commented 1 month ago

Went through this with Leendert and it appears to work.

elisalle commented 1 month ago

Update: the tables are removed, but the references to the geometry columns in the geometry_columns table are not dropped. A solution could be cleaning up any orphaned references at the end of the migration:

def drop_deleted_geom_column_triggers():
    geometry_column_references = []
    connection = op.get_bind()
    result = connection.execute(sa.text("SELECT * FROM geometry_columns;")).fetchall()
    for row in result:
        geometry_column_references.append({"table": row[0], "column": row[1]})
    for reference in geometry_column_references:
        try:
            connection.execute(sa.text(f"SELECT {reference['column']} FROM {reference['table']};"))
        except sqlalchemy.exc.OperationalError:
            connection.execute(sa.text(f"SELECT DiscardGeometryColumn('{reference['table']}', '{reference['column']}';"))
elisalle commented 1 month ago

@leendertvanwolfswinkel Margriet says that there is an epic with all the last cleanup things for when the 300 schema migration is almost ready, and suggests that this should go in there.