Extending Drizzle Schema in to multiple files with planetscale table prefix

Using the t3 latest App router I want to create a new schema file for each added table just so I can include drizzle-zod schemas inside this file so I would have a file for teams / posts etc

However, the tables from the extended schema doesn't get created with the "t3-new" prefix but their actual table name

/server/db/schema/teams.ts
export const mysqlTable = mysqlTableCreator((name) => `t3-new_${name}`);

export const teams = mysqlTable("teams", {
  id: serial("id").primaryKey(),
  name: text("name").notNull(),
  userId: varchar("user_id", { length: 256 }).notNull(),
});

/server/db/schema/_root.ts
import { teams } from "./teams";
export { teams };


/server/db/index.ts
import { Client } from "@planetscale/database";
import { drizzle } from "drizzle-orm/planetscale-serverless";

import { env } from "~/env.mjs";
import * as schema from "./schema";
import * as extended from "~/server/db/schema/_root";

export const db = drizzle(
  new Client({
    url: env.DATABASE_URL,
  }).connection(),
  { schema: { ...schema, ...extended } },
);


Can this be done or will I just have to create a new folder for each of the respective drizzle-zod types and leave the table creation stuff inside the original schema.

I was just playing around with the config to see if it would work, it creates the tables fine just the extended schema creates the tables without the prefix.
Was this page helpful?