Skip to content

Commit ea63268

Browse files
committed
feat(server): run database migrations on startup
1 parent 538e449 commit ea63268

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

apps/server/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ENV NODE_ENV=production
2222
COPY --from=builder /app/apps/server/dist ./apps/server/dist
2323
COPY --from=builder /app/node_modules ./node_modules
2424
COPY --from=builder /app/apps/server/node_modules ./apps/server/node_modules
25+
COPY --from=builder /app/packages/db/src/migrations ./packages/db/src/migrations
2526

2627
EXPOSE 3000
2728
CMD ["node", "apps/server/dist/index.mjs"]

apps/server/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { join } from "node:path";
2+
import { db } from "@ifinho/db";
13
import { env } from "@ifinho/env/server";
24
import type { ChatRequest } from "@ifinho/types";
35
import cors from "cors";
6+
import { migrate } from "drizzle-orm/node-postgres/migrator";
47
import express from "express";
58
import { Ollama } from "ollama";
69

@@ -123,6 +126,12 @@ app.post("/api/chat", async (req, res) => {
123126
}
124127
});
125128

129+
console.log("Running database migrations...");
130+
await migrate(db, {
131+
migrationsFolder: join(process.cwd(), "packages/db/src/migrations"),
132+
});
133+
console.log("Migrations applied.");
134+
126135
app.listen(3000, () => {
127136
console.log("Server is running on http://localhost:3000");
128137
});

0 commit comments

Comments
 (0)