Skip to content

Migrations

Point migrations at a folder of .sql files. Each deploy runs the new ones, in order.

const db = yield* Turso.Database("Db", {
group: group.name,
migrations: "./migrations",
});
-- migrations/0001_users.sql
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL);

If any statement in a file fails, none of that file’s changes are kept and the deploy fails.

Alchemy keeps track of which files ran in the __alchemy_migrations table.

const schema = yield* Drizzle.Schema("Schema", {
schema: "./src/schema.ts",
out: "./migrations",
dialect: "sqlite",
});
const db = yield* Turso.Database("Db", {
group: group.name,
migrations: schema,
});

Drizzle.Schema writes a migration when src/schema.ts changes. Add Drizzle.providers() to your Stack and commit the ./migrations folder.

Rather run drizzle-kit generate yourself? Pass the folder instead: migrations: "./migrations".

Already used drizzle-kit on this database? Alchemy picks up its history on the first deploy.

migrations: { dir: "./migrations", table: "schema_migrations" },
const db = yield* Turso.Database("Db", {
group: group.name,
migrations: "./migrations",
importFiles: ["./seed/users.sql"],
});

importFiles run after migrations. A file runs again only if you change it.

Changing or deleting a file that already ran makes the deploy fail. Add a new file instead.