fix(conversation): add indexes and fix column types to match database
- Add @Index decorators for conversation_id, created_at, role - Set created_at to timestamptz type to match database - Set columns nullable to match database schema This prevents synchronize:true from trying to modify columns that have dependent indexes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a821df8dc1
commit
6718fdc9e3
|
|
@ -5,6 +5,7 @@ import {
|
||||||
CreateDateColumn,
|
CreateDateColumn,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
JoinColumn,
|
JoinColumn,
|
||||||
|
Index,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { ConversationEntity } from './conversation.entity';
|
import { ConversationEntity } from './conversation.entity';
|
||||||
|
|
||||||
|
|
@ -35,11 +36,14 @@ export const MessageType = {
|
||||||
export type MessageTypeType = (typeof MessageType)[keyof typeof MessageType];
|
export type MessageTypeType = (typeof MessageType)[keyof typeof MessageType];
|
||||||
|
|
||||||
@Entity('messages')
|
@Entity('messages')
|
||||||
|
@Index('idx_messages_conversation_id', ['conversationId'])
|
||||||
|
@Index('idx_messages_created_at', ['createdAt'])
|
||||||
|
@Index('idx_messages_role', ['role'])
|
||||||
export class MessageEntity {
|
export class MessageEntity {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ name: 'conversation_id', type: 'uuid' })
|
@Column({ name: 'conversation_id', type: 'uuid', nullable: true })
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
|
|
||||||
@Column({ length: 20 })
|
@Column({ length: 20 })
|
||||||
|
|
@ -56,13 +60,13 @@ export class MessageEntity {
|
||||||
|
|
||||||
// ========== Token统计字段(与evolution-service保持一致)==========
|
// ========== Token统计字段(与evolution-service保持一致)==========
|
||||||
|
|
||||||
@Column({ name: 'input_tokens', default: 0 })
|
@Column({ name: 'input_tokens', nullable: true })
|
||||||
inputTokens: number;
|
inputTokens: number;
|
||||||
|
|
||||||
@Column({ name: 'output_tokens', default: 0 })
|
@Column({ name: 'output_tokens', nullable: true })
|
||||||
outputTokens: number;
|
outputTokens: number;
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'created_at' })
|
@CreateDateColumn({ name: 'created_at', type: 'timestamptz', nullable: true })
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
@ManyToOne(() => ConversationEntity, (conversation) => conversation.messages)
|
@ManyToOne(() => ConversationEntity, (conversation) => conversation.messages)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue