-
Notifications
You must be signed in to change notification settings - Fork 837
Scan deletedAt (time or null) in findConfigs, findRulesConfigs and GetConfig #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this. Why can't the zero time stand for "null" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot store nil time into time.Time variable.
Added description of the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The zero value is time.Time{}, and can be checked like DeletedAt.IsZero()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use another variable to scan but I think it will complicate code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, PTAL
pkg/configs/db/postgres/postgres.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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