← All decisions

Use Supabase CLI for migrations

accepted

0012 — Use Supabase CLI for migrations

Context

Phase 0 of ark shipped with a bespoke migration system: SQL files in platform/sql/NNN_*.sql, applied via a custom pnpm migrate:apply CLI that tracked applied migrations in a public.ark_migrations table. The CLI also exposed an applyMigrations(pool, sqlDir, { tracking }) library for the test harness.

This worked, but it duplicated infrastructure that Supabase already provides:

We initially set up ark-demo via the Supabase MCP apply_migration tool, which writes to schema_migrations correctly. So the project was already in good shape; the redundancy was on the local side — our custom CLI was tracking the same migrations a second time.

The question surfaced when the project owner noted: “I’ve used the Supabase CLI in another project — are we doing something different?” Yes; we shouldn’t be.

This decision is also a worked example of ADR 0011 applied to ourselves: don’t reinvent. Use the canonical tool.

Decision

Use the Supabase CLI for production migration application. Keep applyMigrations() as a hermetic test-harness primitive in @ark/db.

Concretely:

Consequences

Easier:

Harder:

Migration journey (what was done)

The repo’s history reflects the bespoke system through Phase 1.5a; this ADR (and its sibling commits) document the switch. For agents reading older sessions or stale memory:

Old (pre-ADR 0012)New
platform/sql/NNN_*.sqlsupabase/migrations/<ts>_<NNN>_<name>.sql
pnpm migrate:applysupabase db push --linked
public.ark_migrations (custom)supabase_migrations.schema_migrations (Supabase)
applyMigrations(pool, sqlDir, { tracking: true })(removed — production goes through CLI)
applyMigrations(pool, sqlDir)(kept — test harness only)
packages/db/src/migrate-cli.ts(removed)
packages/db/test/migrate-cli.spec.ts(removed)

Memory and docs that referenced the old paths have been updated to point at the new layout.

Alternatives considered

Trip-wires

We revisit this if: