Skip to content

Adds migration fix script to flake - #764

Open
klautcomputing wants to merge 1 commit into
mainfrom
migration-hooks
Open

klautcomputing wants to merge 1 commit into
mainfrom
migration-hooks

Conversation

@klautcomputing

Copy link
Copy Markdown
Collaborator

@IongIer please take a look at this

@IongIer

IongIer commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

TLDR:

  1. Stop after any failed or unavailable rollback, including missing down.sql.
  2. Preserve an existing post-checkout hook.
  3. Compare migrations by Diesel’s numeric version, not directory name.
  4. Reject ambiguous down.sql candidates instead of choosing the first ref.
  5. Avoid installing a potentially GC-broken /nix/store symlink as the persistent hook.

As i don't know nix at all....BEEP BOOP I AM A ROBOT:

  • [P2] Stop reverting after a down migration fails — flake.nix:154-156
    When reverting multiple orphaned migrations, a failure here only emits a warning and the caller proceeds to
    older migrations. If a newer migration cannot be reverted but an older dependency can, the database is left
    with the newer migration applied while its prerequisite and ledger entry are removed. Propagate the failure
    and stop processing older migrations.

  • [P2] Preserve existing post-checkout hooks — flake.nix:313-314
    When a developer already has a post-checkout hook, ln -sf replaces it without warning, silently disabling any
    existing tooling attached to that hook. The installer should refuse installation, preserve and chain the
    existing hook, or use a hook-management mechanism rather than overwriting it.

  • [P2] Compare migrations by Diesel version, not directory name — flake.nix:184
    only_old compares full directory names, but Diesel identifies migrations solely by their numeric version. If
    a migration is renamed while retaining its timestamp/version—or two branches use different names for the same
    version—the hook treats the old directory as removed, executes its down.sql, and deletes the ledger row even
    though the new branch still contains that version.

  • [P2] Do not choose an arbitrary migration when versions collide — flake.nix:166
    locate() accepts the first branch or tag containing a requested version. Independent branches can contain
    different migrations with the same timestamp/version, so migration-fix may execute an unrelated down.sql. It
    should detect multiple distinct candidates and refuse or require an explicit choice.

There is also a lower-severity durability concern: flake.nix:314 is a symlink into /nix/store. It can become
broken after garbage collection or after the dev-shell generation changes because repository symlinks are not
Nix GC roots. This could be addressed alongside the existing “preserve existing hook” finding.

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.

2 participants