fix: store registry page timestamps in UTC

- GORM stamped created_at and updated_at in the process's local time,
  which the timestamp columns keep as the wall clock; east of UTC a page
  without a content date got a sitemap lastmod in the future
- Page.BeforeSave stamps both in UTC for the admin's and the API's saves,
  and the admin's address change writes updated_at in UTC
This commit is contained in:
Jakub Zych
2026-11-04 19:24:15 +01:00
parent 49cc241f58
commit dfc85bc805
3 changed files with 70 additions and 3 deletions

View File

@@ -52,8 +52,21 @@ type Page struct {
ContentUpdatedAt *lagoon.Date `gorm:"column:content_updated_at"`
ReportedAt *time.Time `gorm:"column:reported_at"`
Note string `gorm:"column:note"`
CreatedAt *time.Time `gorm:"column:created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at"`
CreatedAt *time.Time `gorm:"column:created_at;autoCreateTime:false"`
UpdatedAt *time.Time `gorm:"column:updated_at;autoUpdateTime:false"`
}
// BeforeSave stamps UpdatedAt (and CreatedAt of a new row) in UTC on every
// save, the admin's and the API's. GORM's own timestamps use the process's
// local time, which a timestamp column stores as the wall clock: on a
// machine east of UTC that put the page's sitemap lastmod in the future.
func (p *Page) BeforeSave(*gorm.DB) error {
now := time.Now().UTC()
if p.CreatedAt == nil || p.CreatedAt.IsZero() {
p.CreatedAt = &now
}
p.UpdatedAt = &now
return nil
}
func (Page) TableName() string { return "golem15_seo_pages" }