Skip to content

feat(chat): complete connected-site operational parity #1589

feat(chat): complete connected-site operational parity

feat(chat): complete connected-site operational parity #1589

name: Check Database Migrations
on:
pull_request:
paths:
- "apps/database/supabase/migrations/**.sql"
jobs:
check-ci:
uses: ./.github/workflows/ci-check.yml
with:
workflow_name: check-migrations.yml
check-migrations:
needs: [check-ci]
if: needs.check-ci.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0 # needed for diffing against base branch
- name: Get new migration files
id: new_migrations
run: |
NEW_FILES=$(git diff --name-only --diff-filter=A ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- 'apps/database/supabase/migrations/**.sql')
echo "new_files<<EOF" >> $GITHUB_OUTPUT
echo "$NEW_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Check new migration files
run: |
NEW_MIGRATIONS="${{ steps.new_migrations.outputs.new_files }}"
if [ -z "$NEW_MIGRATIONS" ]; then
echo "No new migration files found. Skipping checks."
exit 0
fi
echo "New migration files found:"
echo "$NEW_MIGRATIONS"
# Check 1: No file should end with _new_migration.sql
for file in $NEW_MIGRATIONS; do
if [[ "$file" == *"_new_migration.sql" ]]; then
echo "::error file=$file::Migration file '$file' must not end with '_new_migration.sql'."
exit 1
fi
done
# Check 2: New migrations must be chronologically after existing ones.
LAST_BASE_MIGRATION_PATH=$(git ls-tree -r --name-only ${{ github.event.pull_request.base.sha }} apps/database/supabase/migrations | grep '\.sql$' | sort -r | head -n 1)
if [ -z "$LAST_BASE_MIGRATION_PATH" ]; then
echo "No existing migrations in base branch. Skipping chronological check."
else
LAST_BASE_MIGRATION=$(basename "$LAST_BASE_MIGRATION_PATH")
echo "Last migration in base branch: $LAST_BASE_MIGRATION"
for file in $NEW_MIGRATIONS; do
CURRENT_MIGRATION_BASENAME=$(basename "$file")
if [[ "$CURRENT_MIGRATION_BASENAME" < "$LAST_BASE_MIGRATION" ]]; then
echo "::error file=$file::New migration file '$file' is older than the last migration in base branch '$LAST_BASE_MIGRATION_PATH'."
exit 1
fi
done
fi
echo "All migration checks passed."