fix: CI workflows — add nodejs, clean up migration runner

deploy.yaml: add nodejs install (required for actions/checkout)
migrate.yaml: rewrite migration runner
  - Use PGHOST/PGUSER/PGPASSWORD env vars (no inline -h/-U/-p flags)
  - ON_ERROR_STOP=1 for strict error handling on push
  - || true for dispatch (idempotent full replay)
  - Verify schema after apply
  - fetch-depth: 2 for diff detection
This commit is contained in:
2026-09-11 10:37:08 +09:00
parent 8290e9de37
commit 8dc774a6c8
2 changed files with 59 additions and 45 deletions
+4 -2
View File
@@ -15,8 +15,10 @@ jobs:
name: Tag & Push Latest name: Tag & Push Latest
runs-on: rust runs-on: rust
steps: steps:
- name: Install Docker - name: Install Node.js and Docker
run: apt-get update && apt-get install -y docker.io run: |
apt-get update
apt-get install -y nodejs docker.io
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
+55 -43
View File
@@ -11,66 +11,78 @@ env:
DB_HOST: memory-db-rw.poimen.svc.cluster.local DB_HOST: memory-db-rw.poimen.svc.cluster.local
DB_PORT: "5432" DB_PORT: "5432"
DB_NAME: memory DB_NAME: memory
MIGRATIONS_DIR: crates/mem-store/migrations
jobs: jobs:
migrate: migrate:
name: Run Migrations name: Run Migrations
runs-on: rust runs-on: rust
steps: steps:
- name: Install psql - name: Install Node.js and psql
run: apt-get update && apt-get install -y postgresql-client run: |
apt-get update
apt-get install -y nodejs postgresql-client
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Fetch previous migrations state - name: Detect changed migrations
id: detect
run: | run: |
git fetch origin main --depth=2 CHANGED=$(git diff --name-only HEAD~1 HEAD -- "$MIGRATIONS_DIR"/*.sql 2>/dev/null || echo "")
# List changed migration files if [ -n "$CHANGED" ]; then
CHANGED=$(git diff --name-only HEAD~1 HEAD -- crates/mem-store/migrations/ || echo "") echo "files=$CHANGED" >> $GITHUB_OUTPUT
echo "Changed migrations: $CHANGED" echo "found=true" >> $GITHUB_OUTPUT
echo "CHANGED_MIGRATIONS=$CHANGED" >> $GITHUB_ENV echo "Changed: $CHANGED"
else
echo "found=false" >> $GITHUB_OUTPUT
echo "No migration changes detected"
fi
- name: Run migrations - name: Apply changed migrations (push)
if: env.CHANGED_MIGRATIONS != '' if: github.event_name == 'push' && steps.detect.outputs.found == 'true'
env:
PGHOST: ${{ env.DB_HOST }}
PGPORT: ${{ env.DB_PORT }}
PGDATABASE: ${{ env.DB_NAME }}
PGUSER: ${{ secrets.DB_USER }}
PGPASSWORD: ${{ secrets.DB_PASSWORD }}
run: | run: |
export PGPASSWORD="${DB_PASSWORD}" for f in ${{ steps.detect.outputs.files }}; do
[ -f "$f" ] || continue
echo "=== Running changed migrations ===" echo "=== Applying: $f ==="
for f in $CHANGED_MIGRATIONS; do psql -v ON_ERROR_STOP=1 -f "$f"
if [ -f "$f" ]; then echo "=== OK ==="
echo "--- Applying: $f ---"
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f "$f" 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Migration $f failed!"
exit 1
fi
echo "--- OK: $f ---"
fi
done done
echo "=== Verify schema ===" - name: Apply all migrations (dispatch)
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c "\dt memory*"
env:
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
- name: Run all migrations (manual trigger)
if: github.event_name == 'workflow_dispatch' if: github.event_name == 'workflow_dispatch'
env:
PGHOST: ${{ env.DB_HOST }}
PGPORT: ${{ env.DB_PORT }}
PGDATABASE: ${{ env.DB_NAME }}
PGUSER: ${{ secrets.DB_USER }}
PGPASSWORD: ${{ secrets.DB_PASSWORD }}
run: | run: |
export PGPASSWORD="${DB_PASSWORD}" for f in $(ls "$MIGRATIONS_DIR"/*.sql | sort); do
echo "=== Applying: $f ==="
echo "=== Running all migrations in order ===" psql -v ON_ERROR_STOP=1 -f "$f" || true
for f in $(ls crates/mem-store/migrations/*.sql | sort); do echo "=== Done ==="
echo "--- Applying: $f ---"
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f "$f" 2>&1 || true
echo "--- Done: $f ---"
done done
echo "=== Final schema ===" - name: Verify schema
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c "\dt memory*"
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c "\d memory_entity"
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c "\d memory_edge"
env: env:
DB_USER: ${{ secrets.DB_USER }} PGHOST: ${{ env.DB_HOST }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} PGPORT: ${{ env.DB_PORT }}
PGDATABASE: ${{ env.DB_NAME }}
PGUSER: ${{ secrets.DB_USER }}
PGPASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
echo "=== Tables ==="
psql -c "\dt memory*"
echo "=== Entity Schema ==="
psql -c "\d memory_entity"
echo "=== Edge Schema ==="
psql -c "\d memory_edge"