Database Rules¶
Track database migrations and schema changes.
Rules in this Category¶
| Rule Name | Label | Risk Level | Description |
|---|---|---|---|
migration |
migration |
๐ต Info | Any migration file modified |
risky-migration |
risky-migration |
๐ด High | Destructive operations (DROP, TRUNCATE) |
safe-migration |
safe-migration |
๐ข Low | Additive operations (CREATE, INSERT) |
schema-change |
schema-change |
๐ก Medium | Schema modifications (ALTER, MODIFY) |
migration¶
Detects any database migration file changes.
Detection¶
Matches files in migration directories:
migrations/db/migrations/database/migrations/
Example¶
Changed Files:
Result: โ
migration label applied
risky-migration¶
Flags destructive database operations.
Detection Patterns¶
Detects these SQL operations:
DROP TABLEDROP COLUMNTRUNCATE TABLEALTER TABLE ... DROPDROP INDEXDROP CONSTRAINT
Use Cases¶
- ๐จ Require senior engineer review
- ๐จ Extra testing before production
- ๐จ Backup verification
- ๐จ Rollback plan required
Example¶
Configuration¶
Require Manual Review
Use branch protection rules to require additional reviews when risky-migration is applied.
safe-migration¶
Identifies additive database operations.
Detection Patterns¶
CREATE TABLECREATE INDEXINSERT INTOADD COLUMNADD CONSTRAINT
Use Cases¶
- โ Fast-track safe migrations
- โ Lower review requirements
- โ Identify non-breaking changes
Example¶
ALTER TABLE users
ADD COLUMN email_verified BOOLEAN DEFAULT FALSE;
Result: ๐ข safe-migration label applied
schema-change¶
Detects schema modifications.
Detection Patterns¶
ALTER TABLEMODIFY COLUMNRENAME COLUMNCHANGE COLUMN
Example¶
Result: ๐ก schema-change label applied
Combined Usage¶
Recommended Configuration¶
Outcome:
| SQL Operation | Labels Applied |
|---|---|
CREATE TABLE users |
migration, safe-migration |
DROP TABLE users |
migration, risky-migration |
ALTER TABLE users MODIFY email |
migration, schema-change |
INSERT INTO users ... |
migration, safe-migration |
Workflow Integration¶
jobs:
label:
uses: workflow-kit/pr-auto-labeler/.github/workflows/pr-auto-labeler.yml@latest
with:
enabled_rules: '["risky-migration"]'
require-dba-review:
needs: label
if: contains(github.event.pull_request.labels.*.name, 'risky-migration')
runs-on: ubuntu-latest
steps:
- name: Request DBA Review
run: echo "๐จ Risky migration detected - DBA review required"
Troubleshooting¶
Migration file not detected?
Check:
- File path includes
migrations/directory - File is actually changed in the PR diff
- Enable debug mode to see file analysis
Comments in SQL triggering false positives?
The rules ignore SQL comments:
-- single line comments/* block comments */
If you're seeing false positives, please report it.
Best Practices¶
Do's
โ
Always enable risky-migration for safety
โ
Combine with test-missing to ensure tests
โ
Use branch protection for risky migrations
โ
Document migration rollback procedures
Don'ts
โ Don't skip review for risky-migration
โ Don't run risky migrations in peak hours
โ Don't forget database backups
Related Rules¶
- test-missing ๐งช โ Ensure migrations have tests
- security-change ๐ โ Sensitive data access
- large-pr ๐ โ Large migration files