migrate function hangs without any result

I have this in my migrate.js file
// @ts-check

const { drizzle } = require("drizzle-orm/node-postgres");
const { migrate } = require("drizzle-orm/node-postgres/migrator");
const { Client } = require("pg");
require("dotenv").config();
const path = require("path");

// for query purposes
const config = {
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || ""),
user: process.env.DB_USER,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
connectionTimeoutMillis: 10000,
};
console.table(config);
const client = new Client(config);

console.log(path.join(process.cwd(), "drizzle"));

async function main() {
try {
await migrate(drizzle(client), {
migrationsFolder: path.join(process.cwd(), "drizzle"),
});
console.log("success");
client.end();
process.exit(0);
} catch (error) {
console.log("error: ", error);
client.end();
process.exit(1);
}
}
await main();
// @ts-check

const { drizzle } = require("drizzle-orm/node-postgres");
const { migrate } = require("drizzle-orm/node-postgres/migrator");
const { Client } = require("pg");
require("dotenv").config();
const path = require("path");

// for query purposes
const config = {
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || ""),
user: process.env.DB_USER,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
connectionTimeoutMillis: 10000,
};
console.table(config);
const client = new Client(config);

console.log(path.join(process.cwd(), "drizzle"));

async function main() {
try {
await migrate(drizzle(client), {
migrationsFolder: path.join(process.cwd(), "drizzle"),
});
console.log("success");
client.end();
process.exit(0);
} catch (error) {
console.log("error: ", error);
client.end();
process.exit(1);
}
}
await main();
when I run the file with bun everything hangs and nothing get's executed, the log functions log the correct credentials and file path but the execution stops after the migrate call, it hangs longer than the timeout so I don't think it is a database issue
7 Replies
hachoter
hachoterOP15mo ago
Also nothing is added to the database The same thing is also happening when trying to insert with drizzle When I set logger to true I get the query and everything looks ok in the query but it still hangs studio runs as expected using the same credentials I also verified all the values are correct
Angelelz
Angelelz15mo ago
I haven't seen anything like this. Can you put together and share a minimal reproduction repo?
hachoter
hachoterOP15mo ago
@Angelelz Here you go https://github.com/isaacfink/drizzle-bug I just tested it on my local database instead of rds and it is still not working, run the db:migrations:generate command with bun than try running bun ./migrate.js you can see the credentials in the console so you can make sue everything else is in order
GitHub
GitHub - isaacfink/drizzle-bug
Contribute to isaacfink/drizzle-bug development by creating an account on GitHub.
hachoter
hachoterOP15mo ago
I am using ssl in the repo but I have tried with and without, for thenrds one in my original project it is a requirement The repo already has a migration
Angelelz
Angelelz15mo ago
Did this work before? Have you tried with pnpm/npm/yarn? Well, I looked into it. I don't think that drizzle is the problem Is not like I figured it out but I found that changing type to module and then using postgres-js as the driver, seems to work This worked for me:
// @ts-check
const drizzle = require('drizzle-orm/postgres-js').drizzle
const migrate = require('drizzle-orm/postgres-js/migrator').migrate
const dotenvConfig = require('dotenv').config;
dotenvConfig();
const path = require('path');

import postgres from 'postgres'

// for query purposes
const config = {
host: "localhost",
port: 5432,
user: 'root',
database: 'buggy',
password: 'root',
};
console.table(config);
const sql = postgres(config);

console.log(path.join(process.cwd(), "drizzle"));

const db = drizzle(sql);

await migrate(db, { migrationsFolder: path.join(process.cwd(), "drizzle") });
console.log("success");

export { }
// @ts-check
const drizzle = require('drizzle-orm/postgres-js').drizzle
const migrate = require('drizzle-orm/postgres-js/migrator').migrate
const dotenvConfig = require('dotenv').config;
dotenvConfig();
const path = require('path');

import postgres from 'postgres'

// for query purposes
const config = {
host: "localhost",
port: 5432,
user: 'root',
database: 'buggy',
password: 'root',
};
console.table(config);
const sql = postgres(config);

console.log(path.join(process.cwd(), "drizzle"));

const db = drizzle(sql);

await migrate(db, { migrationsFolder: path.join(process.cwd(), "drizzle") });
console.log("success");

export { }
But I had to set esModuleInterop to true
hachoter
hachoterOP15mo ago
I can't change type to module and I am not using typescript so changing any ts settings won't help, its it just the driver?
Angelelz
Angelelz15mo ago
With this code you don't have to change it to type: module But you'll need esModuleInterop: true I honestly didn't look at why it's not working, I just tested different setups and found what works
Want results from more Discord servers?
Add your server