Repository navigation
fix(migrator): write SQLite applied_at in SQLite's format and rename the default database - #7
Merged
Conversation
…the default database modernc.org/sqlite writes a Go time.Time as "2006-01-02 15:04:05 +0000 UTC", which SQLite's date functions can't read, so datetime(applied_at) was NULL. apply writes SQLite's own format for the sqlite driver, as agency's migrator did; PostgreSQL still gets a time.Time. The default SQLite path is ./migrator.db, the usage text and each file generate writes link to the migrator README, and generate creates a missing migrations directory again: the not-exist check didn't see through the wrapped error from loadFiles.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
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.
Summary
Fixes what the review of #2 found in the migrator, before
migrator/v0.1.0is tagged:applied_atis written in a format SQLite's date functions can read.The new tests also turned up an older bug:
generatefailed when the migrations directory didn't exist. That's fixed too.Type of Change
Changes Made
applied_at:time.Timeas2026-11-27 04:41:16.449017 +0000 UTC. SQLite can't read that, sodatetime(applied_at)was NULL.applynow writes2026-11-27 04:41:15.916498+00:00, SQLite's own format and the format agency's migrator wrote.time.Timeinto itsTIMESTAMPTZcolumn, unchanged../agency_applications.dbbecomes./migrator.db(config.goand the README's defaults table).backend/config.example.yaml; it now links to the README's Configuration section.generatewrites pointed todocs/migrations.md; it now links to the README's Driver-specific SQL section.generateand a missing directory:Generatecreates the migrations directory if it's missing, but its not-exist check usedos.IsNotExist.loadFileswraps that error, andos.IsNotExistdoesn't unwrap, sogeneratefailed instead.errors.Is(err, fs.ErrNotExist).Testing
New tests in
migrator/migrator_test.go:TestUp_SQLiteAppliedAtFormat:+00:00datetime(applied_at)is not NULLappliedMigrationsreads it back as the same timeTestAppliedMigrations_ReadsSQLiteFormat: a row in agency's format still reads back.TestGenerate_WritesNextVersionWithStubs: next version,@UP/@DOWNstubs and the README link.TestGenerate_CreatesDirAndStartsAtOne: fails without theerrors.Isfix.TestLoadConfig_Defaultsexpects./migrator.db.make checkandmake testpass.End to end, with the built binary and agency's on one SQLite file:
CONFIG_PATH=/dev/null, creating./migrator.db.…+00:00, anddatetime()reads both.statusis identical from the two binaries.generateinto a missing directory creates it.Checklist
Related Issues
Closes #5. Related to #2 and OpenNSW/core#336.
Screenshots/Demo
N/A
Additional Notes
migrator/v0.1.0. No release has./agency_applications.dbas its default. TNSW uses PostgreSQL and sets its config, so it isn't affected.hostthat is an IPv6 literal, such as::1, gives an invalid address. That comes fromcore/databaseand is tracked in database: PostgreSQL DSN breaks IPv6 hosts and Validate accepts out-of-range ports core#336.