| 1 | import * as Cloudflare from "@/Cloudflare/index.ts"; |
| 2 | import * as Drizzle from "@/Drizzle/index.ts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | |
| 5 | /** |
| 6 | * The full deploy-time Drizzle flywheel on D1: |
| 7 | * |
| 8 | * 1. `Drizzle.Schema` diffs `drizzle-schema.ts` against the checked-in |
| 9 | * snapshot under `drizzle-migrations/` and regenerates SQL on drift |
| 10 | * (no drift in CI — the initial migration is checked in). |
| 11 | * 2. `Cloudflare.D1.Database` detects the drizzle-kit layout and applies |
| 12 | * pending migrations through drizzle-orm's own migrator, tracked in |
| 13 | * the `drizzle_migrations` table (a custom-table override of drizzle's |
| 14 | * default `__drizzle_migrations`). |
| 15 | * |
| 16 | * Paths are relative to the test cwd (`packages/alchemy`). |
| 17 | */ |
| 18 | export const DrizzleDb = Effect.gen(function* () { |
| 19 | const schema = yield* Drizzle.Schema("d1-drizzle-schema", { |
| 20 | schema: "./test/Cloudflare/D1/fixtures/drizzle-schema.ts", |
| 21 | out: "./test/Cloudflare/D1/fixtures/drizzle-migrations", |
| 22 | dialect: "sqlite", |
| 23 | }); |
| 24 | |
| 25 | return yield* Cloudflare.D1.Database("D1DrizzleDatabase", { |
| 26 | migrations: { dir: schema.out, table: "drizzle_migrations" }, |
| 27 | }); |
| 28 | }); |