The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as FileSystem from "effect/FileSystem"; |
| 3 | import * as Path from "effect/Path"; |
| 4 | import { DrizzleV0LayoutError } from "./Format.ts"; |
| 5 | import { DRIZZLE_DIR_PATTERN } from "./Utils.ts"; |
| 6 | |
| 7 | /** |
| 8 | * The on-disk layout of a migrations directory. `directory` covers both |
| 9 | * drizzle-kit v1 and Prisma layouts (`<ts>_<name>/migration.sql` — records |
| 10 | * key by directory name); `flat` is plain `.sql` files (records key by file |
| 11 | * path). |
| 12 | */ |
| 13 | export type MigrationLayout = "directory" | "flat"; |
| 14 | |
| 15 | /** |
| 16 | * Fingerprint a migrations directory's layout to pick the record reader. |
| 17 | * |
| 18 | * A drizzle **v0** layout (`meta/_journal.json`) fails with a typed error: |
| 19 | * the fix (`drizzle-kit up`) is upstream of Alchemy. |
| 20 | */ |
| 21 | export const detectLayout = (dir: string) => |
| 22 | Effect.gen(function* () { |
| 23 | const fs = yield* FileSystem.FileSystem; |
| 24 | const path = yield* Path.Path; |
| 25 | const exists = (p: string) => fs.exists(p).pipe(Effect.orElseSucceed(() => false)); |
| 26 | |
| 27 | if (yield* exists(path.join(dir, "meta", "_journal.json"))) { |
| 28 | return yield* new DrizzleV0LayoutError({ |
| 29 | dir, |
| 30 | message: |
| 31 | `${dir} uses drizzle-kit's pre-v1 migration layout (meta/_journal.json). ` + |
| 32 | `Upgrade drizzle-kit and run "drizzle-kit up" to convert it, then redeploy.`, |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | const entries = yield* fs.readDirectory(dir).pipe(Effect.orElseSucceed(() => [] as string[])); |
| 37 | for (const entry of entries) { |
| 38 | if (!DRIZZLE_DIR_PATTERN.test(entry)) continue; |
| 39 | if (yield* exists(path.join(dir, entry, "migration.sql"))) { |
| 40 | return "directory" as const; |
| 41 | } |
| 42 | } |
| 43 | return "flat" as const; |
| 44 | }); |