Migration Halts

I was working on Migrating a .sql file that I sucesfully generated with drizzle generate. The issue I ran into was that the Migration process has been running for several minutes. The .sql file is pretty lightweight and does not contain too much sql.
-- generated sql
import { pgTable, serial, text, varchar, timestamp, uuid } from "drizzle-orm/pg-core";

export const userTable = pgTable("user", {
id: text("id").primaryKey(),
username: varchar("username").notNull().unique(),
email: varchar("email").notNull().unique(),
password: varchar("password").notNull(),
});

export const sessionTable = pgTable("session", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => userTable.id),
expiresAt: timestamp("expires_at", {
withTimezone: true,
mode: "date"
}).notNull()
});
-- generated sql
import { pgTable, serial, text, varchar, timestamp, uuid } from "drizzle-orm/pg-core";

export const userTable = pgTable("user", {
id: text("id").primaryKey(),
username: varchar("username").notNull().unique(),
email: varchar("email").notNull().unique(),
password: varchar("password").notNull(),
});

export const sessionTable = pgTable("session", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => userTable.id),
expiresAt: timestamp("expires_at", {
withTimezone: true,
mode: "date"
}).notNull()
});
-- migration file
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';


const DATABASE_URL = "databaseStringCopiedFromDBForDebugging";
const migrationClient = postgres(DATABASE_URL, {max: 1});

// test connection

async function main() {
console.log('Migrating database...');
console.log('DATABASE_URL:', process.env.DATABASE_URL);
await migrate(drizzle(migrationClient), { migrationsFolder: './src/drizzle/migrations' });
await migrationClient.end();
console.log('Database migrated successfully!');
}

main();
-- migration file
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';


const DATABASE_URL = "databaseStringCopiedFromDBForDebugging";
const migrationClient = postgres(DATABASE_URL, {max: 1});

// test connection

async function main() {
console.log('Migrating database...');
console.log('DATABASE_URL:', process.env.DATABASE_URL);
await migrate(drizzle(migrationClient), { migrationsFolder: './src/drizzle/migrations' });
await migrationClient.end();
console.log('Database migrated successfully!');
}

main();
// drizzle.config.ts
import type { Config } from "drizzle-kit";
import { defineConfig } from "drizzle-kit"

export default defineConfig({
schema: "./src/drizzle/schema.ts",
out: "./src/drizzle/migrations",
dialect: "postgresql",
dbCredentials: {
url: "databaseStringCopiedForDebugging"
},
verbose: true,
strict: true,
})
// drizzle.config.ts
import type { Config } from "drizzle-kit";
import { defineConfig } from "drizzle-kit"

export default defineConfig({
schema: "./src/drizzle/schema.ts",
out: "./src/drizzle/migrations",
dialect: "postgresql",
dbCredentials: {
url: "databaseStringCopiedForDebugging"
},
verbose: true,
strict: true,
})
No description
3 Replies
sanner
sannerOP4mo ago
This is my current folder structure
Darren
Darren4mo ago
Add a process.exit() at bottom of main I have a feeling you can't end since drizzle still holds the connection what if you put
const DATABASE_URL = "databaseStringCopiedFromDBForDebugging";
const migrationClient = postgres(DATABASE_URL, {max: 1});
const DATABASE_URL = "databaseStringCopiedFromDBForDebugging";
const migrationClient = postgres(DATABASE_URL, {max: 1});
inside your main()
sanner
sannerOP4mo ago
I figured out the issue had to use ssl and the rejectUnauthorized flag
import { drizzle } from "drizzle-orm/node-postgres";
import { DrizzlePostgreSQLAdapter } from "@lucia-auth/adapter-drizzle";
import {session, user} from "$lib/drizzle/schema";
import pg from "pg";


const db = new pg.Client({
connectionString: import.meta.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
}
});
export const temboDB = drizzle(db, {schema: {user, session}});
export const adapter = new DrizzlePostgreSQLAdapter(temboDB, session, user);
import { drizzle } from "drizzle-orm/node-postgres";
import { DrizzlePostgreSQLAdapter } from "@lucia-auth/adapter-drizzle";
import {session, user} from "$lib/drizzle/schema";
import pg from "pg";


const db = new pg.Client({
connectionString: import.meta.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
}
});
export const temboDB = drizzle(db, {schema: {user, session}});
export const adapter = new DrizzlePostgreSQLAdapter(temboDB, session, user);
Want results from more Discord servers?
Add your server