From e28e4a8ba32a014bd2e4ba6b5afdd45ecf8b5ba8 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Sun, 19 Dec 2021 14:17:10 +0800 Subject: [PATCH] reorder fields --- attribute/attribute.go | 9 +++++---- auth/group.go | 7 ++++--- auth/user.go | 16 +++++++++------- history/history.go | 15 ++++++++------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/attribute/attribute.go b/attribute/attribute.go index ea28fbd..6700e6d 100644 --- a/attribute/attribute.go +++ b/attribute/attribute.go @@ -9,14 +9,15 @@ import ( ) type Attribute struct { - ID uint `gorm:"primaryKey"` - CreatedAt time.Time - UpdatedAt time.Time + ID uint `gorm:"primaryKey"` Key string `gorm:"unique;not null"` Description string - Default string Value string + Default string + + CreatedAt time.Time + UpdatedAt time.Time } var l zerolog.Logger diff --git a/auth/group.go b/auth/group.go index 36e0483..89ea66f 100644 --- a/auth/group.go +++ b/auth/group.go @@ -9,9 +9,7 @@ import ( //Group enum of user permission groups type Group struct { - ID uint `gorm:"primaryKey"` - CreatedAt time.Time - UpdatedAt time.Time + ID uint `gorm:"primaryKey"` // Name starting with '*' is reserved and starting with '_' is internal Name string `gorm:"unique;not null"` @@ -21,6 +19,9 @@ type Group struct { //extra fields GRPF1 string + + CreatedAt time.Time + UpdatedAt time.Time } func (grp *Group) BeforeSave(tx *gorm.DB) (err error) { diff --git a/auth/user.go b/auth/user.go index 5dd729f..37fed35 100644 --- a/auth/user.go +++ b/auth/user.go @@ -11,9 +11,7 @@ import ( //User User model type User struct { - ID string `gorm:"primaryKey"` - CreatedAt time.Time - UpdatedAt time.Time + ID string `gorm:"primaryKey"` Username string `gorm:"unique;not null"` Password string `json:"-"` @@ -27,17 +25,21 @@ type User struct { Groups []*Group `gorm:"many2many:user_groups;"` Profile Profile + + CreatedAt time.Time + UpdatedAt time.Time } // Profile user extended information type Profile struct { - ID uint `gorm:"primaryKey"` - CreatedAt time.Time - UpdatedAt time.Time - UserID string + ID uint `gorm:"primaryKey"` + UserID string DisplayName string Email string + + CreatedAt time.Time + UpdatedAt time.Time } // BeforeCreate set UID diff --git a/history/history.go b/history/history.go index 8946c2f..cb19465 100644 --- a/history/history.go +++ b/history/history.go @@ -20,13 +20,12 @@ const ( ) type History struct { - ID uint `gorm:"primaryKey"` - CreatedAt time.Time - Module string - Type string - Caller string - Trace string - BodyJson string + ID uint `gorm:"primaryKey"` + Module string + Type string + Caller string + Trace string + BodyJson string Name string Message string @@ -36,6 +35,8 @@ type History struct { Group string // Scope for users to narrow down view point Scope string + + CreatedAt time.Time } func (h *History) BeforeCreate(tx *gorm.DB) (err error) {