From 6a6a662a2ea6ad7aa2a5587ee38b64346e8396fc Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Sat, 23 May 2026 14:36:51 +0200 Subject: [PATCH] fix(db): store CreatedAt/UpdatedAt in milliseconds GORM's autoCreateTime/autoUpdateTime tags default to Unix seconds on int64 fields and overwrite the service-supplied UnixMilli value on save. The frontend interprets these timestamps as JS Date inputs (milliseconds), so created/updated columns rendered ~1970 dates. Adding the :milli qualifier makes GORM match what the service code and UI expect. --- database/model/model.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/database/model/model.go b/database/model/model.go index a2ef1da3..99566d9d 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -144,7 +144,7 @@ type ApiToken struct { Name string `json:"name" gorm:"uniqueIndex;not null"` Token string `json:"token" gorm:"not null"` Enabled bool `json:"enabled" gorm:"default:true"` - CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime"` + CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"` } // MarshalJSON emits settings, streamSettings, and sniffing as nested JSON @@ -275,8 +275,8 @@ type Node struct { OnlineCount int `json:"onlineCount" gorm:"-"` DepletedCount int `json:"depletedCount" gorm:"-"` - CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime"` - UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime"` + CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"` + UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"` } type CustomGeoResource struct { @@ -287,8 +287,8 @@ type CustomGeoResource struct { LocalPath string `json:"localPath" gorm:"column:local_path"` LastUpdatedAt int64 `json:"lastUpdatedAt" gorm:"default:0;column:last_updated_at"` LastModified string `json:"lastModified" gorm:"column:last_modified"` - CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime;column:created_at"` - UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime;column:updated_at"` + CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli;column:created_at"` + UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli;column:updated_at"` } type ClientReverse struct { @@ -333,8 +333,8 @@ type ClientRecord struct { TgID int64 `json:"tgId" gorm:"column:tg_id"` Comment string `json:"comment"` Reset int `json:"reset" gorm:"default:0"` - CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime"` - UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime"` + CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"` + UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"` } func (ClientRecord) TableName() string { return "clients" } @@ -374,7 +374,7 @@ type ClientInbound struct { ClientId int `json:"clientId" gorm:"primaryKey;column:client_id;index"` InboundId int `json:"inboundId" gorm:"primaryKey;column:inbound_id;index"` FlowOverride string `json:"flowOverride" gorm:"column:flow_override"` - CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime"` + CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"` } func (ClientInbound) TableName() string { return "client_inbounds" }