Skip to content
Merged
Show file tree
Hide file tree
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 Nov 6, 2025
40488b6
Update src/backend/base/langflow/alembic/DB-MIGRATION-GUIDE.MD
ricofurtado Nov 6, 2025
5f7b330
fix: Cleanup text and typos
ricofurtado Nov 6, 2025
1381f0a
feat: Implement migration validation workflow and add migration valid…
ricofurtado Nov 17, 2025
6ac2304
Update src/backend/base/langflow/alembic/migration_validator.py
ricofurtado Nov 17, 2025
3c407b3
Update src/backend/base/langflow/alembic/migration_validator.py
ricofurtado Nov 17, 2025
76c9ba3
Update src/backend/base/langflow/alembic/migration_validator.py
ricofurtado Nov 17, 2025
b09f3c0
fix: moved the test_migrations directory to under tests
ricofurtado Nov 17, 2025
0d919cd
feat: Added migration validator to pre-commit check.
ricofurtado Nov 17, 2025
96e79b7
fix: improved test performance.
ricofurtado Nov 17, 2025
782c6df
fix: optimized attribute resolution in migration validator
ricofurtado Nov 17, 2025
fed102c
feat: add comprehensive tests for migration validator and guidelines
ricofurtado Nov 24, 2025
8af5c2a
fix: Lint is complaining about shebang declared but not being used.
ricofurtado Nov 24, 2025
ec8ad0a
fix: Shebang reinstated.
ricofurtado Nov 24, 2025
1549d97
Update src/backend/base/langflow/alembic/DB-MIGRATION-GUIDE.MD
ricofurtado Nov 24, 2025
a613912
Update .github/workflows/migration-validation.yml
ricofurtado Nov 24, 2025
e7885d4
feat: color improvments
ricofurtado Nov 24, 2025
75d347b
Update .github/workflows/migration-validation.yml
ricofurtado Nov 24, 2025
80d432d
Update .github/workflows/migration-validation.yml
ricofurtado Nov 24, 2025
03a5085
ci: Created relative paths for CI
ricofurtado Nov 24, 2025
e2cffc4
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 24, 2025
0a86d9b
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Nov 24, 2025
f675114
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Nov 24, 2025
082f591
fix: Component index json.
ricofurtado Nov 24, 2025
d5c3380
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 24, 2025
c540ec9
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Nov 24, 2025
ba1a211
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Nov 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions .github/workflows/migration-validation.yml
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');
}
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ repos:
language: system
types_or: [python, pyi]
args: [--config, pyproject.toml]
- id: validate-migrations
name: Validate Alembic Migrations (Expand-Contract)
entry: python src/backend/base/langflow/alembic/migration_validator.py
language: python
files: (alembic|migrations)/versions/.*\.py$
additional_dependencies: [sqlalchemy, alembic]
pass_filenames: true
always_run: false
verbose: true
- id: check-migration-phase
name: Check Migration Phase Documentation
entry: python -c "import sys, re; content = open(sys.argv[1]).read(); sys.exit(0 if re.search(r'Phase:\s*(EXPAND|MIGRATE|CONTRACT)', content) else 1)"
language: python
files: (alembic|migrations)/versions/.*\.py$
pass_filenames: true
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
Expand Down
10 changes: 9 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "0.2.0",
"configurations": [

{
"name": "Debug Backend",
"type": "debugpy",
Expand Down Expand Up @@ -79,6 +80,13 @@
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false
}
},
{
"name": "Python Debugger: Python File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
Loading
Loading