Skip to content

Commit 9fbbd67

Browse files
committed
Fix review comments
1 parent 2432316 commit 9fbbd67

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

pkg/configs/configs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ type Config struct {
2727
// _version_ of a configuration a unique ID and guarantees that later versions
2828
// have greater IDs.
2929
type View struct {
30-
ID ID `json:"id"`
31-
Config Config `json:"config"`
32-
DeletedAt time.Time
30+
ID ID `json:"id"`
31+
Config Config `json:"config"`
32+
DeletedAt time.Time `json:"deleted_at"`
3333
}
3434

3535
// GetVersionedRulesConfig specializes the view to just the rules config.

pkg/configs/db/memory/memory.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ func (d *DB) GetConfigs(since configs.ID) (map[string]configs.View, error) {
5353
return cfgs, nil
5454
}
5555

56-
// SetDeletedAtConfig sets deletedAt for last configuration for a user.
56+
// SetDeletedAtConfig sets a deletedAt for configuration
57+
// by adding a single new row with deleted_at set
58+
// the same as SetConfig is actually insert
5759
func (d *DB) SetDeletedAtConfig(userID string, deletedAt time.Time) error {
5860
cv, err := d.GetConfig(userID)
5961
if err != nil {

pkg/configs/db/postgres/postgres.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -251,24 +251,9 @@ func (d DB) GetRulesConfigs(since configs.ID) (map[string]configs.VersionedRules
251251
})
252252
}
253253

254-
// GetLastConfig gets a last configuration (active or deleted).
255-
func (d DB) GetLastConfig(userID string) (configs.View, error) {
256-
var cfgView configs.View
257-
var cfgBytes []byte
258-
err := d.Select("id", "config").
259-
From("configs").
260-
Where(squirrel.Eq{"owner_id": userID}).
261-
OrderBy("id DESC").
262-
Limit(1).
263-
QueryRow().Scan(&cfgView.ID, &cfgBytes)
264-
if err != nil {
265-
return cfgView, err
266-
}
267-
err = json.Unmarshal(cfgBytes, &cfgView.Config)
268-
return cfgView, err
269-
}
270-
271-
// SetDeletedAtConfig sets a deletedAt for configuration.
254+
// SetDeletedAtConfig sets a deletedAt for configuration
255+
// by adding a single new row with deleted_at set
256+
// the same as SetConfig is actually insert
272257
func (d DB) SetDeletedAtConfig(userID string, deletedAt time.Time, cfg configs.Config) error {
273258
cfgBytes, err := json.Marshal(cfg)
274259
if err != nil {
@@ -283,7 +268,7 @@ func (d DB) SetDeletedAtConfig(userID string, deletedAt time.Time, cfg configs.C
283268

284269
// DeactivateConfig deactivates a configuration.
285270
func (d DB) DeactivateConfig(userID string) error {
286-
cfg, err := d.GetLastConfig(userID)
271+
cfg, err := d.GetConfig(userID)
287272
if err != nil {
288273
return err
289274
}
@@ -292,7 +277,7 @@ func (d DB) DeactivateConfig(userID string) error {
292277

293278
// RestoreConfig restores configuration.
294279
func (d DB) RestoreConfig(userID string) error {
295-
cfg, err := d.GetLastConfig(userID)
280+
cfg, err := d.GetConfig(userID)
296281
if err != nil {
297282
return err
298283
}

0 commit comments

Comments
 (0)