fix(sync): offline detector wiped device name, auto_sync, and metadata on every transition
setOfflineMode/setOnlineMode only mean to flip sync_enabled, but they called the full-row UpdateDevice with Go zero values — which wrote DeviceName: "" and NULLed auto_sync/sync_frequency_minutes/ device_metadata on the device row at every offline->online flip. New targeted SetDeviceSyncEnabled query touches exactly that column; the real settings update keeps using UpdateDevice. Caught as part of the H4 helper-census pass (plan §5.4 erasure list).
This commit is contained in:
1 parent
188ae076ab
commit
082a3e0c3c
4 files changed
+53
-6
No files matched your search
@@ -526,6 +526,7 @@ type Querier interface {
|
|||||||
SearchNarratorValues(ctx context.Context, arg SearchNarratorValuesParams) ([]SearchNarratorValuesRow, error)
|
SearchNarratorValues(ctx context.Context, arg SearchNarratorValuesParams) ([]SearchNarratorValuesRow, error)
|
||||||
SearchSeriesValues(ctx context.Context, arg SearchSeriesValuesParams) ([]SearchSeriesValuesRow, error)
|
SearchSeriesValues(ctx context.Context, arg SearchSeriesValuesParams) ([]SearchSeriesValuesRow, error)
|
||||||
SearchTagsValues(ctx context.Context, arg SearchTagsValuesParams) ([]SearchTagsValuesRow, error)
|
SearchTagsValues(ctx context.Context, arg SearchTagsValuesParams) ([]SearchTagsValuesRow, error)
|
||||||
|
SetDeviceSyncEnabled(ctx context.Context, arg SetDeviceSyncEnabledParams) (Devices, error)
|
||||||
// Library Visibility queries
|
// Library Visibility queries
|
||||||
SetLibraryVisibility(ctx context.Context, arg SetLibraryVisibilityParams) (LibraryVisibility, error)
|
SetLibraryVisibility(ctx context.Context, arg SetLibraryVisibilityParams) (LibraryVisibility, error)
|
||||||
// Set system config
|
// Set system config
|
||||||
|
|||||||
@@ -13116,6 +13116,42 @@ func (q *Queries) SearchTagsValues(ctx context.Context, arg SearchTagsValuesPara
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SetDeviceSyncEnabled = `-- name: SetDeviceSyncEnabled :one
|
||||||
|
UPDATE devices
|
||||||
|
SET
|
||||||
|
sync_enabled = $2,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE id = $1
|
||||||
|
RETURNING id, user_id, device_name, device_type, device_identifier, auth_token, last_sync, last_seen, sync_enabled, auto_sync, sync_frequency_minutes, device_metadata, created_at, updated_at
|
||||||
|
`
|
||||||
|
|
||||||
|
type SetDeviceSyncEnabledParams struct {
|
||||||
|
ID pgtype.UUID `db:"id" json:"id"`
|
||||||
|
SyncEnabled pgtype.Bool `db:"sync_enabled" json:"sync_enabled"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) SetDeviceSyncEnabled(ctx context.Context, arg SetDeviceSyncEnabledParams) (Devices, error) {
|
||||||
|
row := q.db.QueryRow(ctx, SetDeviceSyncEnabled, arg.ID, arg.SyncEnabled)
|
||||||
|
var i Devices
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.UserID,
|
||||||
|
&i.DeviceName,
|
||||||
|
&i.DeviceType,
|
||||||
|
&i.DeviceIdentifier,
|
||||||
|
&i.AuthToken,
|
||||||
|
&i.LastSync,
|
||||||
|
&i.LastSeen,
|
||||||
|
&i.SyncEnabled,
|
||||||
|
&i.AutoSync,
|
||||||
|
&i.SyncFrequencyMinutes,
|
||||||
|
&i.DeviceMetadata,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const SetLibraryVisibility = `-- name: SetLibraryVisibility :one
|
const SetLibraryVisibility = `-- name: SetLibraryVisibility :one
|
||||||
INSERT INTO library_visibility (user_id, library_id, is_visible)
|
INSERT INTO library_visibility (user_id, library_id, is_visible)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
|
|||||||
@@ -1669,6 +1669,14 @@ SET
|
|||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
RETURNING *;
|
RETURNING *;
|
||||||
|
|
||||||
|
-- name: SetDeviceSyncEnabled :one
|
||||||
|
UPDATE devices
|
||||||
|
SET
|
||||||
|
sync_enabled = $2,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE id = $1
|
||||||
|
RETURNING *;
|
||||||
|
|
||||||
-- name: UpdateDeviceLastSeen :one
|
-- name: UpdateDeviceLastSeen :one
|
||||||
UPDATE devices
|
UPDATE devices
|
||||||
SET
|
SET
|
||||||
|
|||||||
@@ -133,11 +133,12 @@ func (d *OfflineDetector) handleReconnectedDevice(ctx context.Context, status De
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *OfflineDetector) setOfflineMode(ctx context.Context, deviceID pgtype.UUID) {
|
func (d *OfflineDetector) setOfflineMode(ctx context.Context, deviceID pgtype.UUID) {
|
||||||
_, err := d.db.UpdateDevice(ctx, database.UpdateDeviceParams{
|
// Targeted flip: the full-row UpdateDevice used here zeroed the
|
||||||
|
// device name, auto_sync, frequency, and metadata on every
|
||||||
|
// transition (pg zero values are not "leave alone").
|
||||||
|
_, err := d.db.SetDeviceSyncEnabled(ctx, database.SetDeviceSyncEnabledParams{
|
||||||
ID: deviceID,
|
ID: deviceID,
|
||||||
DeviceName: "",
|
|
||||||
SyncEnabled: pgtype.Bool{Bool: false, Valid: true},
|
SyncEnabled: pgtype.Bool{Bool: false, Valid: true},
|
||||||
AutoSync: pgtype.Bool{},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -146,11 +147,12 @@ func (d *OfflineDetector) setOfflineMode(ctx context.Context, deviceID pgtype.UU
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *OfflineDetector) setOnlineMode(ctx context.Context, deviceID pgtype.UUID) {
|
func (d *OfflineDetector) setOnlineMode(ctx context.Context, deviceID pgtype.UUID) {
|
||||||
_, err := d.db.UpdateDevice(ctx, database.UpdateDeviceParams{
|
// Targeted flip: the full-row UpdateDevice used here zeroed the
|
||||||
|
// device name, auto_sync, frequency, and metadata on every
|
||||||
|
// transition (pg zero values are not "leave alone").
|
||||||
|
_, err := d.db.SetDeviceSyncEnabled(ctx, database.SetDeviceSyncEnabledParams{
|
||||||
ID: deviceID,
|
ID: deviceID,
|
||||||
DeviceName: "",
|
|
||||||
SyncEnabled: pgtype.Bool{Bool: true, Valid: true},
|
SyncEnabled: pgtype.Bool{Bool: true, Valid: true},
|
||||||
AutoSync: pgtype.Bool{},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user