How to Prevent and Resolve Git Merge Conflicts in SQL Migrations
By Sharon Ben-Moshe · October 13, 2026 · 1 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Prevent and resolve Git merge conflicts in migration directories. Learn timestamp vs sequential numbering and branch collision mitigation strategies.
Quick answer
Git merge conflicts in SQL migrations occur when multiple developers concurrently create migration files with the same sequential version number (e.g. V004__add_users.sql). Prevent collisions by using UTC timestamp versioning (e.g., 20261013143000_name.sql), enforcing rebase checks in CI, and configuring migration runners (like Flyway, Liquibase, or Drizzle) to accept out-of-order execution in non-production environments.
FAQs
Why is timestamp versioning superior to integer versioning?
Timestamp versioning (`YYYYMMDDHHMMSS`) guarantees uniqueness across independent git feature branches. Two developers branching from main will never generate identical timestamps, eliminating file-name collision conflicts upon merge.
What is out-of-order migration execution?
Out-of-order execution allows a migration tool to apply Migration B even if Migration C was merged earlier. Flyway supports `outOfOrder=true`. In production, this should be used carefully to ensure schema dependencies are respected.
What should I do if a Git merge conflict corrupts the migration journal?
Never edit the production migration history table directly without team review. Resolve the git conflict by renaming the newer branch's migration to the latest timestamp, test locally against a clean database snapshot, and re-run.
How can CI prevent conflicting migrations?
Add a CI validation step that checks for duplicate version IDs or conflicting schema locks before approving pull requests.
Keep reading
SQL Query Optimization and Tuning: The End-to-End Practitioner's Guide
By Sharon Ben-Moshe · Oct 13, 2026
The definitive guide to SQL query optimization. Master EXPLAIN execution plans, SARGable predicates, covering indexes, and keyset cursor pagination.
Read postHow SQL Query Engines Actually Execute Queries: The Complete Lifecycle
By Sharon Ben-Moshe · Oct 13, 2026
Journey through the SQL query lifecycle. Explore lexical parsing, Abstract Syntax Trees, logical optimization, Cost-Based Optimizers, and Volcano execution.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.