Skip to content

Commit c074424

Browse files
d-csclaude
andcommitted
refactor(run-ops): migrate on a single RUN_OPS_DATABASE_URL
Drop the separate directUrl / RUN_OPS_DATABASE_DIRECT_URL. It was only consumed by `prisma migrate` (never the app runtime) to bypass a pooler for advisory locks — but the run-ops connection isn't wired to the app yet and the migration only needs one endpoint. Point RUN_OPS_DATABASE_URL at the direct DB endpoint and it's fully covered. A pooled/ direct split can be reintroduced with directUrl if the app ever connects via a pooler. Removes directUrl from the schema, the env.server.ts declaration, the .env.example line, the migrate runner's direct resolution, and the testcontainer helper's dead env var. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ffb2560 commit c074424

5 files changed

Lines changed: 7 additions & 21 deletions

File tree

.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ DIRECT_URL=${DATABASE_URL}
1010
# Dedicated run-ops database (@internal/run-ops-database). Only needed to run prisma commands
1111
# against it or to enable the run-ops split; start it with `docker compose --profile runops up`.
1212
RUN_OPS_DATABASE_URL=postgresql://postgres:postgres@localhost:5434/postgres?schema=public
13-
RUN_OPS_DATABASE_DIRECT_URL=${RUN_OPS_DATABASE_URL}
1413
REMIX_APP_PORT=3030
1514
# Dev-only: stream the webapp's logs over a local telnet/TCP socket (nc localhost 6767). Uncomment to enable.
1615
# WEBAPP_TELNET_LOGS_PORT=6767

apps/webapp/app/env.server.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,6 @@ const EnvironmentSchema = z
139139
.string()
140140
.refine(isValidDatabaseUrl, "RUN_OPS_DATABASE_URL is invalid")
141141
.optional(),
142-
// Direct/unpooled endpoint for the run-ops DB, consumed by the migration runner (poolers break
143-
// Prisma's advisory locks). Falls back to TASK_RUN_DATABASE_DIRECT_URL then the pooled URL.
144-
RUN_OPS_DATABASE_DIRECT_URL: z
145-
.string()
146-
.refine(isValidDatabaseUrl, "RUN_OPS_DATABASE_DIRECT_URL is invalid")
147-
.optional(),
148142
// The NEW dedicated run-ops DB writer. Optional so single-DB installs never set it.
149143
TASK_RUN_DATABASE_URL: z
150144
.string()

internal-packages/run-ops-database/prisma/schema.prisma

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
datasource db {
2-
provider = "postgresql"
3-
url = env("RUN_OPS_DATABASE_URL")
4-
directUrl = env("RUN_OPS_DATABASE_DIRECT_URL")
2+
provider = "postgresql"
3+
url = env("RUN_OPS_DATABASE_URL")
54
}
65

76
generator client {

internal-packages/run-ops-database/scripts/migrate.mjs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function readFromEnvFiles(key) {
3636
return undefined;
3737
}
3838

39-
// Expand `${VAR}` refs (e.g. the repo .env's RUN_OPS_DATABASE_DIRECT_URL=${RUN_OPS_DATABASE_URL});
40-
// our manual .env reader loads them literally, unlike Prisma's dotenv-expand.
39+
// Expand `${VAR}` refs in env-file values (our manual reader loads them literally, unlike Prisma's
40+
// dotenv-expand), so a `.env` like RUN_OPS_DATABASE_URL=${DATABASE_URL} still resolves.
4141
const expand = (value) =>
4242
value?.replace(/\$\{(\w+)\}/g, (_, k) => process.env[k] ?? readFromEnvFiles(k) ?? "");
4343
const resolveVar = (key) => expand(process.env[key] || readFromEnvFiles(key));
@@ -46,11 +46,6 @@ const redact = (url) => url.replace(/:\/\/[^@]*@/, "://***@");
4646
const subcommand = process.argv[2] === "status" ? "status" : "deploy";
4747

4848
const databaseUrl = resolveVar("RUN_OPS_DATABASE_URL") || resolveVar("TASK_RUN_DATABASE_URL");
49-
// Prefer the direct/unpooled endpoint for migrations (poolers break Prisma's advisory locks).
50-
const directUrl =
51-
resolveVar("RUN_OPS_DATABASE_DIRECT_URL") ||
52-
resolveVar("TASK_RUN_DATABASE_DIRECT_URL") ||
53-
databaseUrl;
5449

5550
if (!databaseUrl) {
5651
// Single-DB installs never set these — safe no-op. A genuinely-expected DB is gated on by the caller.
@@ -71,7 +66,6 @@ const result = spawnSync("prisma", ["migrate", subcommand, "--schema", "prisma/s
7166
env: {
7267
...process.env,
7368
RUN_OPS_DATABASE_URL: databaseUrl,
74-
RUN_OPS_DATABASE_DIRECT_URL: directUrl,
7569
},
7670
});
7771

internal-packages/testcontainers/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export async function pushDatabaseSchema(databaseUrl: string) {
3737

3838
/**
3939
* Pushes the DEDICATED run-ops subset schema (@internal/run-ops-database) into the database at
40-
* `databaseUrl`. The run-ops datasource reads RUN_OPS_DATABASE_URL/RUN_OPS_DATABASE_DIRECT_URL, and
41-
* its schema is a subset of the control-plane schema (run-ops tables, no Organization/Project/etc).
40+
* `databaseUrl`. The run-ops datasource reads RUN_OPS_DATABASE_URL, and its schema is a subset of
41+
* the control-plane schema (run-ops tables, no Organization/Project/etc).
4242
*/
4343
export async function pushRunOpsSchema(databaseUrl: string) {
4444
// Resolve the schema (and the package's own prisma binary) through the @internal/run-ops-database
@@ -49,7 +49,7 @@ export async function pushRunOpsSchema(databaseUrl: string) {
4949
const result = await pushPrismaSchema({
5050
prismaBin: `${runOpsPackagePath}/node_modules/.bin/prisma`,
5151
schemaPath,
52-
env: { RUN_OPS_DATABASE_URL: databaseUrl, RUN_OPS_DATABASE_DIRECT_URL: databaseUrl },
52+
env: { RUN_OPS_DATABASE_URL: databaseUrl },
5353
});
5454

5555
// `db push` derives DDL from the schema datamodel and so cannot create the SQL-only partial unique

0 commit comments

Comments
 (0)