drizzle runtime migrations with svelte production build

Hi! I am using better-auth with drizzle-orm and i am doing the 4th way of handling migrations
I want to have database schema in my TypeScript codebase, I want Drizzle to generate SQL migration files for me and I want Drizzle to apply them during runtime
I want to have database schema in my TypeScript codebase, I want Drizzle to generate SQL migration files for me and I want Drizzle to apply them during runtime
This works in dev, but when i build image in prod, i get error file not found error, probs cus it got compiled and stuff. How can i workaround this ?
// hooks.server.ts
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import { db } from "$lib/server/db";

export const init: ServerInit = async () => {
migrate(db, { migrationsFolder: "./src/lib/server/migrations" });
}
// hooks.server.ts
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import { db } from "$lib/server/db";

export const init: ServerInit = async () => {
migrate(db, { migrationsFolder: "./src/lib/server/migrations" });
}
// db.ts

import { drizzle } from "drizzle-orm/better-sqlite3";
import Database from "better-sqlite3";
import { env } from "$env/dynamic/private";
import * as schema from "./schema"; // it's a folder with index.ts export * ....

const sqlite = new Database(env.DATABASE_URL);
export const db = drizzle(sqlite, { schema });
// db.ts

import { drizzle } from "drizzle-orm/better-sqlite3";
import Database from "better-sqlite3";
import { env } from "$env/dynamic/private";
import * as schema from "./schema"; // it's a folder with index.ts export * ....

const sqlite = new Database(env.DATABASE_URL);
export const db = drizzle(sqlite, { schema });
No description
1 Reply
Mini
MiniOP2mo ago
fixed it by moving drizzle migrations to root and docker file changes of copying migrations folder into final image COPY drizzle /riven/drizzle my schemas, relations, db etc are still inside src/lib/server

Did you find this page helpful?