Skip to content

Preview databases

Give every pull request a copy of your staging database. Each preview gets real data to test with, and is deleted when you’re done.

import * as Alchemy from "alchemy";
const { stage } = yield* Alchemy.Stack;
const preview = stage.startsWith("pr-");
const group = preview
? yield* Turso.Group.ref("Group", { stage: "staging" })
: yield* Turso.Group("Group", { location: "aws-us-east-1" });

Turso.Group.ref uses the group from the staging stage. Previews never create or delete it.

const source = preview ? yield* Turso.Database.ref("Db", { stage: "staging" }) : undefined;
const db = yield* Turso.Database("Db", {
group: group.name,
seed: source ? { type: "database", name: source.name } : undefined,
migrations: "./migrations",
});

Each preview gets its own copy of staging’s database, then runs any new migrations from the pull request.

Terminal window
alchemy destroy --stage pr-42

This deletes the preview’s database. Staging’s group and database stay.