ci: add GitHub Actions workflows #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Database Migration Workflow | ||
| # | ||
| # This workflow handles database migrations and schema checks. | ||
| # It can be used to: | ||
| # - Validate database schema changes | ||
| # - Run migrations in a test environment | ||
| # - Generate migration files | ||
| # | ||
| # Note: This workflow requires database credentials to be set as GitHub secrets. | ||
| # Required secrets: | ||
| # - DATABASE_URL: PostgreSQL connection string | ||
| name: Database | ||
| # Trigger manually or on specific file changes | ||
| on: | ||
| workflow_dispatch: # Allows manual triggering | ||
| push: | ||
| branches: | ||
| - main | ||
| - develop | ||
| paths: | ||
| - 'config/database/**' | ||
| - 'drizzle/**' | ||
| - 'drizzle.config.ts' | ||
| jobs: | ||
| # Validate database schema | ||
| validate-schema: | ||
| name: Validate Schema | ||
| runs-on: ubuntu-latest | ||
| # Skip if database URL is not available | ||
| if: ${{ secrets.DATABASE_URL != '' }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 8 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20.x' | ||
| cache: 'pnpm' | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| # Generate migration files to check for schema changes | ||
| - name: Generate migrations | ||
| run: pnpm db:generate | ||
| env: | ||
| DATABASE_URL: ${{ secrets.DATABASE_URL }} | ||
| # Check if there are uncommitted migration files | ||
| - name: Check for uncommitted migrations | ||
| run: | | ||
| if [ -n "$(git status --porcelain drizzle/)" ]; then | ||
| echo "⚠️ Uncommitted migration files detected!" | ||
| git status | ||
| exit 1 | ||
| else | ||
| echo "✅ All migrations are committed" | ||
| fi | ||