diff --git a/cognee-mcp/entrypoint.sh b/cognee-mcp/entrypoint.sh index 1d762242b..60b6ad459 100644 --- a/cognee-mcp/entrypoint.sh +++ b/cognee-mcp/entrypoint.sh @@ -58,14 +58,20 @@ else echo "Direct mode: Using local cognee instance" echo "Running database migrations..." + set +e # Disable exit on error to handle specific migration errors MIGRATION_OUTPUT=$(cd cognee && 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." + + echo "Migration failed with unexpected error. Trying to run Cognee without migrations." + echo "Initializing database tables..." + python /app/src/run_cognee_database_setup.py + INIT_EXIT_CODE=$? + + if [[ $INIT_EXIT_CODE -ne 0 ]]; then + echo "Database initialization failed!" exit 1 fi fi diff --git a/cognee-mcp/src/run_cognee_database_setup.py b/cognee-mcp/src/run_cognee_database_setup.py new file mode 100644 index 000000000..e0ac91ec4 --- /dev/null +++ b/cognee-mcp/src/run_cognee_database_setup.py @@ -0,0 +1,5 @@ +from cognee.modules.engine.operations.setup import setup +import asyncio + +if __name__ == "__main__": + asyncio.run(setup()) diff --git a/entrypoint.sh b/entrypoint.sh index 0a6d1cb25..ed7e6b15d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,19 +20,15 @@ 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. Trying to run Cognee without migrations." + echo "Migration failed with unexpected error. Trying to run Cognee without migrations." - echo "Initializing database tables..." - python /app/cognee/modules/engine/operations/setup.py - INIT_EXIT_CODE=$? + 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 + if [[ $INIT_EXIT_CODE -ne 0 ]]; then + echo "Database initialization failed!" + exit 1 fi else echo "Database migrations done."