refactor(relay): generate mysql migrations manually per the alchemy drizzle guide
alchemy's Drizzle.Schema auto-generation is Postgres-only (drizzle-kit has no programmatic mysql API), so follow the documented MySQL pattern: a drizzle.config.ts + `drizzle-kit generate`, with migrations checked in and the database/branch resources pointed at the static migrations/mysql dir. This also makes RelayMysqlDatabase's props identical to the provisioning PR, so the cutover deploy no-ops on the database itself. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
7d4b7d42b8
commit
b46842d790
3 files changed
+25
-14
No files matched your search
@@ -40,7 +40,9 @@ credential, or authorization behavior.
|
||||
APNs delivery, and queue processing.
|
||||
- [`src/auth`](./src/auth) contains relay token and DPoP proof handling.
|
||||
- [`src/persistence/schema.ts`](./src/persistence/schema.ts) defines persisted relay state. Keep
|
||||
schema and migration changes together.
|
||||
schema and migration changes together: after editing the schema, run
|
||||
`pnpm exec drizzle-kit generate` (see [`drizzle.config.ts`](./drizzle.config.ts)) and commit the
|
||||
new `migrations/mysql/` directory — MySQL migrations are generated manually, not by the deploy.
|
||||
|
||||
Shared request and response schemas live in
|
||||
[`packages/contracts/src/relay.ts`](../../packages/contracts/src/relay.ts). Shared client-side relay
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { defineConfig } from "drizzle-kit";
|
||||
|
||||
// MySQL migrations are generated manually and checked in (alchemy's
|
||||
// Drizzle.Schema auto-generation is Postgres-only). After changing
|
||||
// src/persistence/schema.ts run `pnpm exec drizzle-kit generate` and commit
|
||||
// the new migrations/mysql/<timestamp>_*/ directory; deploys apply it.
|
||||
export default defineConfig({
|
||||
schema: "./src/persistence/schema.ts",
|
||||
out: "./migrations/mysql",
|
||||
dialect: "mysql",
|
||||
});
|
||||
+11
-13
@@ -1,6 +1,5 @@
|
||||
import type { MysqlClient } from "@effect/sql-mysql2/MysqlClient";
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Drizzle from "alchemy/Drizzle";
|
||||
import * as Planetscale from "alchemy/Planetscale";
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as RemovalPolicy from "alchemy/RemovalPolicy";
|
||||
@@ -35,14 +34,14 @@ export class RelayTransactions extends Context.Service<
|
||||
);
|
||||
}
|
||||
|
||||
// Unlike Postgres, alchemy has no automatic Drizzle.Schema generation for
|
||||
// MySQL (drizzle-kit exposes no programmatic mysql API): migrations are
|
||||
// generated manually with `pnpm exec drizzle-kit generate` (drizzle.config.ts)
|
||||
// and checked in; deploys apply whatever is committed here.
|
||||
const mysqlMigrationsDir = "migrations/mysql";
|
||||
|
||||
export const PlanetscaleDatabase = Effect.gen(function* () {
|
||||
const { stage } = yield* Alchemy.Stack;
|
||||
const schema = yield* Drizzle.Schema("RelaySchema", {
|
||||
schema: "./src/persistence/schema.ts",
|
||||
out: "./migrations/mysql",
|
||||
dialect: "mysql",
|
||||
});
|
||||
|
||||
const mode = relayDatabaseMode(stage);
|
||||
|
||||
// The retired Postgres database stays in the stack (prod only) until the
|
||||
@@ -71,15 +70,14 @@ export const PlanetscaleDatabase = Effect.gen(function* () {
|
||||
|
||||
const database =
|
||||
mode === "shared-database"
|
||||
? // Same resource id as the provisioning PR that created this database
|
||||
// (with its baseline already applied) ahead of the cutover, so this
|
||||
// deploy is a plain update; only migrationsDir moves from the static
|
||||
// baseline dir to the schema resource for future schema evolution.
|
||||
? // Same resource + props as the provisioning PR that created this
|
||||
// database (with its baseline already applied) ahead of the cutover,
|
||||
// so this deploy no-ops on the database itself.
|
||||
yield* Planetscale.MySQLDatabase("RelayMysqlDatabase", {
|
||||
name: "t3coderelay-vitess",
|
||||
region: { slug: "us-west" },
|
||||
clusterSize: "PS_20",
|
||||
migrationsDir: schema.out,
|
||||
migrationsDir: mysqlMigrationsDir,
|
||||
migrationsTable: "relay_migrations",
|
||||
replicas: 2,
|
||||
}).pipe(RemovalPolicy.retain())
|
||||
@@ -91,7 +89,7 @@ export const PlanetscaleDatabase = Effect.gen(function* () {
|
||||
? yield* Planetscale.MySQLBranch("RelayMysqlBranch", {
|
||||
database,
|
||||
isProduction: false,
|
||||
migrationsDir: schema.out,
|
||||
migrationsDir: mysqlMigrationsDir,
|
||||
migrationsTable: "relay_migrations",
|
||||
})
|
||||
: undefined;
|
||||
|
||||
Reference in new issue
Block a user