Is it possible to run migrations with the "neon" driver?

It's not quite clear from the documentation, and the driver package doesn't export any migrate function, and I wonder if it is possible. If it is, would love for an explanation for how, or a code example, if it isn't possible, do I need to download the node pg driver as well just for the migrations, and will it work with neon? Thanks!
1 Reply
Mykhailo
Mykhailo12mo ago
Hello, @shohambs🐶! Yes, it is possible, there is code example below:
import 'dotenv/config';
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { migrate } from 'drizzle-orm/neon-http/migrator';

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

const sql = neon(process.env.DRIZZLE_DATABASE_URL!);
const db = drizzle(sql);

await migrate(db, { migrationsFolder: './drizzle' });

console.log('Done');
})();
import 'dotenv/config';
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { migrate } from 'drizzle-orm/neon-http/migrator';

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

const sql = neon(process.env.DRIZZLE_DATABASE_URL!);
const db = drizzle(sql);

await migrate(db, { migrationsFolder: './drizzle' });

console.log('Done');
})();
Want results from more Discord servers?
Add your server