Skip to content

bug: Incorrect createTable prefix when using Better Auth + Drizzle + PostgreSQL #2184

Description

@epsilon42

Provide environment information

System:
OS: macOS 15.5
CPU: (10) arm64 Apple M1 Pro
Memory: 73.70 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.7.0 - /Users/andrew/.nvm/versions/node/v20.7.0/bin/node
Yarn: 1.22.22 - /opt/homebrew/bin/yarn
npm: 10.8.1 - /Users/andrew/.nvm/versions/node/v20.7.0/bin/npm
pnpm: 10.5.2 - /opt/homebrew/bin/pnpm

Describe the bug

When running pnpm create t3-app@latest and using the following combination:

  • Better Auth
  • Drizzle
  • PostgreSQL

It creates a schema.ts with the incorrect table prefix:

export const createTable = pgTableCreator((name) => `pg-drizzle_${name}`);

Expected behaviour is for pg-drizzle to be replaced with the project name the user entered for the question: What will your project be called?

Reproduction repo

https://github.com/t3-oss/create-t3-app/blob/main/cli/template/extras/src/server/db/schema-drizzle/with-better-auth-postgres.ts

To reproduce

Run pnpm create t3-app@latest with these key options selected:

  • Better Auth
  • Drizzle
  • PostgreSQL

Full output:

❯ pnpm create t3-app@latest

   ___ ___ ___   __ _____ ___   _____ ____    __   ___ ___
  / __| _ \ __| /  \_   _| __| |_   _|__ /   /  \ | _ \ _ \
 | (__|   / _| / /\ \| | | _|    | |  |_ \  / /\ \|  _/  _/
  \___|_|_\___|_/‾‾\_\_| |___|   |_| |___/ /_/‾‾\_\_| |_|


│
◇  What will your project be called?
│  t3test
│
◇  Will you be using TypeScript or JavaScript?
│  TypeScript
│
◇  Will you be using Tailwind CSS for styling?
│  Yes
│
◇  Would you like to use tRPC?
│  Yes
│
◇  What authentication provider would you like to use?
│  BetterAuth
│
◇  What database ORM would you like to use?
│  Drizzle
│
◇  Would you like to use Next.js App Router?
│  Yes
│
◇  What database provider would you like to use?
│  PostgreSQL
│
◇  Would you like to use ESLint and Prettier or Biome for linting and formatting?
│  ESLint/Prettier
│
◇  Should we initialize a Git repository and stage the changes?
│  Yes
│
◇  Should we run 'pnpm install' for you?
│  Yes
│
◇  What import alias would you like to use?
│  ~/

Using: pnpm

✔ t3test scaffolded successfully!

Adding boilerplate...
✔ Successfully setup boilerplate for betterAuth
✔ Successfully setup boilerplate for drizzle
✔ Successfully setup boilerplate for tailwind
✔ Successfully setup boilerplate for trpc
✔ Successfully setup boilerplate for dbContainer
✔ Successfully setup boilerplate for envVariables
✔ Successfully setup boilerplate for eslint

Installing dependencies...
✔ Successfully installed dependencies!

Formatting project with prettier...
✔ Successfully formatted project
Initializing Git...
✔ Successfully initialized and staged git

Next steps:
  cd t3test
  Start up a database, if needed using './start-database.sh'
  pnpm db:push
  pnpm dev
  git commit -m "initial commit"

❯ cd t3test

❯ cat src/server/db/schema.ts
.
.
.
export const createTable = pgTableCreator((name) => `pg-drizzle_${name}`);
.
.
.

Additional information

In order for the code in cli/src/installers/drizzle.ts to set the prefix in the schema to the project name, it expects the table prefix to be project1_${name}.

I think all that needs to be changed is this file:

  • cli/template/extras/src/server/db/schema-drizzle/with-better-auth-postgres.ts
// Change from this
export const createTable = pgTableCreator((name) => `pg-drizzle_${name}`);

// To this:
export const createTable = pgTableCreator((name) => `project1_${name}`);

This follows the pattern used elsewhere in the project.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions