Scan deletedAt (time or null) in findConfigs, findRulesConfigs and GetConfig#683
Scan deletedAt (time or null) in findConfigs, findRulesConfigs and GetConfig#683
Conversation
|
Please give more explanation of the issue - this is a public repo so you can't just link to a private one. |
pkg/configs/configs.go
Outdated
There was a problem hiding this comment.
I don't understand this. Why can't the zero time stand for "null" ?
There was a problem hiding this comment.
We cannot store nil time into time.Time variable.
Added description of the PR.
There was a problem hiding this comment.
The zero value is time.Time{}, and can be checked like DeletedAt.IsZero()
There was a problem hiding this comment.
Yes, zero time can stand for null, but opposite doesn't work: null cannot stand for zero time when I scan values from DB:
panic: sql: Scan error on column index 2: unsupported Scan, storing driver.Value type <nil> into type *time.Time
There was a problem hiding this comment.
Fine; use a DB-related type in the DB code but don't export it into the rest of the code.
There was a problem hiding this comment.
We can use another variable to scan but I think it will complicate code.
There was a problem hiding this comment.
Putting an unfamiliar type in this struct is a huge overhead to understanding. Adding an extra variable in the scan code, which already has several variables for scanning only, is easy to understand.
pkg/configs/db/postgres/postgres.go
Outdated
There was a problem hiding this comment.
This cfg.DeletedAt has to be time or null to be able to store null time from DB.
pkg/configs/db/postgres/postgres.go
Outdated
There was a problem hiding this comment.
This cfg.DeletedAt has to be time or null to be able to store null time from DB.
Add
deleted_attoGetConfig,findConfigsandfindRulesConfigsfunctions so they can return actual value ofdeleted_atfor later use in ruler. Otherwise, ruler never discoveries deleted configs and never delete them from the map.By default
deleted_atcolumn in DB set toNULLso we scan this intopq.NullTimevariable (because we cannot storenilvalue into typetime.Time).To restore config we set
deleted_atcolumn in DB toNULL.fixes https://github.com/weaveworks/service-conf/issues/1859