Skip to content

WIP: Check if table already exists before creating it #158

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontera/contrib/backends/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def strategy_worker(cls, manager):
if drop_all_tables:
if model.__table__.name in inspector.get_table_names():
model.__table__.drop(bind=b.engine)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably the same check should be added to drop().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think the check above if model.__table__.name in inspector.get_table_names() should do the same thing, but checkfirst=True looks better.

model.__table__.create(bind=b.engine)
model.__table__.create(bind=b.engine, checkfirst=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is happening because SQLA has non-unified behavior between various engines. For example that code works well for sqlite, without need of checkfirst=True. However, I still think it makes sense to merge it.


if clear_content:
session = b.session_cls()
Expand All @@ -158,8 +158,8 @@ def db_worker(cls, manager):
metadata_m.__table__.drop(bind=b.engine)
if queue_m.__table__.name in existing:
queue_m.__table__.drop(bind=b.engine)
metadata_m.__table__.create(bind=b.engine)
queue_m.__table__.create(bind=b.engine)
metadata_m.__table__.create(bind=b.engine, checkfirst=True)
queue_m.__table__.create(bind=b.engine, checkfirst=True)

if clear_content:
session = b.session_cls()
Expand Down