fix(db): rename pgSchema exports to prevent barrel collision

chat/image/mesh modules all exported a generic `const schema`
binding. When packages/db/src/schema/index.ts did `export * from
"./chat"` + `export * from "./image"` + `export * from "./mesh"`,
TypeScript's ambiguous-re-export rule silently dropped the colliding
bindings — drizzle-kit's introspection could not find the pgSchema
instances, so CREATE SCHEMA statements were never emitted. The
migration worked on the prior dev DB only because chat/image already
existed from an earlier turbostarter run; a fresh clone would fail.

pdf.ts already used `pdfSchema` (unique name). Applied the same
pattern everywhere:
- chat.ts:  `export const chatSchema = pgSchema("chat")`
- image.ts: `export const imageSchema = pgSchema("image")`
- mesh.ts:  `export const meshSchema = pgSchema("mesh")`

Also added `CREATE EXTENSION IF NOT EXISTS vector` at the top of the
migration (pgvector is used by pdf.embedding — the generated
migration assumed it was pre-enabled).

Verified end-to-end against a fresh pgvector/pgvector:pg17 container:
`pnpm drizzle-kit migrate` applies cleanly from scratch, all 7 mesh.*
tables + chat/image/pdf/mesh schemas created correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-04-04 22:02:09 +01:00
parent 3ab3fbcdf6
commit 8ce8b04e75
6 changed files with 62 additions and 28 deletions

View File

@@ -7,15 +7,18 @@ import { createInsertSchema, createSelectSchema } from "../utils/drizzle-zod";
import { user } from "./auth";
export const schema = pgSchema("chat");
// Uniquely-named pgSchema export (not `schema`) so drizzle-kit can
// introspect it through the `export * from "./chat"` barrel. See
// mesh.ts for the full rationale.
export const chatSchema = pgSchema("chat");
export const messageRoleEnum = schema.enum("role", [
export const messageRoleEnum = chatSchema.enum("role", [
"system",
"assistant",
"user",
]);
export const chat = schema.table("chat", {
export const chat = chatSchema.table("chat", {
id: text().primaryKey().notNull().$defaultFn(generateId),
name: text(),
userId: text()
@@ -27,7 +30,7 @@ export const chat = schema.table("chat", {
createdAt: timestamp().defaultNow(),
});
export const message = schema.table("message", {
export const message = chatSchema.table("message", {
id: text().primaryKey().notNull().$defaultFn(generateId),
chatId: text()
.references(() => chat.id, { onDelete: "cascade", onUpdate: "cascade" })
@@ -40,7 +43,7 @@ export const messageRelations = relations(message, ({ many }) => ({
part: many(part),
}));
export const part = schema.table("part", {
export const part = chatSchema.table("part", {
id: text().primaryKey().notNull().$defaultFn(generateId),
messageId: text()
.references(() => message.id, { onDelete: "cascade", onUpdate: "cascade" })