Skip to content

Commit

Permalink
Fix problem with database importer seeing dangling multihop tables
Browse files Browse the repository at this point in the history
  • Loading branch information
apontzen committed Nov 7, 2023
1 parent 6a268c0 commit 25ff9c9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tangos/scripts/db_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,15 @@ def _drop_foreign_keys(session):
all_fks = []

for table_name in Base.metadata.tables:
fks = []
for fk in inspector.get_foreign_keys(table_name):
if fk['name']:
fks.append(ForeignKeyConstraint((), (), name=fk['name']))
t = Table(table_name, fake_metadata, *fks)
fake_tables.append(t)
all_fks.extend(fks)
# if the metadata has multihop tables left, we aren't interested in those (they're not really in the database)
if 'multihop' not in table_name:
fks = []
for fk in inspector.get_foreign_keys(table_name):
if fk['name']:
fks.append(ForeignKeyConstraint((), (), name=fk['name']))
t = Table(table_name, fake_metadata, *fks)
fake_tables.append(t)
all_fks.extend(fks)

with engine.begin() as conn:
for fkc in all_fks:
Expand Down

0 comments on commit 25ff9c9

Please sign in to comment.