-
Notifications
You must be signed in to change notification settings - Fork 8.2k
feat: comprehensive database migration guidelines #10519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3691bd8
feat: Version 1.2 - comprehensive database migration guidelines using…
ricofurtado 40488b6
Update src/backend/base/langflow/alembic/DB-MIGRATION-GUIDE.MD
ricofurtado 5f7b330
fix: Cleanup text and typos
ricofurtado 1381f0a
feat: Implement migration validation workflow and add migration valid…
ricofurtado 6ac2304
Update src/backend/base/langflow/alembic/migration_validator.py
ricofurtado 3c407b3
Update src/backend/base/langflow/alembic/migration_validator.py
ricofurtado 76c9ba3
Update src/backend/base/langflow/alembic/migration_validator.py
ricofurtado b09f3c0
fix: moved the test_migrations directory to under tests
ricofurtado 0d919cd
feat: Added migration validator to pre-commit check.
ricofurtado 96e79b7
fix: improved test performance.
ricofurtado 782c6df
fix: optimized attribute resolution in migration validator
ricofurtado fed102c
feat: add comprehensive tests for migration validator and guidelines
ricofurtado 8af5c2a
fix: Lint is complaining about shebang declared but not being used.
ricofurtado ec8ad0a
fix: Shebang reinstated.
ricofurtado 1549d97
Update src/backend/base/langflow/alembic/DB-MIGRATION-GUIDE.MD
ricofurtado a613912
Update .github/workflows/migration-validation.yml
ricofurtado e7885d4
feat: color improvments
ricofurtado 75d347b
Update .github/workflows/migration-validation.yml
ricofurtado 80d432d
Update .github/workflows/migration-validation.yml
ricofurtado 03a5085
ci: Created relative paths for CI
ricofurtado e2cffc4
[autofix.ci] apply automated fixes
autofix-ci[bot] 0a86d9b
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] f675114
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] 082f591
fix: Component index json.
ricofurtado d5c3380
[autofix.ci] apply automated fixes
autofix-ci[bot] c540ec9
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] ba1a211
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| name: Database Migration Validation | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'src/backend/base/langflow/alembic/versions/*.py' | ||
| - 'alembic/versions/*.py' | ||
|
|
||
| jobs: | ||
| validate-migration: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| pip install sqlalchemy alembic | ||
|
|
||
| - name: Get changed migration files | ||
| id: changed-files | ||
| run: | | ||
| # Get all changed Python files in alembic/versions directories | ||
|
|
||
| # CHANGED_FILES=$(git diff --name-only origin/main...HEAD | grep -E '(alembic|migrations)/versions/.*\.py$' || echo "") | ||
|
|
||
| # Exclude test migrations, as they are not part of the main codebase | ||
| CHANGED_FILES=$(git diff --name-only origin/main...HEAD | grep -E '(alembic|migrations)/versions/.*\.py$' | grep -v 'test_migrations/' || echo "") | ||
|
|
||
| if [ -z "$CHANGED_FILES" ]; then | ||
| echo "No migration files changed" | ||
| echo "files=" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "Changed migration files:" | ||
| echo "$CHANGED_FILES" | ||
| # Convert newlines to spaces for passing as arguments | ||
| echo "files=$(echo $CHANGED_FILES | tr '\n' ' ')" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Validate migrations | ||
| if: steps.changed-files.outputs.files != '' | ||
| run: | | ||
| python src/backend/base/langflow/alembic/migration_validator.py ${{ steps.changed-files.outputs.files }} | ||
|
|
||
| # - name: Check migration phase sequence | ||
| # if: steps.changed-files.outputs.files != '' | ||
| # run: | | ||
| # python scripts/check_phase_sequence.py ${{ steps.changed-files.outputs.files }} | ||
|
|
||
| - name: Generate validation report | ||
| if: always() && steps.changed-files.outputs.files != '' | ||
| run: | | ||
| python src/backend/base/langflow/alembic/migration_validator.py \ | ||
| --json ${{ steps.changed-files.outputs.files }} > validation-report.json || true | ||
|
|
||
| - name: Post PR comment with results | ||
| if: always() && steps.changed-files.outputs.files != '' | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
|
|
||
| let message = ''; | ||
| let validationPassed = true; | ||
|
|
||
| try { | ||
| const report = JSON.parse(fs.readFileSync('validation-report.json', 'utf8')); | ||
|
|
||
| for (const result of report) { | ||
| if (!result.valid) { | ||
| validationPassed = false; | ||
| } | ||
| } | ||
|
|
||
| if (validationPassed) { | ||
| message = `✅ **Migration Validation Passed**\n\n`; | ||
| message += `All migrations follow the Expand-Contract pattern correctly.\n\n`; | ||
| } else { | ||
| message = `❌ **Migration Validation Failed**\n\n`; | ||
| message += `Your migrations don't follow the Expand-Contract pattern.\n\n`; | ||
|
|
||
| for (const result of report) { | ||
| if (!result.valid || result.warnings.length > 0) { | ||
| message += `### File: \`${result.file.split('/').pop()}\`\n`; | ||
| message += `**Phase:** ${result.phase}\n\n`; | ||
|
|
||
| if (result.violations && result.violations.length > 0) { | ||
| message += `**Violations:**\n`; | ||
| for (const v of result.violations) { | ||
| message += `- Line ${v.line}: ${v.message}\n`; | ||
| } | ||
| message += `\n`; | ||
| } | ||
|
|
||
| if (result.warnings && result.warnings.length > 0) { | ||
| message += `**Warnings:**\n`; | ||
| for (const w of result.warnings) { | ||
| message += `- Line ${w.line}: ${w.message}\n`; | ||
| } | ||
| message += `\n`; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| message += `### 📚 Resources\n`; | ||
| message += `- Review the [DB Migration Guide](./src/backend/base/langflow/alembic/DB-MIGRATION-GUIDE.MD)\n`; | ||
| message += `- Use \`python scripts/generate_migration.py --help\` to generate compliant migrations\n\n`; | ||
|
|
||
| message += `### Common Issues & Solutions\n`; | ||
| message += `- **New columns must be nullable:** Add \`nullable=True\` or \`server_default\`\n`; | ||
| message += `- **Missing phase marker:** Add \`Phase: EXPAND/MIGRATE/CONTRACT\` to docstring\n`; | ||
| message += `- **Column drops:** Only allowed in CONTRACT phase\n`; | ||
| message += `- **Direct renames:** Use expand-contract pattern instead\n`; | ||
| } | ||
| } catch (error) { | ||
| message = `⚠️ **Migration validation check failed to run properly**\n`; | ||
| message += `Error: ${error.message}\n`; | ||
| } | ||
|
|
||
| // Post or update comment | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| }); | ||
|
|
||
| const botComment = comments.find(comment => | ||
| comment.user.type === 'Bot' && | ||
| comment.body.includes('Migration Validation') | ||
| ); | ||
|
|
||
| if (botComment) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: botComment.id, | ||
| body: message | ||
| }); | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| body: message | ||
| }); | ||
| } | ||
|
|
||
| // Fail the workflow if validation didn't pass | ||
| if (!validationPassed) { | ||
| core.setFailed('Migration validation failed'); | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.