From 12560c391ec8303092c175d7a216497f19a047e1 Mon Sep 17 00:00:00 2001 From: Igor Ilic Date: Fri, 16 Jan 2026 14:48:00 +0100 Subject: [PATCH] refactor: update alembic upgrade calls to be done from cognee folder --- Dockerfile | 4 ---- cognee-mcp/Dockerfile | 4 ++-- cognee-mcp/entrypoint.sh | 26 +++++++++----------------- entrypoint.sh | 10 ++-------- 4 files changed, 13 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9b9a34d41..8b42e405d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,10 +34,6 @@ COPY README.md pyproject.toml uv.lock entrypoint.sh ./ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --extra debug --extra api --extra postgres --extra neo4j --extra llama-index --extra ollama --extra mistral --extra groq --extra anthropic --frozen --no-install-project --no-dev --no-editable -# Copy Alembic configuration -COPY alembic.ini /app/alembic.ini -COPY alembic/ /app/alembic - # Then, add the rest of the project source code and install it # Installing separately from its dependencies allows optimal layer caching COPY ./cognee /app/cognee diff --git a/cognee-mcp/Dockerfile b/cognee-mcp/Dockerfile index 6608102c8..cf30466df 100644 --- a/cognee-mcp/Dockerfile +++ b/cognee-mcp/Dockerfile @@ -34,8 +34,8 @@ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --frozen --no-install-project --no-dev --no-editable # Copy Alembic configuration -COPY alembic.ini /app/alembic.ini -COPY alembic/ /app/alembic +COPY cognee/alembic.ini /app/cognee/alembic.ini +COPY cognee/alembic/ /app/cognee/alembic # Then, add the rest of the project source code and install it # Installing separately from its dependencies allows optimal layer caching diff --git a/cognee-mcp/entrypoint.sh b/cognee-mcp/entrypoint.sh index cf7d19f0a..1d762242b 100644 --- a/cognee-mcp/entrypoint.sh +++ b/cognee-mcp/entrypoint.sh @@ -7,11 +7,11 @@ echo "Environment: $ENVIRONMENT" # Install optional dependencies if EXTRAS is set if [ -n "$EXTRAS" ]; then echo "Installing optional dependencies: $EXTRAS" - + # Get the cognee version that's currently installed COGNEE_VERSION=$(uv pip show cognee | grep "Version:" | awk '{print $2}') echo "Current cognee version: $COGNEE_VERSION" - + # Build the extras list for cognee IFS=',' read -ra EXTRA_ARRAY <<< "$EXTRAS" # Combine base extras from pyproject.toml with requested extras @@ -28,11 +28,11 @@ if [ -n "$EXTRAS" ]; then fi fi done - + echo "Installing cognee with extras: $ALL_EXTRAS" echo "Running: uv pip install 'cognee[$ALL_EXTRAS]==$COGNEE_VERSION'" uv pip install "cognee[$ALL_EXTRAS]==$COGNEE_VERSION" - + # Verify installation echo "" echo "✓ Optional dependencies installation completed" @@ -56,17 +56,9 @@ if [ -n "$API_URL" ]; then echo "Skipping database migrations (API server handles its own database)" else echo "Direct mode: Using local cognee instance" - # Run Alembic migrations with proper error handling. - # Note on UserAlreadyExists error handling: - # During database migrations, we attempt to create a default user. If this user - # already exists (e.g., from a previous deployment or migration), it's not a - # critical error and shouldn't prevent the application from starting. This is - # different from other migration errors which could indicate database schema - # inconsistencies and should cause the startup to fail. This check allows for - # smooth redeployments and container restarts while maintaining data integrity. echo "Running database migrations..." - MIGRATION_OUTPUT=$(alembic upgrade head) + MIGRATION_OUTPUT=$(cd cognee && alembic upgrade head) MIGRATION_EXIT_CODE=$? if [[ $MIGRATION_EXIT_CODE -ne 0 ]]; then @@ -93,19 +85,19 @@ if [ -n "$API_URL" ]; then if echo "$API_URL" | grep -q "localhost" || echo "$API_URL" | grep -q "127.0.0.1"; then echo "⚠️ Warning: API_URL contains localhost/127.0.0.1" echo " Original: $API_URL" - + # Try to use host.docker.internal (works on Mac/Windows and recent Linux with Docker Desktop) FIXED_API_URL=$(echo "$API_URL" | sed 's/localhost/host.docker.internal/g' | sed 's/127\.0\.0\.1/host.docker.internal/g') - + echo " Converted to: $FIXED_API_URL" echo " This will work on Mac/Windows/Docker Desktop." echo " On Linux without Docker Desktop, you may need to:" echo " - Use --network host, OR" echo " - Set API_URL=http://172.17.0.1:8000 (Docker bridge IP)" - + API_URL="$FIXED_API_URL" fi - + API_ARGS="--api-url $API_URL" if [ -n "$API_TOKEN" ]; then API_ARGS="$API_ARGS --api-token $API_TOKEN" diff --git a/entrypoint.sh b/entrypoint.sh index 496825408..e20cff463 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,16 +11,10 @@ echo "Debug port: $DEBUG_PORT" echo "HTTP port: $HTTP_PORT" # Run Alembic migrations with proper error handling. -# Note on UserAlreadyExists error handling: -# During database migrations, we attempt to create a default user. If this user -# already exists (e.g., from a previous deployment or migration), it's not a -# critical error and shouldn't prevent the application from starting. This is -# different from other migration errors which could indicate database schema -# inconsistencies and should cause the startup to fail. This check allows for -# smooth redeployments and container restarts while maintaining data integrity. echo "Running database migrations..." -MIGRATION_OUTPUT=$(alembic upgrade head) +# Move to the cognee directory to run alembic migrations from there +MIGRATION_OUTPUT=$(cd cognee && alembic upgrade head) MIGRATION_EXIT_CODE=$? if [[ $MIGRATION_EXIT_CODE -ne 0 ]]; then