Troubles during migrations using drizzle and a neon serverless database

Hello im really new to drizzle and i already learned how to setup a scheme but im having troubles when i want to migrate it to the neon postgressql database. Error: No database connection string was provided to neon(). Perhaps an environment variable has not been set? This is how my migration file looks like:
import { migrate } from 'drizzle-orm/neon-http/migrator';
import { drizzle, NeonHttpDatabase } from 'drizzle-orm/neon-http'
import { neon } from '@neondatabase/serverless';


async function main() {
const sql = neon(process.env.DATABASE_URL as string)
const db: NeonHttpDatabase = drizzle(sql);

console.log("[migrate] Running migrations ...");

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

console.log("[migrate] All migrations have been ran, exiting ...");
}

main();
import { migrate } from 'drizzle-orm/neon-http/migrator';
import { drizzle, NeonHttpDatabase } from 'drizzle-orm/neon-http'
import { neon } from '@neondatabase/serverless';


async function main() {
const sql = neon(process.env.DATABASE_URL as string)
const db: NeonHttpDatabase = drizzle(sql);

console.log("[migrate] Running migrations ...");

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

console.log("[migrate] All migrations have been ran, exiting ...");
}

main();
3 Replies
patryk
patrykOP11mo ago
my .env.local is setup as it should i think DATABASE_URL=postgresql://user:password@thehost/mydbname nevermind i fixed it but i'll leave the ticket here. i added this to my migrate.ts
import * as dotenv from 'dotenv';

dotenv.config({
path: '.env.local',
});
import * as dotenv from 'dotenv';

dotenv.config({
path: '.env.local',
});
Artemis
Artemis11mo ago
hello I'm also really new to drizzle .I'm also Having a similar issue while migrating it to neon
import { drizzle, NeonHttpDatabase } from "drizzle-orm/neon-http";
import { migrate } from "drizzle-orm/neon-http/migrator";
import { neon } from "@neondatabase/serverless";
import * as dotenv from "dotenv";

dotenv.config({
path: ".env",
});
const sql = neon(process.env.NEON_DATABASE_URL);
const db: NeonHttpDatabase = drizzle(sql);
const main = async () => {
try {
await migrate(db, {
migrationsFolder: "app/db/migrations",
});
console.log("Migration complete");
} catch (e) {
console.error("Migration failed", e);
process.exit(1);
}
};

main();
import { drizzle, NeonHttpDatabase } from "drizzle-orm/neon-http";
import { migrate } from "drizzle-orm/neon-http/migrator";
import { neon } from "@neondatabase/serverless";
import * as dotenv from "dotenv";

dotenv.config({
path: ".env",
});
const sql = neon(process.env.NEON_DATABASE_URL);
const db: NeonHttpDatabase = drizzle(sql);
const main = async () => {
try {
await migrate(db, {
migrationsFolder: "app/db/migrations",
});
console.log("Migration complete");
} catch (e) {
console.error("Migration failed", e);
process.exit(1);
}
};

main();
In my case It's showing Argument of type 'NeonQueryFunction<false, false>' is not assignable to parameter of type 'NeonQueryFunction<boolean, boolean>'. at
const db: NeonHttpDatabase = drizzle(sql);
const db: NeonHttpDatabase = drizzle(sql);
line
Whit4D
Whit4D10mo ago
Try adding a type like:
import { neon, NeonQueryFunction } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';

const sql : NeonQueryFunction<boolean, boolean> = neon(process.env.DRIZZLE_DATABASE_URL!);
const db = drizzle(sql);
import { neon, NeonQueryFunction } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';

const sql : NeonQueryFunction<boolean, boolean> = neon(process.env.DRIZZLE_DATABASE_URL!);
const db = drizzle(sql);
Alternatively, remove the sql constant and just place the neon call inside the drizzle call, like:
import { neon } from '@neondatabase/serverless'
import { drizzle } from 'drizzle-orm/neon-http'

const db = drizzle(neon(process.env.DRIZZLE_DATABASE_URL!))
import { neon } from '@neondatabase/serverless'
import { drizzle } from 'drizzle-orm/neon-http'

const db = drizzle(neon(process.env.DRIZZLE_DATABASE_URL!))
Want results from more Discord servers?
Add your server