Skip to content

fix(migrator): write SQLite applied_at in SQLite's format and rename the default database - #7

Merged
sthanikan2000 merged 1 commit into
mainfrom
fix/5-migrator-sqlite-time-and-defaults
Nov 27, 2026
Merged

sthanikan2000 merged 1 commit into
mainfrom
fix/5-migrator-sqlite-time-and-defaults

Conversation

@sthanikan2000

Copy link
Copy Markdown
Member

Summary

Fixes what the review of #2 found in the migrator, before migrator/v0.1.0 is tagged:

  • On SQLite, applied_at is written in a format SQLite's date functions can read.
  • The default SQLite path no longer names one deployment.
  • The texts that pointed to files outside this repo now link to the migrator README.

The new tests also turned up an older bug: generate failed when the migrations directory didn't exist. That's fixed too.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Other (please describe):

Changes Made

  • SQLite applied_at:
    • The command opens SQLite with modernc.org/sqlite, which stores a Go time.Time as 2026-11-27 04:41:16.449017 +0000 UTC. SQLite can't read that, so datetime(applied_at) was NULL.
    • apply now writes 2026-11-27 04:41:15.916498+00:00, SQLite's own format and the format agency's migrator wrote.
    • PostgreSQL still binds a time.Time into its TIMESTAMPTZ column, unchanged.
  • Default SQLite path: ./agency_applications.db becomes ./migrator.db (config.go and the README's defaults table).
  • Links:
    • The usage text pointed to backend/config.example.yaml; it now links to the README's Configuration section.
    • Each file generate writes pointed to docs/migrations.md; it now links to the README's Driver-specific SQL section.
  • generate and a missing directory:
    • Generate creates the migrations directory if it's missing, but its not-exist check used os.IsNotExist.
    • loadFiles wraps that error, and os.IsNotExist doesn't unwrap, so generate failed instead.
    • It now uses errors.Is(err, fs.ErrNotExist).

Testing

  • I have tested this change locally
  • I have added tests that prove my fix is effective or that my feature works
  • I have tested edge cases
  • All existing tests pass

New tests in migrator/migrator_test.go:

  • TestUp_SQLiteAppliedAtFormat:
    • the stored text parses with SQLite's layout and ends in +00:00
    • it lies within the test's time window
    • datetime(applied_at) is not NULL
    • appliedMigrations reads it back as the same time
  • TestAppliedMigrations_ReadsSQLiteFormat: a row in agency's format still reads back.
  • TestGenerate_WritesNextVersionWithStubs: next version, @UP/@DOWN stubs and the README link.
  • TestGenerate_CreatesDirAndStartsAtOne: fails without the errors.Is fix.

TestLoadConfig_Defaults expects ./migrator.db. make check and make test pass.

End to end, with the built binary and agency's on one SQLite file:

  • This binary applied 000001 and 000002 with CONFIG_PATH=/dev/null, creating ./migrator.db.
  • Agency's binary rolled back 000002 and applied it again.
  • Both rows are stored as …+00:00, and datetime() reads both.
  • status is identical from the two binaries.
  • generate into a missing directory creates it.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have checked that there are no merge conflicts

Related Issues

Closes #5. Related to #2 and OpenNSW/core#336.

Screenshots/Demo

N/A

Additional Notes

…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.
@sthanikan2000 sthanikan2000 added the bug Something isn't working label Nov 27, 2026
@sthanikan2000 sthanikan2000 self-assigned this Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 44f7992d-1fd0-4e38-a0a5-2d90bcbc1134
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sthanikan2000
sthanikan2000 merged commit 0061725 into main Nov 27, 2026
9 checks passed
@sthanikan2000
sthanikan2000 deleted the fix/5-migrator-sqlite-time-and-defaults branch November 27, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrator: fix the SQLite applied_at format, default path and links before v0.1.0

1 participant