Coming from another migration tool
Optional: hand this page to your coding agentThe steps work by hand too.Show the whole prompt
Move this repository's database migrations from the tool it uses now to SQL Yodeler, following https://intentius.io/sql-yodeler/from-other-tools/.
Make the project from the starter template, move the old migration files out of migrations/, and ask me before running `YODEL_ROLE=writer npx yodel init --from <env> --force` against the environment I name: it writes one row to that environment's history.
Leave the old tool's history table in the database.
Open a pull request with src/, the baseline migration, the config and the pipelines, with the old tool's migration jobs removed and listed in its description.
Never run `yodel apply` against a shared environment, never run `chant approve`, `yodel approve` or `yodel override`, never edit the `chant/lifecycle` branch or `.chant/allowed_signers`, never merge; approvals and applies belong to people.This page is for a database that golang-migrate, goose, Flyway or dbmate manages today. It starts with trying yodel on your pull requests while you keep your tool, then maps their concepts onto SQL Yodeler’s, takes the database into versioned migrations with its current schema as the starting point, and says how rollback works.
Try it without switching
Section titled “Try it without switching”yodel check reads your tool’s migrations directory and lints the migrations a pull request adds. Your tool keeps applying them; yodel applies nothing to any environment.
For each pull request it:
- Runs every migration in your tool’s order into a throwaway database: the emulator on your machine, a container in CI.
- Reads the schema the migrations already on
mainleave, then the schema after each new one. - Classifies each new migration’s change the way yodel classifies its own: a drop that removes data, a Postgres statement that rewrites a table or blocks writes while an index builds, a constraint that can fail on the rows already there, a ClickHouse mutation that rewrites parts. Every yodel lint rule runs on it, your own column rules included.
A finding points at the migration file and the statement’s line, so the forge shows it on the pull request.
What it reads from each tool, the up direction only:
| Tool | Files | What is read |
|---|---|---|
| golang-migrate | <version>_<title>.up.sql in the directory |
the whole file, by version; .down.sql files are not read |
| goose | <version>_<name>.sql in the directory |
the -- +goose Up section, by version. A -- +goose StatementBegin … StatementEnd block is one statement. Go migrations are refused, since their code is not SQL |
| Flyway | V<version>__<description>.sql, B<version>__<description>.sql and R__<description>.sql in every location, subfolders included |
the newest B__ baseline first, when there is one, then the versioned files after its version by version (1.10 after 1.9), then the repeatable ones by description, with placeholders substituted. Undo files and callbacks (beforeMigrate.sql, afterEachMigrate__notify.sql, …) are not read. Java and Kotlin migrations are refused, naming each one |
| dbmate | <version>_<name>.sql in the directory |
the -- migrate:up section, by version |
For Flyway, yodel check reads the first flyway.toml, else flyway.conf, in the directory it checks or a directory above it, up to the project’s:
locations, relative to the configuration file.filesystem:<path>is that directory;classpath:<path>issrc/main/resources/<path>, and its code migrations would be insrc/main/java/<path>orsrc/main/kotlin/<path>. With no locations, the directory checked is the one location.- Placeholders:
flyway.placeholders.<name>inflyway.conf,[flyway.placeholders]inflyway.toml, withplaceholderPrefix,placeholderSuffixandplaceholderReplacement. Flyway’s own work too:${flyway:defaultSchema}isdefaultSchema, else the first ofschemas, else the replay profile’s schema;${flyway:database}comes fromurl;${flyway:user},${flyway:table},${flyway:filename},${flyway:timestamp},${flyway:workingDirectory}and${flyway:environment}as Flyway sets them. A placeholder with no value fails the check, naming the file and line. - In
flyway.toml, the[environments.<name>]that[flyway] environmentnames (defaultwhen it names none) givesurl,userandschemas. sqlMigrationPrefix,repeatableSqlMigrationPrefix,baselineMigrationPrefix,sqlMigrationSeparatorandsqlMigrationSuffixeswhen they are set.
Two migrations of one version (1 and 1.0 included) fail the check, as they fail Flyway.
Set it up
Section titled “Set it up”The project is a chant.config.ts with one profile, replay, for the throwaway database, and a yodel.config.ts naming your directory. The profile’s schemas (Postgres) or databases (ClickHouse) are the ones your migrations create objects in; yodel check empties them before and after each run.
import type { ChantConfig } from "@intentius/chant/config";import "@intentius/chant-lexicon-sql";
export default { lexicons: ["sql"], sql: { dialect: "postgres", profiles: { replay: { url: process.env.REPLAY_POSTGRES_URL ?? "postgres://127.0.0.1:5432/postgres", user: { env: "REPLAY_POSTGRES_USER" }, password: { env: "REPLAY_POSTGRES_PASSWORD" }, schemas: ["app"], }, }, },} satisfies ChantConfig;export default { check: { dir: "db/migrations", tool: "goose" } };tool is optional: yodel tells the four apart by their file names and markers. On your machine, with the emulator running (npx yodel emulator up):
npx yodel check --base main--base picks the new migrations: the files added or changed since that commit. --all lints every migration.
On every pull request
Section titled “On every pull request”npx yodel ci renders one pull request job for GitHub Actions, GitLab CI and Forgejo Actions. It starts a throwaway database as a service and runs yodel check against it, with the findings annotated on the migration files. No job reads or writes one of your environments, so it needs no secrets.
Silencing a finding
Section titled “Silencing a finding”A line in the migration file silences one rule for that file, with a reason:
-- +goose Up-- yodel:allow destructive nickname was never readALTER TABLE app.users DROP COLUMN nickname;Moving over
Section titled “Moving over”When yodel’s findings are what you want on every change, take the database into yodel’s own migrations: the rest of this page.
The concepts, side by side
Section titled “The concepts, side by side”The main difference in day-to-day work: yodel writes the schema’s SQL. You change the declared schema in src/ (chant’s sql lexicon), and yodel new <name> writes the migration from the difference between that and the schema the previous migration recorded. What the declared schema does not say, such as reference rows or a data fix, you write yourself in a hand-written migration, yodel new <name> --sql (Hand-written migrations). Before it is applied anywhere you can still change a statement by hand: edit it in migration.json, which is what apply runs, and the same text in migration.sql (lint checks the two match); yodel lint --update-checksum <id> then records the new checksum.
| In golang-migrate, goose, Flyway, dbmate | In SQL Yodeler |
|---|---|
An up file: 1_add_note.up.sql, V2__add_note.sql, a -- +goose Up or -- migrate:up section |
A directory, migrations/<YYYYMMDDTHHMM>-<name>/, with migration.sql (the statements) and migration.json (its parent, its checksum, its steps and the schema as it stands after it). yodel new <name> writes it. See Migrations. |
| An up file you write by hand: data, reference rows, a statement the tool would not generate | A hand-written migration: yodel new <name> --sql, then your statements in its migration.sql, recorded with yodel lint --update-checksum <id>. It is planned, approved, applied and resumed like any other (Hand-written migrations). |
A down file, -- +goose Down, -- migrate:down, flyway undo |
No down files. yodel revert <env> <id> plans the reverse from the recorded schemas when you need it (below). |
| The order: the version number or timestamp in the file name | Each migration names its parent; the chain of parents is the order. The timestamp in the id is for people and never decides the order. |
schema_migrations (version, dirty), goose_db_version, flyway_schema_history |
<history>.history, in a database (ClickHouse) or schema (Postgres) of its own, yodeler by default. It is append-only: one row per event (a migration or statement started, succeeded, failed), with who ran it and under which approval. See The history table. |
migrate version, goose status, flyway info, dbmate status |
yodel status <env>: applied, pending, failed part way, out of order, checksum mismatches. |
golang-migrate’s dirty flag and migrate force; a failed row in flyway_schema_history |
A migration that failed part way. The history records each statement, so the next yodel apply resumes at the statement that failed and never sends again one that succeeded. There is nothing to force. See Resuming. |
flyway validate |
yodel status and yodel apply check every applied migration’s files against the checksum recorded when it ran, and refuse on a mismatch; yodel lint checks each migration’s own checksum field. |
flyway repair |
yodel repair <env> <id> --reason "<text>" records a new checksum for an applied migration whose files were edited on purpose, with the reason. Nothing runs on the server. It does not clear failures: a failed migration resumes instead. |
baseline, baselineOnMigrate |
yodel init --from <env>: reads the live database into declarations, writes a baseline migration whose statements create all of it, and records it applied without running it. See Adopting it. |
outOfOrder=true, goose’s --allow-missing |
yodel apply <env> --allow-out-of-order, for one run. Without it, a pending migration the chain puts before an applied one is refused (exit 1), never skipped. See Out-of-order migrations. |
Flyway’s repeatable migrations (R__) for views and functions |
Views, functions, procedures and triggers are declared in src/ like tables. A changed body becomes a CREATE OR REPLACE in the next migration (Postgres objects). |
| goose’s Go migrations, Flyway’s Java migrations: code that moves data | Steps inside a migration: a backfill (yodel new <name> --backfill <file>), a ClickHouse rebuild, a Postgres expand-and-contract change. They resume from their receipts. See Data migrations. |
Flyway callbacks (beforeMigrate, afterMigrate) |
environments.<env>.steps in yodel.config.ts: read-only checks and commands before and after each apply (Steps around apply). |
dbmate’s schema.sql dump |
Each migration.json records the schema after it, and src/ declares the current one. yodel docs writes an HTML reference and an ERD (Generated schema reference). |
| Squashing old migrations into one | yodel checkpoint <name>: new environments start from it instead of replaying the whole chain (Checkpoints). |
migrate up / flyway migrate in a deploy job |
yodel apply <env> in the pipelines yodel ci renders: the plan is posted on the pull request, and the apply after a merge waits for an approval bound to a digest of that plan (Approval). |
| Tests that run the migrations on a fresh database | yodel test: cases in tests/*.test.ts, run on a database built from the migrations (Lint). |
Adopting the database
Section titled “Adopting the database”Adoption keeps the database as it is. The migrations the old tool ran are not imported one by one: the schema they produced becomes the baseline, the first migration of the new chain, recorded as applied without running.
Before you start
Section titled “Before you start”- Stop the old tool’s migration jobs for the environment, and apply whatever the old tool still has pending, so the database holds the schema you mean to keep. A migration the old tool runs after the baseline is recorded changes the database behind yodel’s back:
yodel driftreports a declared object it changed or dropped, and a table it created stays undeclared. - Decide which environment to adopt with
yodel init --from, usually production. The others that hold the same schema take the baseline afterwards withyodel init --baseline(see More than one environment). - Have the writer’s credentials for it.
initreads the database and then writes one row to the history (creating the history’s database or schema and table first, when they are not there), so the user needs to create those: on ClickHouse,CREATE DATABASE(or an existing history database it can create tables in); on Postgres,CREATEon the database. A read-only user fails at that write. The plan check before it only reads.
The project
Section titled “The project”yodel init needs a project around it: chant.config.ts with a profile for the environment, yodel.config.ts, a migrations Op, and a package.json from which chant and the sql lexicon resolve. It does not write these. The quickest way to get them is a starter template, made with yodel create and the database (ClickHouse) or schema (Postgres) you already have:
npx @intentius/sql-yodeler@latest create events-schema --clickhouse --database eventsnpx @intentius/sql-yodeler@latest create app-schema --postgres --schema appcd app-schema && npm installThe history goes in its own database or schema (--history <name> on yodel create, yodeler by default); it must not be one of the project’s. When the project owns more than one database or schema, list each in databases (ClickHouse) or schemas (Postgres) of every profile in chant.config.ts. Starting a project has the rest of what the template writes.
Moving the old tool’s files
Section titled “Moving the old tool’s files”yodel’s migrations live in migrations/ at the project root, and the name is fixed. Move the old tool’s files out of it before you run init (for example to legacy-migrations/, or delete them and let git keep them). init refuses while migrations/ holds any subdirectory, and yodel never reads the old files: flat .sql files left there are ignored, which only confuses whoever reads the directory later.
Running init
Section titled “Running init”Point the environment at the database (in the templates, <ENV>_CLICKHOUSE_URL or <ENV>_POSTGRES_URL, and the writer’s user and password variables), then:
YODEL_ROLE=writer:prod npx yodel init --from prod --forceYODEL_ROLE=writer:prodmakes the template’schant.config.tsread the writer’s variables. Without it the template reads the reader’s, which its README creates read-only.--forceis needed because the template’ssrc/schema.tsis a placeholder schema, andinitrefuses to write over declarations without it:refused: src already declares a schema (schema.ts) ... Pass --force to overwrite. The import writessrc/schema.ts; any other file insrc/is kept and built with it, so remove files that declare objects the database does not have.
What init does, step by step, and what it refuses, is in Adopting an existing database. Afterwards npx yodel plan prod shows no change and npx yodel status prod lists the baseline applied. Commit src/, the baseline and the project.
The old tool’s history table
Section titled “The old tool’s history table”init leaves the old tool’s history table out of the declared schema, with a warning such as app.schema_migrations is kept by a migration runner (Rails, golang-migrate, dbmate); left out, since declaring it would have chant change what that tool owns. It does this on both dialects for the tables chant knows by name: schema_migrations, goose_db_version, flyway_schema_history, and those of Prisma, Rails, Django, Alembic, drizzle-kit, Knex, Sequelize and node-pg-migrate. (Flyway keeps its table under a configurable name; one under another name is adopted like any other table.)
From then on yodel never reads it or writes to it: migrations are written from the declared schema, and drift reports only declared objects. Keep it while you might go back to the old tool, and drop it by hand once nothing runs the old tool. Its rows changing does not move a plan’s digest; creating or dropping the table in one of the project’s databases or schemas does, so drop it between applies, not while an approved plan is waiting.
Tables the project should not own
Section titled “Tables the project should not own”There is no exclude list. The scope is the databases (ClickHouse) or schemas (Postgres) the profile lists: init adopts every object in them except the history tables above, and nothing outside them. To keep a table out of the project (a table another service owns, a scratch table), keep it in a database or schema the profile does not list. Deleting a table’s declaration after init does not undeclare it: the baseline recorded it, so the next yodel new writes a DROP TABLE, which yodel lint flags as destructive.
An undeclared object in a listed database or schema (one created after init) is left alone: migrations are written from the declarations, and drift does not report it. Creating or dropping one does move the plan digest, since the digest covers the catalog of those databases or schemas.
More than one environment
Section titled “More than one environment”Once migrations/ holds the baseline, init --from refuses in that project, so it records the baseline in one environment. An environment that does not hold the schema yet, or one you can empty first (a dev or CI database), starts with an empty history, and yodel apply runs the baseline there, which creates everything. An environment that already holds the schema and its data takes it with yodel init --baseline <env>: it compares that environment’s live schema with the schema the baseline records, refuses and names each difference when they differ, and otherwise records the baseline applied there, without running it, behind the environment’s gate (Another environment that already holds the schema). Stop the old tool in that environment first too, and bring it to the same schema as the adopted one.
Cutting CI over
Section titled “Cutting CI over”The template renders pipelines for GitHub Actions, GitLab CI and Forgejo Actions (npm run ci, which is yodel ci): lint and a plan comment on each pull request with the reader’s credentials, and on a merge, an apply per environment with the writer’s, behind its approval. Create the users the template’s README lists and the secrets Setting up each forge places, remove the old tool’s migration jobs in the same pull request that adds these, and from then on make each change by editing src/ and running yodel new <name>. The two workflows has the details.
Rolling back
Section titled “Rolling back”There are no down migrations to write or keep in step with the up ones. Each migration records the schema after it, and its parent records the schema before it, so yodel can plan the reverse when you ask for it.
Reverting the newest migration
Section titled “Reverting the newest migration”npx yodel revert prod <id> --dry-run # the reverse statements, each with its rule and class, and the digestYODEL_ROLE=writer:prod npx yodel revert prod <id>yodel revert undoes the newest migration applied in the environment, and only that one, since any later migration was written against it. It goes through the migrations Op like an apply: it stops at the gate with the approve command (exit 3), and once approved, the next yodel revert runs it under the lock. The policy in yodel.config.ts judges its statements, so a rule that refuses drops refuses a revert that drops what the migration added unless an override is recorded. The history gets a row for each reverse statement and a reverted row; the migration is then pending again, and yodel status marks it reverted. Delete it, or rewrite it with yodel new <name> --replace, before the next yodel apply, which would otherwise apply it again.
A revert carries the schema back, not the data. A dropped column comes back empty, and a revert that drops a column the migration added loses what was written to it since. Reverting the baseline plans the drop of everything it created.
When a hand-written step is needed
Section titled “When a hand-written step is needed”- The migration has a data step (a backfill). The revert is refused (exit 3) until
--step <file>names SQL that undoes the data step; it runs before the reverse statements and is part of the digest. - The reverse would need an Op or a manual step (a ClickHouse sort key changed back, a Postgres column renamed back). The revert is refused (exit 3). Write the change back as a new migration: edit
src/, thenyodel new <name>. - The migration is not the newest applied one, or other environments have moved on from it. Roll forward the same way: a new migration that undoes it.
A migration that failed part way
Section titled “A migration that failed part way”It is not rolled back. Statements that succeeded stay, and the next yodel apply resumes at the one that failed. Fix the cause on the server (the row a constraint rejects, a lock someone holds), or edit that statement in migration.json and migration.sql and record the files’ new checksum with yodel lint --update-checksum <id>; then approve and apply again. yodel repair is for a migration that applied completely and whose files were edited afterwards; it refuses one that failed part way. On Postgres, each statement that can run in a transaction runs in its own, so a failed statement leaves nothing half done.
Proven by
Section titled “Proven by”The scenario claims below run what this page describes against a real server, once plain (it passes) and once with the behaviour broken (the claim catches it). Claims status lists every claim.
| Claim | What it says | Plain, broken | Last run |
|---|---|---|---|
declarative |
the declarative path: yodel plan shows the change against the live server and yodel apply makes it behind the plan-bound gate, for src/ declarations (on Postgres, functions, procedures and triggers, and access control: a role, a policy and grants, with a grant made by hand revoked; on ClickHouse, a dictionary, a function, and access control: a role, a user, a row policy and grants, with a grant made by hand revoked) and for an ORM’s exported DDL; a pull request on that path gets lint over the planned changes and the plan comment with them, and a policy rule at the base commit that denies the plan refuses yodel apply before the gate; yodel drift reports a declared object changed out of band, naming the property, a column added to it by hand, and one dropped; on the versioned path it compares with the newest applied migration’s recorded schema, so a pending migration is not drift; yodel init –from adopts a live database without touching it, and yodel plan then shows no change; on Postgres its policies, row-level security and grants too, on ClickHouse its dictionaries, functions, roles, users, row policies and grants; it refuses a database holding an object of a kind it cannot declare, naming it; yodel init –baseline records the baseline, behind the gate, in a second environment that holds the same schema, and refuses one that differs | ClickHouse: pass, caught; Postgres: pass, caught | 821d93b, 2026-11-03 |
resume |
an interrupted apply resumes where it stopped: a backfill step written as yodel’s form (table, key, batch size, SQL) from its receipts, running each batch once, and a failed statement at that statement, never resending one that ran; Postgres: a column rename runs as a PostgresMigrationOp step (expand, backfill, switch, contract) and keeps every value; a step that fails part way keeps its work and resumes from its receipts; Postgres: a statement blocked behind another session’s lock times out at lock_timeout and is retried until it succeeds; Postgres and ClickHouse with Keeper: two applies at once never send a statement twice, the second waits naming the holder, and –stand-down steps aside for a newer commit | ClickHouse: pass, caught; Postgres: pass, caught | 821d93b, 2026-11-03 |
migrations |
yodel new writes the next migration offline, with no dev database, and it applies; on Postgres, functions, procedures and triggers too, which lint checks; yodel new –sql writes a migration a person writes; its reference rows and a column declared in src/ too are recorded from migration.sql, replay to the schema it records, apply behind the gate, and the next yodel new diffs from it; yodel lint –replay replays the migrations into a fresh database and each gives the schema it recorded; offline, yodel lint fails a migrations directory with a fork (exit 1), naming both migrations; a checkpoint replays alone to its recorded schema, and a fresh environment starts from it; yodel revert undoes the newest migration behind the gate, with a hand-written step for its data step, back to its parent’s recorded schema, and refuses a checkpoint or a migration before one; yodel test runs a project’s tests on databases replayed from the migrations, a seed meeting the backfill after it, fails a case whose assertion does not hold, and refuses an environment with a history; on Postgres, a unique index over rows with duplicates is refused before the gate by its generated pre-check (exit 1, naming the statement and the count), and yodel lint flags it as data-dependent; a project’s own column rule from chant.config.ts lint.policies fails yodel lint on the migration that breaks it, and a yodel:allow line silences it; yodel check runs a goose directory’s migrations into a throwaway schema and fails the one a pull request adds when it drops a column, on that file’s line; a yodel:allow line in the file silences it; a migration merged late, before one already applied, is refused unless –allow-out-of-order, and never skipped | ClickHouse: pass, caught; Postgres: pass, caught | 821d93b, 2026-11-03 |
