@@ -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
272257func (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.
285270func (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.
294279func (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