Skip to content

Skips V03's index rename on SQLite - #142

Merged
johnnyt merged 1 commit into
mainfrom
sr-zb9m-v03-on-sqlite
Sep 30, 2026
Merged

johnnyt merged 1 commit into
mainfrom
sr-zb9m-v03-on-sqlite

Conversation

@johnnyt

@johnnyt johnnyt commented Sep 30, 2026

Copy link
Copy Markdown
Member

Fixes migration V03 on SQLite. Refs sr-zb9m.

The bug

StatifierRouter.Migrations.V03 renames the subscription table's unique index with ALTER INDEX IF EXISTS ... RENAME TO ... in both directions, on every adapter. SQLite has no ALTER INDEX, so a SQLite host whose router migration walks through V03 (any uncapped StatifierRouter.Migrations.up/1) fails with a syntax error near "INDEX", from 0.8.0 on. V01 and V02 run on SQLite; the new test reproduces the failure on the base commit.

The fix

On Ecto.Adapters.SQLite3, V03.up/1 and V03.down/1 do nothing (the private rename_index/3 reads repo().__adapter__()). V03 exists to repair a name Postgres cut to 63 bytes; SQLite keeps an identifier whole, so there V02 already left the index under its whole 70-byte name and there is nothing to repair. The test reads that name back from sqlite_master after V02. The index keeps V02's name on SQLite; the package's queries name the index's columns, never its name (StatifierRouter.subscribe/3's conflict_target). Every other adapter runs exactly the statement it ran before, and the Postgres migration tests (StatifierRouter.IndexNamesTest, StatifierRouter.MigrationsTest) pass unchanged: neither file is in this diff.

Tests

  • test/support/sqlite_repo.ex: StatifierRouter.SQLiteRepo, an Ecto repo on Ecto.Adapters.SQLite3, started per test with a temporary database file.
  • test/statifier_router/sqlite_migrations_test.exs: V01 and V02, then V03 up and down, then V02 down, asserting the subscription index's name, uniqueness and column order after each step; and the uncapped up/1 and down/1 a host's first migration writes. Not :isolated: it never touches Postgres.

Sabotage, one row per check, each restored byte-equal from a copy before the next:

Mutation in v03.ex Result
the adapter check replaced by true (the old unconditional rename) both SQLite tests red on the V03 up assertion
down/1 running the ALTER INDEX directly both SQLite tests red on the down assertion
the check inverted (rename on SQLite only) IndexNamesTest red in three tests, both SQLite tests red

Dependencies

ecto_sqlite3 ~> 0.22, only: :test, beside postgrex. No runtime dependency changes. The whole mix.lock change is four added entries and nothing else moved: ecto_sqlite3 0.25.0, exqlite 0.41.0, elixir_make 0.10.0 and cc_precompiler 0.1.11.

Records and changelog

  • ADR-0007 gets a dated foot Note: its Note of 2026-09-27 says V03 renames with ALTER INDEX IF EXISTS, which no longer holds on SQLite. The Note decides nothing and removes no line (git diff origin/main -- docs/adr/ is additions only); each claim in it cites StatifierRouter.Migrations.V03 or the new test by name.
  • changelog.d/sr-zb9m.md under ### Fixed.

Provenance

One engineering choice: the rename is skipped on SQLite only, not run on Postgres only. SQLite is the adapter observed failing and checked to keep the name whole; on any other adapter the migration sends what it sent before, so nothing changes where nothing was checked.

Gate

Full mix quality on this head: Format, Compile, Isolated tests, Doc links, Dependencies, Credo, Docs, Tests (422 of 422 passed, 97.7% coverage) and Dialyzer all passed; Doctor, Gettext and Sobelow skipped as not installed.

StatifierRouter.Migrations.V03 renamed the subscription index with
ALTER INDEX IF EXISTS on every adapter. SQLite has no ALTER INDEX, so a
SQLite host whose router migration walks through V03 failed with a
syntax error near "INDEX" from 0.8.0 on.

On Ecto.Adapters.SQLite3 both directions now do nothing: SQLite keeps an
identifier whole, so V02's index there already holds its whole name and
there is no cut name to repair. Every other adapter runs the rename as
before; the Postgres migration tests pass unchanged.

Adds ecto_sqlite3 as a test-only dependency, a SQLite test repo and
StatifierRouter.SQLiteMigrationsTest, which walks V01 to V03 up and
down on SQLite and reads the index name back. ADR-0007 gets a dated
foot Note; a changelog fragment records the fix.

Refs: sr-zb9m
@johnnyt
johnnyt merged commit e5f4e26 into main Sep 30, 2026
1 check passed
@johnnyt
johnnyt deleted the sr-zb9m-v03-on-sqlite branch September 30, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant