From 011fc2340a857422477e43f4ae33ccf4d8ed230d Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 23 Oct 2022 23:53:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=97=A5=E6=9C=9F=E5=BD=92=E9=9B=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/common.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/model/common.go b/model/common.go index fc51e7c..a3628da 100644 --- a/model/common.go +++ b/model/common.go @@ -1,6 +1,7 @@ package model import ( + "gorm.io/gorm" "time" ) @@ -9,10 +10,10 @@ const CtxKeyViewPasswordVerified = "ckvpv" const CacheKeyOauth2State = "p:a:state" type Common struct { - ID uint64 `gorm:"primaryKey"` - CreatedAt time.Time `sql:"index"` - UpdatedAt time.Time - DeletedAt *time.Time `sql:"index"` + ID uint64 `gorm:"primaryKey"` + CreatedAt time.Time `gorm:"<-:create"` + UpdatedAt time.Time `gorm:"autoUpdateTime"` + DeletedAt gorm.DeletedAt `gorm:"index"` } type Response struct { From 51655a09a1f19fb9042f94db46fd9a4e0a0bb1b0 Mon Sep 17 00:00:00 2001 From: naiba Date: Mon, 24 Oct 2022 04:12:51 +0000 Subject: [PATCH 2/2] gorm: CreatedAt index --- model/common.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/model/common.go b/model/common.go index a3628da..3341e54 100644 --- a/model/common.go +++ b/model/common.go @@ -1,8 +1,9 @@ package model import ( - "gorm.io/gorm" "time" + + "gorm.io/gorm" ) const CtxKeyAuthorizedUser = "ckau" @@ -11,7 +12,7 @@ const CacheKeyOauth2State = "p:a:state" type Common struct { ID uint64 `gorm:"primaryKey"` - CreatedAt time.Time `gorm:"<-:create"` + CreatedAt time.Time `gorm:"index;<-:create"` UpdatedAt time.Time `gorm:"autoUpdateTime"` DeletedAt gorm.DeletedAt `gorm:"index"` }