mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-27 20:56:44 +00:00
MySQL Hooks
This commit is contained in:
32
management/server/sql_hooks.go
Normal file
32
management/server/sql_hooks.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func GetDefaultTimezone() time.Time {
|
||||
return time.Date(1, 1, 1, 1, 1, 1, 1, time.Local)
|
||||
}
|
||||
|
||||
func (u *SetupKey) BeforeSave(tx *gorm.DB) (err error) {
|
||||
|
||||
if u.CreatedAt.IsZero() {
|
||||
u.CreatedAt = GetDefaultTimezone()
|
||||
}
|
||||
|
||||
if u.ExpiresAt.IsZero() {
|
||||
u.ExpiresAt = GetDefaultTimezone()
|
||||
}
|
||||
|
||||
if u.UpdatedAt.IsZero() {
|
||||
u.UpdatedAt = GetDefaultTimezone()
|
||||
}
|
||||
|
||||
if u.LastUsed.IsZero() {
|
||||
u.LastUsed = GetDefaultTimezone()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user