The database layer uses Drizzle ORM with a PostgreSQL backend. Schema definitions live inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Wikedhart18/nextjs-ai-chatbot/llms.txt
Use this file to discover all available pages before exploring further.
lib/db/schema.ts. Each table is exported as a Drizzle table object and as a TypeScript type inferred with InferSelectModel.
Migrations are managed with
drizzle-kit and live in lib/db/migrations/. Run pnpm db:migrate to apply pending migrations.Entity relationships
User
Stores registered users. Passwords are hashed with bcrypt before insertion.Primary key. Auto-generated UUID v4. Defaults to a random value.
The user’s email address. Maximum 64 characters. Must be unique per application logic.
bcrypt-hashed password. Optional — accounts using OAuth providers will have no password stored.
Chat
Represents a single conversation thread owned by a user.Primary key. Auto-generated UUID v4.
The time the chat was created. Set by the application at insert time.
Human-readable title for the conversation.
Foreign key referencing
User.id. Identifies the owning user.Controls whether the chat is accessible to others. Defaults to
'private'.Message
An individual message within a chat, from either the user or the AI assistant.Primary key. Auto-generated UUID v4.
Foreign key referencing
Chat.id. The conversation this message belongs to.The sender role (e.g.
'user', 'assistant', 'system', 'tool'). Stored as a plain varchar with no enum constraint at the database level.The message payload serialised as JSON. Shape matches the AI SDK
CoreMessage content format and may include text parts, tool calls, or tool results.The time the message was created.
Vote
Records a user’s up- or down-vote on a specific message. Uses a composite primary key.Part of composite primary key. Foreign key referencing
Chat.id.Part of composite primary key. Foreign key referencing
Message.id.true for an upvote, false for a downvote.Document
An artifact (text, code, image, or sheet) created during a conversation. Uses a composite primary key on(id, createdAt) to support versioning — multiple rows can share the same id but differ by creation time.
Part of composite primary key. Auto-generated UUID v4. Multiple versions of the same document share this value.
Part of composite primary key. The timestamp of this document version.
The document’s title.
The document body. Optional — may be
null for placeholder or in-progress documents.The artifact type. Defaults to
'text'.Foreign key referencing
User.id. The owner of this document.Suggestion
An inline edit suggestion on a document version. References the composite key(documentId, documentCreatedAt) on the Document table.
Primary key. Auto-generated UUID v4.
Part of the composite foreign key referencing
Document.id.Part of the composite foreign key referencing
Document.createdAt. Together with documentId this uniquely identifies the document version this suggestion targets.The original text in the document that is being replaced.
The proposed replacement text.
An optional explanation of why the change is being suggested.
Whether the suggestion has been accepted or dismissed. Defaults to
false.Foreign key referencing
User.id. The user who created the suggestion.The time the suggestion was created.