diff --git a/cognee/modules/engine/operations/setup.py b/cognee/modules/engine/operations/setup.py index a54d4b949..4992931f2 100644 --- a/cognee/modules/engine/operations/setup.py +++ b/cognee/modules/engine/operations/setup.py @@ -15,3 +15,9 @@ async def setup(): """ await create_relational_db_and_tables() await create_pgvector_db_and_tables() + + +if __name__ == "__main__": + import asyncio + + asyncio.run(setup()) diff --git a/entrypoint.sh b/entrypoint.sh index 496825408..82c4a2fea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,19 +20,29 @@ echo "HTTP port: $HTTP_PORT" # smooth redeployments and container restarts while maintaining data integrity. echo "Running database migrations..." +set +e # Disable exit on error to handle specific migration errors MIGRATION_OUTPUT=$(alembic upgrade head) MIGRATION_EXIT_CODE=$? +set -e if [[ $MIGRATION_EXIT_CODE -ne 0 ]]; then if [[ "$MIGRATION_OUTPUT" == *"UserAlreadyExists"* ]] || [[ "$MIGRATION_OUTPUT" == *"User default_user@example.com already exists"* ]]; then echo "Warning: Default user already exists, continuing startup..." else - echo "Migration failed with unexpected error." - exit 1 - fi -fi + echo "Migration failed with unexpected error. Trying to run Cognee without migrations." -echo "Database migrations done." + echo "Initializing database tables..." + python /app/cognee/modules/engine/operations/setup.py + INIT_EXIT_CODE=$? + + if [[ $INIT_EXIT_CODE -ne 0 ]]; then + echo "Database initialization failed!" + exit 1 + fi + fi +else + echo "Database migrations done." +fi echo "Starting server..."