Skip to content

Commit 8717c5c

Browse files
committed
fix(pg): scope settings upsert updates to mutable columns
1 parent f361dd6 commit 8717c5c

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

api/store/pg/device.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ func (pg *Pg) DeviceUpdate(ctx context.Context, device *models.Device) error {
181181
settings := entity.DeviceSettingsFromModel(device.SSH, device.UID)
182182
settings.UpdatedAt = clock.Now()
183183

184-
_, err = db.NewInsert().On("conflict (device_id) do update").Model(&settings).Exec(ctx)
184+
_, err = db.NewInsert().
185+
On("conflict (device_id) do update set updated_at = excluded.updated_at, allow_password = excluded.allow_password, allow_public_key = excluded.allow_public_key, allow_root = excluded.allow_root, allow_empty_passwords = excluded.allow_empty_passwords, allow_tty = excluded.allow_tty, allow_tcp_forwarding = excluded.allow_tcp_forwarding, allow_web_endpoints = excluded.allow_web_endpoints, allow_sftp = excluded.allow_sftp, allow_agent_forwarding = excluded.allow_agent_forwarding").
186+
Model(&settings).
187+
Exec(ctx)
185188
if err != nil {
186189
return fromSQLError(err)
187190
}

api/store/pg/namespace.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ func (pg *Pg) NamespaceUpdate(ctx context.Context, namespace *models.Namespace)
184184

185185
if n.Settings != nil {
186186
n.Settings.UpdatedAt = clock.Now()
187-
_, err = db.NewInsert().On("conflict (namespace_id) do update").Model(n.Settings).Exec(ctx)
187+
_, err = db.NewInsert().
188+
On("conflict (namespace_id) do update set updated_at = excluded.updated_at, record_sessions = excluded.record_sessions, connection_announcement = excluded.connection_announcement, allow_password = excluded.allow_password, allow_public_key = excluded.allow_public_key, allow_root = excluded.allow_root, allow_empty_passwords = excluded.allow_empty_passwords, allow_tty = excluded.allow_tty, allow_tcp_forwarding = excluded.allow_tcp_forwarding, allow_web_endpoints = excluded.allow_web_endpoints, allow_sftp = excluded.allow_sftp, allow_agent_forwarding = excluded.allow_agent_forwarding").
189+
Model(n.Settings).
190+
Exec(ctx)
188191
if err != nil {
189192
return fromSQLError(err)
190193
}

0 commit comments

Comments
 (0)