Skip to content

Commit

Permalink
Merge pull request #1864 from Agenta-AI/cleanup/remove-table-deletion…
Browse files Browse the repository at this point in the history
…-code

refactor(backend): remove code for deleting db and tables
  • Loading branch information
aakrem committed Jul 10, 2024
2 parents 4500e57 + 9fe8df0 commit 12f70a6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 22 deletions.
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

0 comments on commit 12f70a6

Please sign in to comment.