Manager: ensure Gorm-generated timestamps are in UTC

SQLite should store all timestamps in UTC, as the database is woefully
unaware of timezones and will compare lexicographically.
This commit is contained in:
Sybren A. Stüvel 2022-06-10 14:30:30 +02:00
parent 24204084c1
commit 295891a17a

@ -49,7 +49,8 @@ func openDB(ctx context.Context, dsn string) (*DB, error) {
dblogger := NewDBLogger(log.Level(globalLogLevel))
config := gorm.Config{
Logger: dblogger,
Logger: dblogger,
NowFunc: nowFunc,
}
return openDBWithConfig(dsn, &config)
@ -79,6 +80,12 @@ func openDBWithConfig(dsn string, config *gorm.Config) (*DB, error) {
return &db, nil
}
// nowFunc returns 'now' in UTC, so that GORM-managed times (createdAt,
// deletedAt, updatedAt) are stored in UTC.
func nowFunc() time.Time {
return time.Now().UTC()
}
// PeriodicMaintenanceLoop periodically vacuums the database.
// This function only returns when the context is done.
func (db *DB) PeriodicMaintenanceLoop(ctx context.Context) {