Skip to content

v0.30.0 — migrations

Choose a tag to compare

@tshafer tshafer released this 10 Jul 21:32

Version your schema with a fluent builder + migrator:

const migrations: Migration[] = [{
  name: "01_create_users",
  up: (s) => s.createTable("users", (t) => {
    t.id();
    t.string("email").unique();
    t.boolean("active").default(true);
    t.timestamps();
  }),
  down: (s) => s.dropTable("users"),
}];

await new Migrator(connection, "postgres").up(migrations);   // idempotent
await new Migrator(connection, "postgres").down(migrations); // roll back last batch

Applied migrations are batch-tracked in a migrations table; SQL is dialect-aware (sqlite/mysql/postgres). See docs/migrations.md.