refactor: add fix for database creation to mcp

This commit is contained in:
Igor Ilic 2026-01-16 22:32:38 +01:00
parent b6d7fe21de
commit 255f7c7a4a
3 changed files with 22 additions and 15 deletions

View file

@ -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

View file

@ -0,0 +1,5 @@
from cognee.modules.engine.operations.setup import setup
import asyncio
if __name__ == "__main__":
asyncio.run(setup())

View file

@ -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."