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

refactor(backend): remove code for deleting db and tables #1864

Merged
merged 4 commits into from
Jul 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,11 @@ async def init_db(self):
Initialize the database based on the mode and create all tables.
"""
async with self.engine.begin() as conn:
# Drop all existing tables (if needed)
# await conn.run_sync(Base.metadata.drop_all)
# Create tables
for model in models:
await conn.run_sync(model.metadata.create_all)
logger.info(f"Using {self.mode} database...")

async def remove_db(self) -> None:
"""
Remove the database based on the mode.
"""
async with self.engine.begin() as conn:
for model in models:
await conn.run_sync(model.metadata.drop_all)

@asynccontextmanager
async def get_session(self) -> AsyncGenerator[AsyncSession, None]:
session = self.async_session()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
)

from agenta_backend.migrations.mongo_to_postgres.utils import (
drop_all_tables,
create_all_tables,
print_migration_report,
store_mapping,
Expand Down Expand Up @@ -501,7 +500,6 @@ async def transform_evaluation_scenario(scenario):

async def main():
try:
await drop_all_tables()
await create_all_tables(tables=tables)
await migrate_collection("users", UserDB, transform_user)
await migrate_collection("docker_images", ImageDB, transform_image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@
migration_report = {}


async def drop_all_tables():
"""Drop all tables in the database."""
async with db_engine.engine.begin() as conn:
await conn.run_sync(Base.metadata.reflect)
# Drop all tables with CASCADE option
for table in reversed(Base.metadata.sorted_tables):
await conn.execute(text(f"DROP TABLE IF EXISTS {table.name} CASCADE"))
print("\n====================== All tables are dropped.\n")


async def create_all_tables(tables):
"""Create all tables in the database."""
async with db_engine.engine.begin() as conn:
Expand Down
Loading