Skip to content

feat(api): add device identity and lifecycle columns#1029

Open
madhavilosetty-intel wants to merge 1 commit into
mainfrom
feat/device-identity-columns
Open

feat(api): add device identity and lifecycle columns#1029
madhavilosetty-intel wants to merge 1 commit into
mainfrom
feat/device-identity-columns

Conversation

@madhavilosetty-intel

@madhavilosetty-intel madhavilosetty-intel commented May 27, 2026

Copy link
Copy Markdown
Contributor

Add seven additive columns to the devices table across all three
backends (SQLite, Postgres, MongoDB) for issue #843:

  • id: app-generated UUID surrogate key; stable and immutable
  • createddate: server-set insert timestamp (RFC3339Nano); immutable
  • lastupdate: server-set on insert + refreshed on record edits; not touched by heartbeats
  • isdeleted: logical-deletion flag (column + plumbing only)
  • deleteddate: server-set soft-delete timestamp; read-only (column + plumbing only)
  • producttype: manageability SKU (vPro/ISM)
  • connectiontype: device connection type (CIRA/Direct)

id, createddate, and deleteddate are server-managed and immutable.
lastupdate is server-managed and refreshed only on the main device
Update path; the high-frequency UpdateLastSeen/connection-status
heartbeats deliberately leave it untouched to avoid write
amplification at fleet scale. A partial unique index on id enforces
dedup. DTO, OpenAPI, Postman, and tests are updated. Soft-delete
behavior (DELETE handling, read filtering) lands in a separate PR.

Resolves: #843

@madhavilosetty-intel madhavilosetty-intel requested a review from a team as a code owner May 27, 2026 16:32
@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.27848% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.66%. Comparing base (82728e6) to head (28b71a5).

Files with missing lines Patch % Lines
internal/usecase/nosqldb/mongo/client.go 0.00% 10 Missing ⚠️
internal/usecase/devices/usecase.go 76.92% 3 Missing ⚠️
internal/usecase/sqldb/device.go 97.72% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1029      +/-   ##
==========================================
+ Coverage   43.44%   43.66%   +0.22%     
==========================================
  Files         143      143              
  Lines       13621    13687      +66     
==========================================
+ Hits         5917     5977      +60     
- Misses       7143     7147       +4     
- Partials      561      563       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@madhavilosetty-intel madhavilosetty-intel force-pushed the feat/device-identity-columns branch 2 times, most recently from 07c8f53 to 6afe2b0 Compare May 29, 2026 00:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds device-identity and lifecycle columns (id, createddate, softdelete, controlmode, upid, sku, connectiontype) to the devices storage layer across all three backends (SQLite/Postgres via a new migration + sqldb repo updates, and MongoDB via the mongo repo + a partial unique index). Surfaces the new fields on the v1 dto.Device, makes id/createdDate server-managed in UseCase.Insert, and adds round-trip / immutability tests plus a Postman assertion for the server-managed identity fields.

Changes:

  • Schema + repo plumbing for the seven new columns (SQL migrations, SQL Insert/Update/Get* builders, Mongo Update $set map and partial unique idx_devices_id).
  • Use-case wiring: dtoToEntity/entityToDTO/deviceFieldSetters propagate the new fields; Insert generates id (UUID) and createdDate (RFC3339Nano UTC) server-side.
  • Tests + Postman: sqldb identity round-trip and immutability tests, mongo GetByID identity-columns test, custom gomock matcher to ignore server-set fields, Postman assertion that id/createdDate are returned.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/app/migrations/20260526000000_migrate_device_identity.up.sql Adds the 7 columns + partial unique index on id.
internal/app/migrations/20260526000000_migrate_device_identity.down.sql Drops the index and the 7 columns.
internal/entity/device.go Adds the 7 fields to the Device entity with bson tags.
internal/entity/dto/v1/device.go Exposes the 7 fields on the v1 DTO with json tags.
internal/usecase/devices/usecase.go Maps the new fields in dtoToEntity/entityToDTO and patch setters.
internal/usecase/devices/repo.go Server-generates ID (UUID) and CreatedDate on Insert.
internal/usecase/devices/repo_test.go Adds a gomock matcher that ignores server-set ID/CreatedDate.
internal/usecase/sqldb/device.go Extends Get/GetByID/GetByTags/GetByColumn/Insert/Update SQL for new columns; omits id/createddate from Update.
internal/usecase/sqldb/device_test.go Adds round-trip + immutability tests and extends in-test CREATE TABLE schemas.
internal/usecase/nosqldb/mongo/fields.go Adds fieldID constant.
internal/usecase/nosqldb/mongo/device.go Adds the new fields to the mongo Update $set map (omitting id/createddate).
internal/usecase/nosqldb/mongo/device_test.go Adds a GetByID identity-columns test.
internal/usecase/nosqldb/mongo/client.go Creates partial unique index idx_devices_id mirroring the SQL one.
internal/controller/httpapi/v1/devices_test.go Marks softdelete as always-present (no omitempty) in PATCH expectations.
integration-test/collections/console_mps_apis.postman_collection.json Asserts id/createdDate are returned by the relevant endpoint.

Comment thread internal/app/migrations/20260526000000_migrate_device_identity.up.sql Outdated
Comment thread internal/entity/dto/v1/device.go
Comment thread internal/usecase/devices/repo.go Outdated
@madhavilosetty-intel madhavilosetty-intel force-pushed the feat/device-identity-columns branch from c2cc9a6 to 6b6866c Compare May 29, 2026 00:54
Comment thread internal/entity/dto/v1/device.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Comment thread internal/usecase/sqldb/device.go Outdated
@madhavilosetty-intel madhavilosetty-intel force-pushed the feat/device-identity-columns branch from 34633ae to a778742 Compare June 1, 2026 19:04
@sudhir-intc sudhir-intc self-requested a review June 18, 2026 04:08
@madhavilosetty-intel madhavilosetty-intel force-pushed the feat/device-identity-columns branch 2 times, most recently from df97bd2 to 33a5ca7 Compare June 20, 2026 02:54
Add seven additive columns to the devices table across all three
backends (SQLite, Postgres, MongoDB) for issue #843:

- id: app-generated UUID surrogate key; stable and immutable
- createddate: server-set insert timestamp (RFC3339Nano); immutable
- lastupdate: server-set on insert + refreshed on record edits; not touched by heartbeats
- isdeleted: logical-deletion flag (column + plumbing only)
- deleteddate: server-set soft-delete timestamp; read-only (column + plumbing only)
- producttype: manageability SKU (vPro/ISM)
- connectiontype: device connection type (CIRA/Direct)

id, createddate, and deleteddate are server-managed and immutable.
lastupdate is server-managed and refreshed only on the main device
Update path; the high-frequency UpdateLastSeen/connection-status
heartbeats deliberately leave it untouched to avoid write
amplification at fleet scale. A partial unique index on id enforces
dedup. DTO, OpenAPI, Postman, and tests are updated. Soft-delete
behavior (DELETE handling, read filtering) lands in a separate PR.

Resolves: #843
@madhavilosetty-intel madhavilosetty-intel force-pushed the feat/device-identity-columns branch from 33a5ca7 to 28b71a5 Compare June 22, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Device Management and Configuration

3 participants