Migrations and templates

@exo/kit/migrate#

Exports: syncKitMigrations, checkKitMigrations, migrationVersion, migrateUpHalf. It also installs the command exo-kit-migrations.

Some kit modules need tables. The sign-in module needs account_sessions and the users.exo_sub column. The kit ships that SQL, and you copy it into your own migrations folder so that your migration tool (dbmate, or Prisma) can apply it with your own.

exo-kit-migrations sync  --dir apps/api/migrations/kit --signin
exo-kit-migrations check --dir apps/api/migrations/kit --signin
import { signinMigrations } from '@exo/kit/signin';
import { checkKitMigrations, syncKitMigrations } from '@exo/kit/migrate';

const options = { files: signinMigrations(), dir: 'apps/api/migrations/kit' };
syncKitMigrations(options);  // after a version bump; commit what it writes
checkKitMigrations(options); // in the build; { ok: false } should fail it
  • sync copies the files byte for byte. It never deletes a leftover file, because a file that was applied to a live database is not garbage.
  • check compares your copies with the installed package and reports missing, changed and extra. It exits with 1 on any difference and writes nothing. Run it in your image build so a stale copy cannot ship.
  • Kit file names start with 20200101. That is an ordering floor, so the kit's tables exist before your own migrations that build on them.
  • Each file has a -- migrate:up and a -- migrate:down block. The down block raises an error: kit migrations do not roll back.
  • For accounts in a schema other than public, add --no-auth --schema <name> to both commands.

Templates#

The package includes files that you copy, not code you import. A later version of the kit does not change a copy you already made.

FileWhat it is
templates/migrate.shA wrapper around dbmate for running migrations.
templates/docker/<form>/DockerfileSeven Dockerfile archetypes.
templates/docker/compose-service.ymlA compose service block.
FormDirectoryFor
F1static-nginxA static build behind an unprivileged nginx.
F2next-standaloneNext.js with standalone output.
F3node-apiA Node HTTP service in a pnpm monorepo, bundled with esbuild.
F4node-prismaNext.js or Node with Prisma.
F5node-workerA background Node process.
F6python-uvA Python service on uv.
F7python-wrapperA thin HTTP wrapper around a third-party Python tool.

The comments in these files explain why each non-obvious line exists. Keep them when you copy.