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:
parent
0f56cea96a
commit
10a2449d05
|
|
@ -8,26 +8,28 @@ import {
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { MessageEntity } from './message.entity';
|
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')
|
@Entity('conversations')
|
||||||
export class ConversationEntity {
|
export class ConversationEntity {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ name: 'user_id', type: 'uuid' })
|
@Column({ name: 'user_id', type: 'uuid', nullable: true })
|
||||||
userId: string;
|
userId: string;
|
||||||
|
|
||||||
@Column({
|
@Column({ length: 20, default: 'ACTIVE' })
|
||||||
type: 'enum',
|
status: ConversationStatusType;
|
||||||
enum: ConversationStatus,
|
|
||||||
default: ConversationStatus.ACTIVE,
|
|
||||||
})
|
|
||||||
status: ConversationStatus;
|
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -35,7 +37,7 @@ export class ConversationEntity {
|
||||||
@Column({ type: 'text', nullable: true })
|
@Column({ type: 'text', nullable: true })
|
||||||
summary: string;
|
summary: string;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ length: 50, nullable: true })
|
||||||
category: string;
|
category: string;
|
||||||
|
|
||||||
@Column({ name: 'message_count', default: 0 })
|
@Column({ name: 'message_count', default: 0 })
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,31 @@ import {
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { ConversationEntity } from './conversation.entity';
|
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 {
|
export type MessageRoleType = (typeof MessageRole)[keyof typeof MessageRole];
|
||||||
TEXT = 'TEXT',
|
|
||||||
TEXT_WITH_ATTACHMENTS = 'TEXT_WITH_ATTACHMENTS',
|
/**
|
||||||
TOOL_CALL = 'TOOL_CALL',
|
* 消息类型常量
|
||||||
TOOL_RESULT = 'TOOL_RESULT',
|
*/
|
||||||
PAYMENT_REQUEST = 'PAYMENT_REQUEST',
|
export const MessageType = {
|
||||||
ASSESSMENT_START = 'ASSESSMENT_START',
|
TEXT: 'TEXT',
|
||||||
ASSESSMENT_RESULT = 'ASSESSMENT_RESULT',
|
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')
|
@Entity('messages')
|
||||||
export class MessageEntity {
|
export class MessageEntity {
|
||||||
|
|
@ -32,18 +42,11 @@ export class MessageEntity {
|
||||||
@Column({ name: 'conversation_id', type: 'uuid' })
|
@Column({ name: 'conversation_id', type: 'uuid' })
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
|
|
||||||
@Column({
|
@Column({ length: 20 })
|
||||||
type: 'enum',
|
role: MessageRoleType;
|
||||||
enum: MessageRole,
|
|
||||||
})
|
|
||||||
role: MessageRole;
|
|
||||||
|
|
||||||
@Column({
|
@Column({ length: 30, default: 'TEXT' })
|
||||||
type: 'enum',
|
type: MessageTypeType;
|
||||||
enum: MessageType,
|
|
||||||
default: MessageType.TEXT,
|
|
||||||
})
|
|
||||||
type: MessageType;
|
|
||||||
|
|
||||||
@Column({ type: 'text' })
|
@Column({ type: 'text' })
|
||||||
content: string;
|
content: string;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue