fix(conversation): use VARCHAR instead of enum for consistency with init-db.sql

- Change MessageEntity.role from enum to VARCHAR(20)
- Change MessageEntity.type from enum to VARCHAR(30)
- Change ConversationEntity.status from enum to VARCHAR(20)
- Add nullable: true to userId to match database schema
- Add length constraints to match database schema
- Convert enums to const objects with type exports for type safety

This ensures TypeORM entities match the database schema exactly,
avoiding potential issues with enum type creation in production.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-23 05:06:36 -08:00
parent 0f56cea96a
commit 10a2449d05
2 changed files with 43 additions and 38 deletions

View File

@ -8,26 +8,28 @@ import {
} from 'typeorm';
import { MessageEntity } from './message.entity';
export enum ConversationStatus {
ACTIVE = 'ACTIVE',
ENDED = 'ENDED',
ARCHIVED = 'ARCHIVED',
}
/**
*
*/
export const ConversationStatus = {
ACTIVE: 'ACTIVE',
ENDED: 'ENDED',
ARCHIVED: 'ARCHIVED',
} as const;
export type ConversationStatusType =
(typeof ConversationStatus)[keyof typeof ConversationStatus];
@Entity('conversations')
export class ConversationEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ name: 'user_id', type: 'uuid' })
@Column({ name: 'user_id', type: 'uuid', nullable: true })
userId: string;
@Column({
type: 'enum',
enum: ConversationStatus,
default: ConversationStatus.ACTIVE,
})
status: ConversationStatus;
@Column({ length: 20, default: 'ACTIVE' })
status: ConversationStatusType;
@Column({ nullable: true })
title: string;
@ -35,7 +37,7 @@ export class ConversationEntity {
@Column({ type: 'text', nullable: true })
summary: string;
@Column({ nullable: true })
@Column({ length: 50, nullable: true })
category: string;
@Column({ name: 'message_count', default: 0 })

View File

@ -8,21 +8,31 @@ import {
} from 'typeorm';
import { ConversationEntity } from './conversation.entity';
export enum MessageRole {
USER = 'user',
ASSISTANT = 'assistant',
SYSTEM = 'system',
}
/**
*
*/
export const MessageRole = {
USER: 'user',
ASSISTANT: 'assistant',
SYSTEM: 'system',
} as const;
export enum MessageType {
TEXT = 'TEXT',
TEXT_WITH_ATTACHMENTS = 'TEXT_WITH_ATTACHMENTS',
TOOL_CALL = 'TOOL_CALL',
TOOL_RESULT = 'TOOL_RESULT',
PAYMENT_REQUEST = 'PAYMENT_REQUEST',
ASSESSMENT_START = 'ASSESSMENT_START',
ASSESSMENT_RESULT = 'ASSESSMENT_RESULT',
}
export type MessageRoleType = (typeof MessageRole)[keyof typeof MessageRole];
/**
*
*/
export const MessageType = {
TEXT: 'TEXT',
TEXT_WITH_ATTACHMENTS: 'TEXT_WITH_ATTACHMENTS',
TOOL_CALL: 'TOOL_CALL',
TOOL_RESULT: 'TOOL_RESULT',
PAYMENT_REQUEST: 'PAYMENT_REQUEST',
ASSESSMENT_START: 'ASSESSMENT_START',
ASSESSMENT_RESULT: 'ASSESSMENT_RESULT',
} as const;
export type MessageTypeType = (typeof MessageType)[keyof typeof MessageType];
@Entity('messages')
export class MessageEntity {
@ -32,18 +42,11 @@ export class MessageEntity {
@Column({ name: 'conversation_id', type: 'uuid' })
conversationId: string;
@Column({
type: 'enum',
enum: MessageRole,
})
role: MessageRole;
@Column({ length: 20 })
role: MessageRoleType;
@Column({
type: 'enum',
enum: MessageType,
default: MessageType.TEXT,
})
type: MessageType;
@Column({ length: 30, default: 'TEXT' })
type: MessageTypeType;
@Column({ type: 'text' })
content: string;