Gap Detection¶
Queen automatically detects missing migrations in your sequence.
What are Gaps?¶
Gaps occur when migration versions are not sequential:
Migration 002 is missing but migrations 003 and 004 are already applied.
Why Gaps Occur¶
- Parallel development - Two developers create migrations with the same version, branch merge causes renaming.
- Branch merges - Feature branch deployed before main branch migrations.
- Manual intervention - Migration applied manually but file never committed.
Why Gaps Matter¶
Migration 003 might depend on schema from 002. Missing migrations break the audit trail and can cause deployment failures.
Gap Types¶
Numbering Gaps¶
Missing version numbers in sequence:
Application Gaps¶
Registered migrations not yet applied while later ones are:
Unregistered Gaps¶
Migrations in database but not in code:
Detection¶
Library¶
gaps, err := q.DetectGaps(ctx)
if err != nil {
log.Fatal(err)
}
for _, gap := range gaps {
fmt.Printf("Gap: %s (type: %s)\n", gap.Version, gap.Type)
}
CLI¶
Output:
Gap Detection Report
Found 1 gap
Version: 002
Name: add_posts
Status: Not applied
Impact: 3 migrations applied after this gap
CI/CD Integration¶
Exit code 4 if gaps detected.
Resolving Gaps¶
Fill Gap¶
Apply the missing migration:
Mark as Applied¶
If migration was executed manually:
Records migration without executing SQL.
Ignore Gap¶
If gap is intentional:
Creates or updates .queenignore:
Batch Resolution¶
Resolution Strategy¶
- Resolve unregistered gaps first (ignore or recreate).
- Fill numbering gaps (create missing migrations).
- Apply application gaps.
Safe Resolution¶
# 1. Analyze impact
queen gap analyze
# 2. Backup
pg_dump mydb > backup.sql
# 4. Fill and verify
queen gap fill 003
queen status
Prevention¶
Use Timestamps¶
Avoid version conflicts in parallel development:
config := &queen.Config{
Naming: &queen.NamingConfig{
Pattern: queen.NamingPatternSequentialPadded,
Padding: 3,
Enforce: true,
},
}
Sequential padded versions (001, 002, ...) are less prone to conflicts than plain sequential ones. For timestamp-based versions, use sequential-padded with appropriate padding.