Database Migrations
Purpose
Create, review, apply, and troubleshoot Alembic migrations safely.
Project Stack
Alembic, SQLAlchemy 2, PostgreSQL.
Operating Principles
- Never edit historical migrations casually.
- Inspect the current migration head before creating a migration.
- Ensure every migration has a clear upgrade and downgrade strategy when practical.
- Review generated migrations instead of blindly trusting autogeneration.
- Check for destructive operations.
- Consider existing production data before changing constraints or column types.
- Consider lock duration and migration runtime for large tables.
- Never reset a shared database to solve a migration problem.
- Verify migration ordering and dependency relationships.
- Test both schema application and application compatibility.
Required Workflow
- Inspect migration history.
- Inspect current models and database state.
- Generate or write the migration.
- Review the migration manually.
- Apply it in a disposable/test environment.
- Run application tests.
- Verify downgrade behavior where applicable.
- Check for destructive or long-running operations.
- Inspect the final migration diff.
Evidence Rules
Use the strongest available evidence in this order:
- Runtime behavior
- Automated test results
- Type checking, linting, and build results
- Installed package/source behavior
- Official framework or library documentation
- Repository configuration
- Static code inspection
- General model knowledge
Never report an assumption as a verified result.
Tool Selection
- Use Filesystem MCP for repository exploration and file inspection.
- Use Context7 for current, version-specific library/framework documentation.
- Use Fetch when official documentation or public web resources need to be retrieved.
- Use Playwright for browser behavior, frontend interaction, forms, authentication flows, and UI verification.
- Use GitHub CLI for repository, branch, pull request, issue, workflow, and CI operations.
- Prefer the smallest tool set that establishes reliable evidence.
Failure Handling
When something fails:
- Reproduce the failure.
- Capture the exact error.
- Identify the failing layer.
- Check whether the failure is environmental, dependency-related, configuration-related, or caused by application code.
- Research uncertain behavior using authoritative sources.
- Apply the smallest appropriate fix.
- Reproduce the original failure again.
- Run regression checks.
- Inspect the final diff.
Do not hide failures by weakening tests, suppressing errors, deleting evidence, or claiming success without verification.
Security
- Never expose secrets.
- Never commit credentials.
- Treat all external input as untrusted.
- Preserve authentication and authorization boundaries.
- Avoid leaking internal implementation details through errors.
- Review security implications whenever the skill touches users, data, credentials, networking, or deployment.
Completion Criteria
A task using this skill is complete only when:
- The requested behavior is implemented.
- Existing project conventions are preserved.
- Relevant static checks pass.
- Relevant tests pass or their absence is explicitly reported.
- Browser verification is performed when the task affects user-facing behavior.
- Security implications have been considered.
- The final diff has been inspected.
- Verified facts are clearly distinguished from assumptions or remaining uncertainty.
1---2name: migrations3description: Database Migrations4---5# Database Migrations67## Purpose89Create, review, apply, and troubleshoot Alembic migrations safely.1011## Project Stack1213Alembic, SQLAlchemy 2, PostgreSQL.1415## Operating Principles16171. Never edit historical migrations casually.182. Inspect the current migration head before creating a migration.193. Ensure every migration has a clear upgrade and downgrade strategy when practical.204. Review generated migrations instead of blindly trusting autogeneration.215. Check for destructive operations.226. Consider existing production data before changing constraints or column types.237. Consider lock duration and migration runtime for large tables.248. Never reset a shared database to solve a migration problem.259. Verify migration ordering and dependency relationships.2610. Test both schema application and application compatibility.2728## Required Workflow29301. Inspect migration history.312. Inspect current models and database state.323. Generate or write the migration.334. Review the migration manually.345. Apply it in a disposable/test environment.356. Run application tests.367. Verify downgrade behavior where applicable.378. Check for destructive or long-running operations.389. Inspect the final migration diff.3940## Evidence Rules4142Use the strongest available evidence in this order:43441. Runtime behavior452. Automated test results463. Type checking, linting, and build results474. Installed package/source behavior485. Official framework or library documentation496. Repository configuration507. Static code inspection518. General model knowledge5253Never report an assumption as a verified result.5455## Tool Selection5657- Use Filesystem MCP for repository exploration and file inspection.58- Use Context7 for current, version-specific library/framework documentation.59- Use Fetch when official documentation or public web resources need to be retrieved.60- Use Playwright for browser behavior, frontend interaction, forms, authentication flows, and UI verification.61- Use GitHub CLI for repository, branch, pull request, issue, workflow, and CI operations.62- Prefer the smallest tool set that establishes reliable evidence.6364## Failure Handling6566When something fails:67681. Reproduce the failure.692. Capture the exact error.703. Identify the failing layer.714. Check whether the failure is environmental, dependency-related, configuration-related, or caused by application code.725. Research uncertain behavior using authoritative sources.736. Apply the smallest appropriate fix.747. Reproduce the original failure again.758. Run regression checks.769. Inspect the final diff.7778Do not hide failures by weakening tests, suppressing errors, deleting evidence, or claiming success without verification.7980## Security8182- Never expose secrets.83- Never commit credentials.84- Treat all external input as untrusted.85- Preserve authentication and authorization boundaries.86- Avoid leaking internal implementation details through errors.87- Review security implications whenever the skill touches users, data, credentials, networking, or deployment.8889## Completion Criteria9091A task using this skill is complete only when:9293- The requested behavior is implemented.94- Existing project conventions are preserved.95- Relevant static checks pass.96- Relevant tests pass or their absence is explicitly reported.97- Browser verification is performed when the task affects user-facing behavior.98- Security implications have been considered.99- The final diff has been inspected.100- Verified facts are clearly distinguished from assumptions or remaining uncertainty.