NeonN
Neon2y ago
3 replies
then-purple

Guide on how to apply migrations (Nextjs/ @neondatabase/serverless)

Recently decided to try Neon for my portfolio V2 api. I'm working with Nextjs 14, drizzle and Neon. I'm having difficulties applyinig migrations to Neon locally.

Here is my
migrate
file
import { neonConfig } from "@neondatabase/serverless";
import { migrate } from "drizzle-orm/neon-http/migrator";
import { db } from "./libs/db";

(async () => {
  neonConfig.fetchConnectionCache = true;

  await migrate(db, { migrationsFolder: "./migrations" });

  try {
    await migrate(db, { migrationsFolder: "/src/migrations" });
    console.log("Done");
  } catch (e) {
    console.log(e);
  }
})();


In my
package.json
i have this script to execute the migrate file in my
src
dir
  "migrations": "npx drizzle-kit generate:pg",
  "apply-migrations": "tsx ./src/migrate.ts"


I'm not sure what the issue is but whenever i run this command, It throws error
Error: Can't find meta/_journal.json file
    at readMigrationFiles (/Users/mac/Web/Portfolio/ogdev/node_modules/src/migrator.ts:40:9)
    at migrate (/Users/mac/Web/Portfolio/ogdev/node_modules/src/neon-http/migrator.ts:18:21)
    at <anonymous> (/Users/mac/Web/Portfolio/ogdev/src/migrate.ts:16:11)
    at import_serverless (/Users/mac/Web/Portfolio/ogdev/src/migrate.ts:21:1)
    at Object.<anonymous> (/Users/mac/Web/Portfolio/ogdev/src/migrate.ts:21:4)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.S (/usr/local/lib/node_modules/tsx/dist/cjs/index.cjs:1:1292)


I'm new to neon and don't know what i'm missing. Woulkd appreciate any resource/guide to achieving this
Thanks
Was this page helpful?