2
0
Просмотр исходного кода

♻️ refactor(entity): simplify timestamp column definitions in entities

- replace manual @Column with TypeORM's @CreateDateColumn and @UpdateDateColumn decorators
- remove redundant default and onUpdate properties as they are handled by the decorators automatically
- update entity documentation to reflect the simplified timestamp configuration

♻️ refactor(chat): update chat message entity timestamp columns

- simplify createdAt and updatedAt columns using TypeORM's specialized decorators
- remove unnecessary default and onUpdate properties for better maintainability
yourname 6 месяцев назад
Родитель
Сommit
91d1d6b805
2 измененных файлов с 6 добавлено и 12 удалено
  1. 4 7
      .roo/rules/10-entity.md
  2. 2 5
      src/server/modules/chat/chat-message.entity.ts

+ 4 - 7
.roo/rules/10-entity.md

@@ -84,19 +84,16 @@ isDeleted!: number;
 
 ```typescript
 // 创建时间 (自动设置)
-@Column({ 
+@CreateDateColumn({ 
   name: 'created_at',
-  type: 'timestamp', 
-  default: () => 'CURRENT_TIMESTAMP'
+  type: 'timestamp'
 })
 createdAt!: Date;
 
 // 更新时间 (自动更新)
-@Column({
+@UpdateDateColumn({
   name: 'updated_at',
-  type: 'timestamp',
-  default: () => 'CURRENT_TIMESTAMP',
-  onUpdate: 'CURRENT_TIMESTAMP' 
+  type: 'timestamp'
 })
 updatedAt!: Date;
 ```

+ 2 - 5
src/server/modules/chat/chat-message.entity.ts

@@ -59,16 +59,13 @@ export class ChatMessage {
 
   @CreateDateColumn({ 
     name: 'created_at',
-    type: 'timestamp', 
-    default: () => 'CURRENT_TIMESTAMP' 
+    type: 'timestamp'
   })
   createdAt!: Date;
 
   @UpdateDateColumn({ 
     name: 'updated_at',
-    type: 'timestamp', 
-    default: () => 'CURRENT_TIMESTAMP',
-    onUpdate: 'CURRENT_TIMESTAMP' 
+    type: 'timestamp'
   })
   updatedAt!: Date;
 }