Fix handling of executed migrations with the withDatetimeMicroseconds driver option - #67
Merged
Merged
Conversation
The Migrator cannot resolve executed migrations when the driver is configured with withDatetimeMicroseconds: fetchMigrationData() compares created_at against a string formatted without microseconds, while the inserted value is formatted by the driver with them. Fails on SQLite (text comparison) and SQL Server (DATETIME rejects 6 fractional digits on insert); MySQL and Postgres pass. See #66 Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Pass created_at to the WHERE clause as a DateTimeInterface instead of a pre-formatted string, so the driver formats it the same way as on insert. A string formatted without microseconds never matches the stored value on SQLite, where datetime comparison is textual. Fixes #66 Assisted-By: Claude Fable 5 <noreply@anthropic.com>
On SQL Server the legacy DATETIME type rejects values with six fractional digits, so inserting into the migration table fails when the driver is configured with withDatetimeMicroseconds. datetime(6) maps to datetime2(6) there and keeps the other drivers' behavior intact. isConfigured() now also compares the existing table with the declared schema, so tables created by previous versions are upgraded on configure(). The comparison is driver-aware for free: SQL Server and Postgres detect the precision change and alter once; MySQL and SQLite exclude size from column comparison, keep their old columns and work either way. Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.x #67 +/- ##
============================================
+ Coverage 95.29% 95.33% +0.04%
- Complexity 248 250 +2
============================================
Files 30 30
Lines 786 793 +7
============================================
+ Hits 749 756 +7
Misses 37 37 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 What was changed
Migrator::fetchMigrationData()passescreated_atto theWHEREclause as aDateTimeInterfaceinstead of a pre-formatted string, so the driver formats it exactly as it did on insert. Previously, withwithDatetimeMicrosecondsenabled, the stored value (...12:30:45.000000) never matched the lookup string (...12:30:45) on SQLite, so executed migrations were resolved as pending and re-run.datetime(6). On SQL Server the legacyDATETIMEtype rejects values with six fractional digits, so with the option enabled even the bookkeeping insert failed;datetime2(6)accepts them.isConfigured()additionally compares the existing migration table with the declared schema, so tables created by previous versions are upgraded onconfigure().How it works
configure()alters the table once; the check then passes.Review notes
Checklist