Upgrading from Badger SQL Migrate
Badger SQL Migrate (bsm, NuGet Badger.SqlMigrate, 0.3.0 and earlier) is now Badger Trek. Rename the project files, move each database's journal once, and keep the full history.
Badger Trek 0.4.0 is the same tool under a new name, and a clean break: it reads nothing Badger SQL Migrate wrote. The journal layout did not change, only its name, so nothing has to be redeployed. trek stops with this page's steps when it finds a bsm.yaml without a trek.yaml, or a database with a Badger SQL Migrate journal and no Badger Trek journal, instead of treating the database as empty.
1. Install Badger Trek
dotnet tool uninstall --global Badger.SqlMigrate
dotnet tool install --global Badger.Trek
With a local tool manifest, use dotnet tool uninstall Badger.SqlMigrate and dotnet tool install Badger.Trek; the command is dotnet trek. In pipelines, replace bsm with trek and rebuild bundles with trek bundle create.
2. Rename the project
git mv bsm.yaml trek.yaml
git mv bsm.plan trek.plan
| Badger SQL Migrate | Badger Trek |
|---|---|
bsm.yaml, bsm.plan | trek.yaml, trek.plan |
-- bsm:preprocess off, -- bsm:requires | -- trek:preprocess off, -- trek:requires |
{bsm.provider}, {bsm.version}, {bsm.schema} | {trek.provider}, {trek.version}, {trek.schema} |
BSM_* environment variables, ~/.bsm | TREK_*, ~/.trek (saved Entra sign-ins are not carried over: sign in again) |
Lint codes BSM001… | TREK001… |
Run trek plan check: the plan head is the same as before if only the files were renamed.
3. Move each database's journal
Badger SQL Migrate kept its journal in state schema bsm (tables bsm_* on SQLite); Badger Trek uses trek. Move it once per database, with the same rights a deploy has. trek prints the exact SQL for the database when it stops, and it never runs it itself:
SQL Server and Azure SQL
IF SCHEMA_ID(N'trek') IS NULL EXEC(N'CREATE SCHEMA [trek]');
ALTER SCHEMA [trek] TRANSFER [bsm].[meta];
ALTER SCHEMA [trek] TRANSFER [bsm].[changes];
ALTER SCHEMA [trek] TRANSFER [bsm].[repeatables];
ALTER SCHEMA [trek] TRANSFER [bsm].[events];
ALTER SCHEMA [trek] TRANSFER [bsm].[schema_snapshots];
DROP SCHEMA [bsm];
PostgreSQL
CREATE SCHEMA IF NOT EXISTS "trek";
ALTER TABLE "bsm".meta SET SCHEMA "trek";
ALTER TABLE "bsm".changes SET SCHEMA "trek";
ALTER TABLE "bsm".repeatables SET SCHEMA "trek";
ALTER TABLE "bsm".events SET SCHEMA "trek";
ALTER TABLE "bsm".schema_snapshots SET SCHEMA "trek";
DROP SCHEMA "bsm";
SQLite
ALTER TABLE bsm_meta RENAME TO trek_meta;
ALTER TABLE bsm_changes RENAME TO trek_changes;
ALTER TABLE bsm_repeatables RENAME TO trek_repeatables;
ALTER TABLE bsm_events RENAME TO trek_events;
ALTER TABLE bsm_schema_snapshots RENAME TO trek_schema_snapshots;
The final DROP SCHEMA fails if anything else is left in bsm, which is the point: nothing of yours is dropped. To leave the journal where it is instead, set stateSchema: bsm on each environment in trek.yaml (see Journal tables); trek then uses it as its own.
4. Check
trek status -e prod # up to date and certified, same head as before
trek verify -e prod # same schema fingerprint
trek log -e prod # the history from Badger SQL Migrate
Renaming -- bsm: directives or {bsm.*} variables inside changes that are already deployed changes their hashes, and trek reports them as edited after deployment. Those edits are harmless: accept them once with trek repair (see Fixing deployed changes). A repeatable whose text changed is simply applied again on the next deploy.