Repository navigation
feat: list pending data migrations, run one by version, and mark repeatable ones - #6
Merged
Merged
Conversation
…le ones DataMigration.pending/2 lists the data migrations that have not run, oldest first. DataMigration.run/4 runs one by version and no other, returning an error and running nothing for a version no file has, a version two files share, or a one-shot data migration that has run. `use DataMigration, repeatable: true` marks one that run/4 may run again; everything else is one-shot. The test sandbox now runs in manual mode and stops each owner, so a migration a test runs no longer commits its schema_migrations row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st repos With the sandbox in manual mode, the lock held the test's connection in the process that called the migrator, and the migrator's task timed out waiting for it. The SQLite repo already had it off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dbernheisel
approved these changes
Sep 25, 2026
MySQL commits the open transaction on DDL, so the migrator's CREATE TABLE IF NOT EXISTS ended the test's sandbox and its rows committed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tw00
commented
Sep 25, 2026
| defmodule DataMigration.MixProject do | ||
| use Mix.Project | ||
| @version "0.1.2" | ||
| @version "0.2.0" |
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.
Moves what tv-labs/platform#10396 built inside Sauron into the library, per review there, and adds the one-shot/repeatable annotation.
Summary
DataMigration.pending(repo, paths)lists the data migrations that have not run, oldest first, as{version, name}. It readsschema_migrationswithout the migration lock and without creating the table.DataMigration.run(repo, version, paths, opts \\ [])runs that one data migration and no other. It runs nothing and returns{:error, :not_found}for a version no file has,{:error, :duplicate_version}for one two files share, and{:error, :already_applied}for a one-shot data migration that has run.optsgo toEcto.Migrator.up/4.use DataMigration, repeatable: truein place ofuse Ecto.Migrationmarks a data migrationrun/4may run again. Anything else, including a plainuse Ecto.Migration, is one-shot. Either kind is pending until it has run once. A rerun deletes the version'sschema_migrationsrow (the same deleteEcto.Migrator.down/4makes, without runningdown/0), then runsup/0. If that raises, the row stays deleted and the migration shows as pending.test_helper.exsputs the sandbox in manual mode, andConnCasestops its owner. In the default auto mode, a process a test starts (a LiveView, the migrator's task) took a connection of its own, and its writes committed. The Postgres, MySQL and MSSQL test repos now setmigration_lock: false, as the SQLite one already did: in manual mode the lock holds the test's connection while the migrator's task waits for it. Therun/4tests passskip_table_creation: true, since MySQL commits the open transaction on the migrator'sCREATE TABLE IF NOT EXISTS.unreleased, README section. Not published:./bin/release 0.1.2 0.2.0after merge fills in the date.The dashboard's "Migrate up" still runs a data migration once. Rerunning a repeatable one from the page can come later.
Evidence
mix test --warnings-as-errors(Elixir 1.18.4, OTP 27): 32 tests, 0 failures (22 before, 10 new) on SQLite and on Postgres (a local server on another port), each on several seeds. CI runs all four adapters and dialyzer: green on727aba7.mix testonmain, the localtest.dbkeeps the page test's99999999999999row inschema_migrations. On this branch it has 0 rows after a run, on SQLite and Postgres.mix compile --warnings-as-errors,mix format --check-formattedandmix dialyzer(0 errors) are clean. On Elixir 1.20 the only warnings are the existing HEEx ones inpage.ex:86andpage.ex:220.lib/data_migration.exwith its three repeatable shims marked: its data migration,Releaseand admin overview tests pass, 248/248.🤖 Generated with Claude Code