DT
Drizzle Team•15mo ago
MrMendez

Migrate using Neon and Sveltekit

this is my code
import { pool } from '$lib/server/db';
import { drizzle } from 'drizzle-orm/neon-serverless';
import { migrate } from 'drizzle-orm/neon-serverless/migrator';
const db = drizzle(pool);

// this will automatically run needed migrations on the database
await migrate(db, { migrationsFolder: './migrations' });
import { pool } from '$lib/server/db';
import { drizzle } from 'drizzle-orm/neon-serverless';
import { migrate } from 'drizzle-orm/neon-serverless/migrator';
const db = drizzle(pool);

// this will automatically run needed migrations on the database
await migrate(db, { migrationsFolder: './migrations' });
pnpm script "migrate:push": "vite-node --options.transformMode.ssr='/.*/' ./src/lib/migrate.ts", my connection setup
import { Pool, neon, neonConfig } from '@neondatabase/serverless';
export const pool = new Pool({ connectionString: DB_CONNECTION_STRING });
export const http = neon(DB_CONNECTION_STRING);
import { Pool, neon, neonConfig } from '@neondatabase/serverless';
export const pool = new Pool({ connectionString: DB_CONNECTION_STRING });
export const http = neon(DB_CONNECTION_STRING);
and the error: Error: The required file "meta/_journal.json" could not be found. It seems like the "meta/_journal.json" file is missing or not located where the system expects it to be. This file is crucial for the migration process and the system cannot proceed without it. Location of the error: - File: /.../node_modules/drizzle-orm/migrator.mjs - Line: 21 - Method: readMigrationFiles Stack trace: 1. readMigrationFiles at migrator.ts:40:9 2. Module.migrate at neon-serverless/migrator.ts:9:21 3. /home/mrmendez/Projects/skymanager/src/lib/migrate.ts:7:7 4. ViteNodeRunner.runModule at vite-node/dist/client.mjs:342:5 5. ViteNodeRunner.directRequest at vite-node/dist/client.mjs:326:5 6. ViteNodeRunner.cachedRequest at vite-node/dist/client.mjs:189:14 7. ViteNodeRunner.executeFile at vite-node/dist/client.mjs:161:12 8. CAC.run at vite-node/dist/cli.mjs:91:5
8 Replies
Angelelz
Angelelz•15mo ago
Did you generate a migration prior to try to run it?
MrMendez
MrMendezOP•15mo ago
yes "migrate:gen": "drizzle-kit generate:pg --schema=./src/lib/migrations/schema.ts"
Angelelz
Angelelz•15mo ago
The other thing would be to check it you're providing the correct directory path in the config
MrMendez
MrMendezOP•15mo ago
No description
Angelelz
Angelelz•15mo ago
Don't you need:
await migrate(db, { migrationsFolder: './src/lib/migrations' });
await migrate(db, { migrationsFolder: './src/lib/migrations' });
?
MrMendez
MrMendezOP•15mo ago
nop, ./migrations is the right relative path, but either way if i use ./src/lib/migrations still does not work also, the type error on db is this: Error: Type Mismatch The "NeonDatabase<Record<string, never>>" type is not compatible with "NeonDatabase<Record<string, unknown>>". The discrepancy is rooted in the compatibility of '$with(...).as' between these types. Here are the details: - The 'getSQL()' return types are incompatible between the versions of drizzle-orm you are using (0.28.5 and 0.28.6). - The 'shouldInlineParams' property has different declarations in these versions. - The Typescript compiler detected this as error 2345, indicating a type assignment issue. Root Cause: It seems like you are using two different versions of drizzle-orm library. The type declarations in version 0.28.5 don't match with those in version 0.28.6, leading to this conflict.
Angelelz
Angelelz•15mo ago
I would delete node_modules and install everything again
MrMendez
MrMendezOP•15mo ago
nop 🥲 wait never mind, yea same error, delete all the meta and sql file and tried generating them again too, still have the same error:
throw new Error(`Can't find meta/_journal.json file);
throw new Error(`Can't find meta/_journal.json file);
i kind of found out the problem will update soon
Want results from more Discord servers?
Add your server