Skip to content

Commit 4574411

Browse files
committed
feat: determine migrations folder based on env
1 parent ef7fbfe commit 4574411

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/api/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ FROM node:24-alpine
1818
RUN corepack enable pnpm
1919
WORKDIR /app
2020
COPY --from=builder /app .
21-
COPY --from=builder /build/packages/api/migrations /migrations
2221

2322
USER node
2423
EXPOSE 8080

packages/api/src/common/mongo.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from "node:path";
2-
import { fileURLToPath } from "node:url";
31
import { CollectionNotFoundError, DatabaseError } from "@nildb/common/errors";
42
import type { AppBindings, EnvVars } from "@nildb/env";
53
import type { UuidDto } from "@nillion/nildb-types";
@@ -82,15 +80,21 @@ export async function mongoMigrateUp(
8280
database: string,
8381
): Promise<void> {
8482
console.warn("! Database migration check");
85-
const __filename = fileURLToPath(import.meta.url);
86-
const __dirname = path.dirname(__filename);
83+
84+
// In dev: this file is at src/common/mongo.ts → ../../migrations
85+
// In prod: code is bundled to dist/main.js → ../migrations
86+
// Detect based on whether we're running from dist/ or src/
87+
const currentFileUrl = new URL(import.meta.url);
88+
const migrationsDir = currentFileUrl.pathname.includes("/dist/")
89+
? new URL("../migrations", import.meta.url).pathname
90+
: new URL("../../migrations", import.meta.url).pathname;
8791

8892
migrateMongo.config.set({
8993
mongodb: {
9094
url: uri,
9195
databaseName: database,
9296
},
93-
migrationsDir: path.join(__dirname, "../../migrations"),
97+
migrationsDir,
9498
changelogCollectionName: "_migrations",
9599
migrationFileExtension: ".mjs",
96100
useFileHash: true,

0 commit comments

Comments
 (0)