Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
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
2 changes: 2 additions & 0 deletions src/codegate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from codegate.codegate_logging import LogFormat, LogLevel, setup_logging
from codegate.config import Config, ConfigurationError
from codegate.db.connection import init_db_sync
from codegate.server import init_app


Expand Down Expand Up @@ -164,6 +165,7 @@ def serve(
},
)

init_db_sync()
app = init_app()

import uvicorn
Expand Down
9 changes: 6 additions & 3 deletions src/codegate/db/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __init__(self, sqlite_path: Optional[str] = None):
}
self._async_db_engine = create_async_engine(**engine_dict)
self._db_engine = create_engine(**engine_dict)

if not self.does_db_exist():
logger.info(f"Database does not exist at {self._db_path}. Creating..")
asyncio.run(self.init_db())
Expand Down Expand Up @@ -153,7 +152,6 @@ async def record_output_stream(
if output_chunks:
# Record the output chunks
output_str = json.dumps(output_chunks)
logger.info(f"Recorded chunks: {output_chunks}. Str: {output_str}")
await self._record_output(prompt, output_str)

async def record_output_non_stream(
Expand Down Expand Up @@ -181,7 +179,12 @@ async def record_output_non_stream(

def init_db_sync():
"""DB will be initialized in the constructor in case it doesn't exist."""
DbRecorder()
db = DbRecorder()
# Remove the DB file if exists for the moment to not cause issues at schema change.
# We can replace this in the future with migrations or something similar.
if db.does_db_exist():
db._db_path.unlink()
asyncio.run(db.init_db())


if __name__ == "__main__":
Expand Down