Files
poimen-memory/.gitea/workflows/migrate.yaml
T
rock 8dc774a6c8 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
2026-09-11 10:37:08 +09:00

89 lines
2.6 KiB
YAML

name: DB Migration
on:
push:
branches: [main]
paths:
- 'crates/mem-store/migrations/**'
workflow_dispatch:
env:
DB_HOST: memory-db-rw.poimen.svc.cluster.local
DB_PORT: "5432"
DB_NAME: memory
MIGRATIONS_DIR: crates/mem-store/migrations
jobs:
migrate:
name: Run Migrations
runs-on: rust
steps:
- name: Install Node.js and psql
run: |
apt-get update
apt-get install -y nodejs postgresql-client
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Detect changed migrations
id: detect
run: |
CHANGED=$(git diff --name-only HEAD~1 HEAD -- "$MIGRATIONS_DIR"/*.sql 2>/dev/null || echo "")
if [ -n "$CHANGED" ]; then
echo "files=$CHANGED" >> $GITHUB_OUTPUT
echo "found=true" >> $GITHUB_OUTPUT
echo "Changed: $CHANGED"
else
echo "found=false" >> $GITHUB_OUTPUT
echo "No migration changes detected"
fi
- name: Apply changed migrations (push)
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: |
for f in ${{ steps.detect.outputs.files }}; do
[ -f "$f" ] || continue
echo "=== Applying: $f ==="
psql -v ON_ERROR_STOP=1 -f "$f"
echo "=== OK ==="
done
- name: Apply all migrations (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: |
for f in $(ls "$MIGRATIONS_DIR"/*.sql | sort); do
echo "=== Applying: $f ==="
psql -v ON_ERROR_STOP=1 -f "$f" || true
echo "=== Done ==="
done
- name: Verify schema
env:
PGHOST: ${{ env.DB_HOST }}
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"