Skip to content
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

MG-2354 - Fix Update Bootstrap Config State #2356

Merged
merged 9 commits into from
Jul 25, 2024
11 changes: 7 additions & 4 deletions bootstrap/postgres/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,10 @@ func (cr configRepository) RemoveChannel(ctx context.Context, id string) error {
}

func (cr configRepository) ConnectThing(ctx context.Context, channelID, thingID string) error {
q := `UPDATE configs SET state = $1 WHERE EXISTS (
SELECT 1 FROM connections WHERE config_id = $2 AND channel_id = $3)`
q := `UPDATE configs SET state = $1
WHERE magistrala_thing = $2
AND EXISTS (SELECT 1 FROM connections WHERE config_id = $2 AND channel_id = $3)`

result, err := cr.db.ExecContext(ctx, q, bootstrap.Active, thingID, channelID)
if err != nil {
return errors.Wrap(errConnectThing, err)
Expand All @@ -473,8 +475,9 @@ func (cr configRepository) ConnectThing(ctx context.Context, channelID, thingID
}

func (cr configRepository) DisconnectThing(ctx context.Context, channelID, thingID string) error {
q := `UPDATE configs SET state = $1 WHERE EXISTS (
SELECT 1 FROM connections WHERE config_id = $2 AND channel_id = $3)`
q := `UPDATE configs SET state = $1
WHERE magistrala_thing = $2
AND EXISTS (SELECT 1 FROM connections WHERE config_id = $2 AND channel_id = $3)`
_, err := cr.db.ExecContext(ctx, q, bootstrap.Inactive, thingID, channelID)
if err != nil {
return errors.Wrap(errDisconnectThing, err)
Expand Down
Loading