© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•16mo ago•
29 replies
Jacob ඞ

Drizzle/better-auth + Local PSQL

I have the biggest issue trying to setup drizzle with my project and I don't believe it should be this complicated as I am facing currently. Someone with more experience please help me out and explain to me what I am doing wrong.

So I am trying to setup better-auth with Drizzle + my local PostgreSQL and I am using the latest version of Next js for my project.

I basically start of my initialising my next js project by running the regular command
npx create-next-app@latest
npx create-next-app@latest
(app router no src-folder) and go then install drizzle following the docs and run the commands that are shown in the docs/guide. I create my
.env
.env
file and setup my
DATABASE_URL="postgres://postgres:mypassword@localhost:5432/postgres"
DATABASE_URL="postgres://postgres:mypassword@localhost:5432/postgres"
and move on to creating my
db
db
directory and place the
index.ts
index.ts
file inside of it which holds this code.

import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";

export function createClient(connectionString: string) {
  const client = postgres(connectionString);
  return drizzle(client, { schema });
}

export type DbClient = ReturnType<typeof createClient>;

export function createMigrationClient(connectionString: string) {
  const psql = postgres(connectionString, { max: 1 });
  const db = drizzle(psql, { schema });

  return db;
}
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";

export function createClient(connectionString: string) {
  const client = postgres(connectionString);
  return drizzle(client, { schema });
}

export type DbClient = ReturnType<typeof createClient>;

export function createMigrationClient(connectionString: string) {
  const psql = postgres(connectionString, { max: 1 });
  const db = drizzle(psql, { schema });

  return db;
}


And I then create my
schema.ts
schema.ts
file. This is basically just copied over from the docs. Afterwards I move on to create my
drizzle.config.ts
drizzle.config.ts
file but I slightly modify it.

import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
  out: './drizzle',
  schema: './src/db/schema.ts',
  dialect: 'postgresql',
  dbCredentials: {
    url: process.env.DATABASE_URL!,
  },
});
import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
  out: './drizzle',
  schema: './src/db/schema.ts',
  dialect: 'postgresql',
  dbCredentials: {
    url: process.env.DATABASE_URL!,
  },
});


What I change here is that I change the
schema: './src/db/schema.ts',
schema: './src/db/schema.ts',
to
schema: './db/schema.ts',
schema: './db/schema.ts',
for app directory in next js.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

local.drizzle.studo issue
Drizzle TeamDTDrizzle Team / help
8mo ago
https://local.drizzle.studio/
Drizzle TeamDTDrizzle Team / help
2y ago
Use drizzle studio without local.drizzle.studio?
Drizzle TeamDTDrizzle Team / help
2y ago