Skip to content

consider alembic used also by cacholote #122

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

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 3 additions & 4 deletions cads_broker/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,7 @@ def init_database(connection_string: str, force: bool = False) -> sa.engine.Engi
sqlalchemy_utils.create_database(engine.url)
# cleanup and create the schema
BaseModel.metadata.drop_all(engine)
cacholote.database.Base.metadata.drop_all(engine)
cacholote.database.Base.metadata.create_all(engine)
cacholote.init_database(connection_string, force)
BaseModel.metadata.create_all(engine)
alembic.command.stamp(alembic_cfg, "head")
else:
Expand All @@ -893,11 +892,11 @@ def init_database(connection_string: str, force: bool = False) -> sa.engine.Engi
if force:
# cleanup and create the schema
BaseModel.metadata.drop_all(engine)
cacholote.database.Base.metadata.drop_all(engine)
cacholote.database.Base.metadata.create_all(engine)
cacholote.init_database(connection_string, force)
BaseModel.metadata.create_all(engine)
alembic.command.stamp(alembic_cfg, "head")
else:
# update db structure
cacholote.init_database(connection_string, force)
alembic.command.upgrade(alembic_cfg, "head")
return engine
4 changes: 2 additions & 2 deletions tests/test_02_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ def test_init_database(postgresql: Connection[str]) -> None:
db.init_database(connection_string, force=True)
expected_tables_complete = (
set(db.BaseModel.metadata.tables)
.union({"alembic_version"})
.union({"alembic_version_cacholote"})
.union(set(cacholote.database.Base.metadata.tables))
)
assert set(conn.execute(query).scalars()) == expected_tables_complete # type: ignore
Expand Down Expand Up @@ -1032,7 +1032,7 @@ def test_init_database_with_password(postgresql2: Connection[str]) -> None:
db.init_database(connection_string, force=True)
expected_tables_complete = (
set(db.BaseModel.metadata.tables)
.union({"alembic_version"})
.union({"alembic_version_cacholote"})
.union(set(cacholote.database.Base.metadata.tables))
)
assert set(conn.execute(query).scalars()) == expected_tables_complete # type: ignore
Expand Down
4 changes: 3 additions & 1 deletion tests/test_90_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def test_init_db(postgresql: Connection[str], mocker) -> None:
)
assert set(conn.execute(query).scalars()) == set(
database.BaseModel.metadata.tables
).union({"alembic_version"}).union(set(cacholote.database.Base.metadata.tables))
).union({"alembic_version_cacholote"}).union(
set(cacholote.database.Base.metadata.tables)
)
conn.close()


Expand Down
Loading