Migrations not working with Neon.Tech?

So i was trying to use drizzle for the first time. a little bit of a noob but im not sure what im doing wrong here. when i go to neon i can see the compute starting so it seems like there's a connection happening, but the actual table is not created? I tried using the neon driver first and couldn't get it working. and when i print my connectionString i see it properly using tsx to run the file Can anyone help? src/db/index.ts
import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js"
import postgres from "postgres"
import { migrate } from "drizzle-orm/postgres-js/migrator"
import { config } from "dotenv"

config({ path: ".env" })
const connectionString = process.env.DATABASE_URL_TEST_DRIZZLE || ""

console.log(connectionString)

const client = postgres(connectionString, { ssl: "require" })
const db: PostgresJsDatabase = drizzle(client)

const migrationsClient = postgres(connectionString, {
max: 1,
})
const migrationsDb = drizzle(migrationsClient)
await migrate(migrationsDb, { migrationsFolder: "./src/db/migrations" })

export { db }
import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js"
import postgres from "postgres"
import { migrate } from "drizzle-orm/postgres-js/migrator"
import { config } from "dotenv"

config({ path: ".env" })
const connectionString = process.env.DATABASE_URL_TEST_DRIZZLE || ""

console.log(connectionString)

const client = postgres(connectionString, { ssl: "require" })
const db: PostgresJsDatabase = drizzle(client)

const migrationsClient = postgres(connectionString, {
max: 1,
})
const migrationsDb = drizzle(migrationsClient)
await migrate(migrationsDb, { migrationsFolder: "./src/db/migrations" })

export { db }
src/db/schema.ts
import { pgTable, uuid, timestamp, text, varchar } from "drizzle-orm/pg-core"

export const users = pgTable("usersTest", {
userId: uuid("user_id").primaryKey(),
firstName: text("first_name"),
lastName: text("last_name"),
fullName: text("full_name"),
email: text("email"),
phone: varchar("phone", { length: 256 }),
createdAt: timestamp("created_at").defaultNow(),
})
import { pgTable, uuid, timestamp, text, varchar } from "drizzle-orm/pg-core"

export const users = pgTable("usersTest", {
userId: uuid("user_id").primaryKey(),
firstName: text("first_name"),
lastName: text("last_name"),
fullName: text("full_name"),
email: text("email"),
phone: varchar("phone", { length: 256 }),
createdAt: timestamp("created_at").defaultNow(),
})
import type { Config } from "drizzle-kit"

export default {
schema: "./src/db/schema.ts",
out: "./src/migrations",
} satisfies Config
import type { Config } from "drizzle-kit"

export default {
schema: "./src/db/schema.ts",
out: "./src/migrations",
} satisfies Config
script: "generate": "drizzle-kit generate:pg --out src/db/migrations --schema src/db/schema.ts",
1 Reply
DiamondDragon
DiamondDragonOP2y ago
I get the error as well when running tsx on index.ts but i have ssl set to require, so im confused
node:internal/process/esm_loader:97
internalBinding('errors').triggerUncaughtException(
^
PostgresError: connection is insecure (try using `sslmode=require`)
node:internal/process/esm_loader:97
internalBinding('errors').triggerUncaughtException(
^
PostgresError: connection is insecure (try using `sslmode=require`)
doh! needed to add ssl require to the migrationClient. so now i can connect to neon properly
const migrationsClient = postgres(connectionString, {
max: 1,
ssl: "require",
})
const migrationsClient = postgres(connectionString, {
max: 1,
ssl: "require",
})
Want results from more Discord servers?
Add your server