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 }

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 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",
image.png
image.png
image.png
Was this page helpful?