mirror of
https://github.com/SrIzan10/helium.git
synced 2026-06-06 00:56:58 +00:00
chore: (ai gen) drizzle migration fixes
This commit is contained in:
@@ -25,6 +25,9 @@ WORKDIR /app
|
|||||||
# Only `.output` folder is needed from the build stage
|
# Only `.output` folder is needed from the build stage
|
||||||
COPY --from=build /app/.output/ ./
|
COPY --from=build /app/.output/ ./
|
||||||
|
|
||||||
|
# Copy drizzle migrations folder
|
||||||
|
COPY --from=build /app/drizzle/ ./drizzle/
|
||||||
|
|
||||||
# Change the port and host
|
# Change the port and host
|
||||||
ENV PORT=80
|
ENV PORT=80
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { migrate } from "drizzle-orm/neon-http/migrator";
|
import { migrate } from "drizzle-orm/neon-http/migrator";
|
||||||
import { drizzle } from "drizzle-orm/neon-http";
|
import { drizzle } from "drizzle-orm/neon-http";
|
||||||
import * as schema from "./schema";
|
import * as schema from "./schema";
|
||||||
|
import { join } from "path";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
|
||||||
export async function runMigrations() {
|
export async function runMigrations() {
|
||||||
if (!process.env.DATABASE_URL) {
|
if (!process.env.DATABASE_URL) {
|
||||||
@@ -9,8 +11,20 @@ export async function runMigrations() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const db = drizzle(process.env.DATABASE_URL, { schema });
|
const db = drizzle(process.env.DATABASE_URL, { schema });
|
||||||
console.log("[DB] Running migrations...");
|
|
||||||
await migrate(db, { migrationsFolder: "./drizzle" });
|
// Determine the correct migrations folder path
|
||||||
|
// In development: ./drizzle from project root
|
||||||
|
// In production (Docker): /app/drizzle
|
||||||
|
let migrationsFolder = "./drizzle";
|
||||||
|
|
||||||
|
if (existsSync("/app/drizzle/meta/_journal.json")) {
|
||||||
|
migrationsFolder = "/app/drizzle";
|
||||||
|
} else if (existsSync(join(process.cwd(), "drizzle/meta/_journal.json"))) {
|
||||||
|
migrationsFolder = join(process.cwd(), "drizzle");
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("[DB] Running migrations from:", migrationsFolder);
|
||||||
|
await migrate(db, { migrationsFolder });
|
||||||
console.log("[DB] Migrations completed successfully");
|
console.log("[DB] Migrations completed successfully");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[DB] Migration failed:", error);
|
console.error("[DB] Migration failed:", error);
|
||||||
|
|||||||
Reference in New Issue
Block a user