drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.5k stars 643 forks source link

[BUG]: prefix with pgTableCreator doesn't work on latest version of Drizzle-kit #2420

Closed volfadar closed 4 months ago

volfadar commented 5 months ago

What version of drizzle-orm are you using?

0.31.0

What version of drizzle-kit are you using?

0.22.1

Describe the Bug

here's my code

export const create = pgTableCreator((name) => `zingfont_${name}`);

export const users = pgTable("users", {
  id: serial("id").primaryKey(),
  name: text("name").notNull(),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  updatedAt: timestamp("updated_at")
    .notNull()
    .$onUpdate(() => new Date()),
});

and when i do npx drizzle-kit generate it generate this sql, which are not contain prefix :

--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
    "id" serial PRIMARY KEY NOT NULL,
    "name" text NOT NULL,
    "created_at" timestamp DEFAULT now() NOT NULL,
    "updated_at" timestamp NOT NULL,
    CONSTRAINT "users_email_unique" UNIQUE("email")
);

and here's my drizzle config :

import { type Config } from "drizzle-kit";

import { env } from "@/env";

export default {
  schema: "./src/server/db/schema.ts",
  dialect: "postgresql",
  dbCredentials: {
    url: env.DATABASE_URL,
  },
  tablesFilter: ["zingfont_*"],
} satisfies Config;

i already tried to remove node_modules and drizzle folder several times, and do migrate, push. several times. the result are the same. there isn't any prefix added.

Expected behavior

there must be a prefix right?

Environment & setup

Windows 11 Bun 1.1.12 Next JS 14.2.1 Supabase

manjime83 commented 4 months ago

I believe you are not using the table creator correctly. Try using the function generated by the table creator to create your tables.

export const pgTable = pgTableCreator((name) => `zingfont_${name}`);

AlexBlokh commented 4 months ago

@volfadar you are not using pgTableCreator just like @manjime83 mentioned

volfadar commented 4 months ago
(name) => `zingfont_${name}`

Hey, I totally missed @manjime83's new reply! Now it all makes sense why my code wasn't working. Thanks so much to both of you guys! 😄