Skip to content

Device Lifecycle ​

Device decommissioning is reversible and does not delete device records, telemetry, attributes, alarms, or command history. A decommissioned device is marked lifecycle_state = 'DECOMMISSIONED', its activity status becomes INACTIVE, its current token is replaced, and its WebSocket and Modbus tunnel sessions are disconnected. The former token is never returned by list, detail, or restore responses.

Restore creates another fresh device token and is allowed only when the tenant's plan/license has an available device slot, no active device uses the same case-insensitive name, and any assigned parent is an active gateway. The new token is returned once by the restore endpoint. It is not recoverable afterward; use the existing deliberate token-reveal flow when necessary.

GET /api/devices and GET /api/devices/types omit decommissioned records by default. Pass includeDecommissioned=true to include them. Device-specific attribute and key reads continue to require the requesting user's device scope. Attribute writes and deletes reject read-only users and decommissioned devices; token-authenticated traffic is also rejected after decommissioning. One exception: Detach (PATCH with only assetId: null) is allowed on a decommissioned device so a SITE/AREA/ZONE can be deleted without Restore. That clears the asset link only — it does not restore the device, reissue a token, or delete telemetry/history.

The device name index is unique per tenant among active devices. Archived records remain in the database with their original names, so a new active device may reuse a decommissioned name. Restoring then requires resolving that name conflict first.

API behavior ​

Method and routeBehavior
GET /api/devices?includeDecommissioned=trueInclude archived devices in the device list.
GET /api/devices/types?includeDecommissioned=trueInclude archived devices when collecting device types.
POST /api/devices/:id/decommissionDecommission an active device.
POST /api/devices/:id/restoreRestore an archived device and return its newly issued token once.

Lifecycle actions require write access to the individual device in addition to a writable tenant role. Attribute and key reads require access to that device; attribute saves and deletes require device write access and are rejected for read-only users or decommissioned devices.

Database migration and rollback ​

0050_device_lifecycle.sql adds the lifecycle columns, constraint, and index. 0082_device_lifecycle_active_names.sql updates installations that applied the initial lifecycle migration before active-only name reuse was introduced. Apply only the required lifecycle migration(s); do not run unrelated pending migrations.

To roll back 0082, first check for name conflicts among active and decommissioned rows. Rename conflicts before restoring the former all-device unique index:

sql
DROP INDEX IF EXISTS uq_devices_tenant_lower_name_active;
CREATE UNIQUE INDEX uq_devices_tenant_lower_name
  ON devices (tenant_id, LOWER(device_name));

To roll back the lifecycle schema, first restore every decommissioned device through the application so it has a fresh valid token. Then recreate the all-device unique index above, remove idx_devices_tenant_lifecycle_state, drop devices_lifecycle_state_check, and drop lifecycle_state, decommissioned_at, and decommissioned_by. This removes lifecycle metadata; it does not delete telemetry or other history. Do not recover or reuse a pre-decommission token.

support@autoconnecto.in · founder@autoconnecto.in · +91 92121 00555 · app.autoconnecto.in