From eb1cb9c496d676f2d7d4d604a23b1b190041fa42 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 24 Jan 2026 22:50:54 -0800 Subject: [PATCH] fix(orm): add explicit PostgreSQL column types for nullable fields Fixed TypeORM DataTypeNotSupportedError for "Object" type in PostgreSQL. ## Issues Fixed 1. **user-service/UserORM** - fingerprint: varchar(255) - phone: varchar(20) - nickname: varchar(100) - avatar: varchar(500) 2. **payment-service/PaymentORM** - transactionId: varchar(255) - currency: varchar(10) - expiresAt: timestamptz - paidAt: timestamptz 3. **conversation-service/MessageORM** - inputTokens: int - outputTokens: int ## Root Cause @Column({ nullable: true }) without explicit `type` defaults to Object, which PostgreSQL doesn't support. Co-Authored-By: Claude Opus 4.5 --- .../database/postgres/entities/message.orm.ts | 4 ++-- .../database/postgres/entities/payment.orm.ts | 8 ++++---- .../infrastructure/database/postgres/entities/user.orm.ts | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/services/conversation-service/src/infrastructure/database/postgres/entities/message.orm.ts b/packages/services/conversation-service/src/infrastructure/database/postgres/entities/message.orm.ts index 04c451c..c29c87b 100644 --- a/packages/services/conversation-service/src/infrastructure/database/postgres/entities/message.orm.ts +++ b/packages/services/conversation-service/src/infrastructure/database/postgres/entities/message.orm.ts @@ -36,10 +36,10 @@ export class MessageORM { @Column({ type: 'jsonb', nullable: true }) metadata: Record | null; - @Column({ name: 'input_tokens', nullable: true }) + @Column({ name: 'input_tokens', type: 'int', nullable: true }) inputTokens: number | null; - @Column({ name: 'output_tokens', nullable: true }) + @Column({ name: 'output_tokens', type: 'int', nullable: true }) outputTokens: number | null; @CreateDateColumn({ name: 'created_at', type: 'timestamptz', nullable: true }) diff --git a/packages/services/payment-service/src/infrastructure/database/postgres/entities/payment.orm.ts b/packages/services/payment-service/src/infrastructure/database/postgres/entities/payment.orm.ts index 7ced119..5633358 100644 --- a/packages/services/payment-service/src/infrastructure/database/postgres/entities/payment.orm.ts +++ b/packages/services/payment-service/src/infrastructure/database/postgres/entities/payment.orm.ts @@ -20,13 +20,13 @@ export class PaymentORM { @Column({ type: 'decimal', precision: 10, scale: 2 }) amount: number; - @Column({ default: 'CNY' }) + @Column({ type: 'varchar', length: 10, default: 'CNY' }) currency: string; @Column({ type: 'varchar', length: 50, default: 'PENDING' }) status: string; - @Column({ name: 'transaction_id', nullable: true }) + @Column({ name: 'transaction_id', type: 'varchar', length: 255, nullable: true }) transactionId: string | null; @Column({ name: 'qr_code_url', type: 'text', nullable: true }) @@ -35,10 +35,10 @@ export class PaymentORM { @Column({ name: 'payment_url', type: 'text', nullable: true }) paymentUrl: string | null; - @Column({ name: 'expires_at' }) + @Column({ name: 'expires_at', type: 'timestamptz' }) expiresAt: Date; - @Column({ name: 'paid_at', nullable: true }) + @Column({ name: 'paid_at', type: 'timestamptz', nullable: true }) paidAt: Date | null; @Column({ name: 'failed_reason', type: 'text', nullable: true }) diff --git a/packages/services/user-service/src/infrastructure/database/postgres/entities/user.orm.ts b/packages/services/user-service/src/infrastructure/database/postgres/entities/user.orm.ts index 4b340c7..fe1f90d 100644 --- a/packages/services/user-service/src/infrastructure/database/postgres/entities/user.orm.ts +++ b/packages/services/user-service/src/infrastructure/database/postgres/entities/user.orm.ts @@ -22,16 +22,16 @@ export class UserORM { }) type: string; - @Column({ nullable: true }) + @Column({ type: 'varchar', length: 255, nullable: true }) fingerprint: string | null; - @Column({ nullable: true }) + @Column({ type: 'varchar', length: 20, nullable: true }) phone: string | null; - @Column({ nullable: true }) + @Column({ type: 'varchar', length: 100, nullable: true }) nickname: string | null; - @Column({ nullable: true }) + @Column({ type: 'varchar', length: 500, nullable: true }) avatar: string | null; @CreateDateColumn({ name: 'created_at' })