feat(api): add device identity and lifecycle columns#1029
feat(api): add device identity and lifecycle columns#1029madhavilosetty-intel wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1029 +/- ##
==========================================
+ Coverage 41.69% 41.87% +0.17%
==========================================
Files 135 135
Lines 12354 12466 +112
==========================================
+ Hits 5151 5220 +69
- Misses 6656 6699 +43
Partials 547 547 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
07c8f53 to
6afe2b0
Compare
There was a problem hiding this comment.
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, MongoUpdate$setmap and partial uniqueidx_devices_id). - Use-case wiring:
dtoToEntity/entityToDTO/deviceFieldSetterspropagate the new fields;Insertgeneratesid(UUID) andcreatedDate(RFC3339Nano UTC) server-side. - Tests + Postman: sqldb identity round-trip and immutability tests, mongo
GetByIDidentity-columns test, custom gomock matcher to ignore server-set fields, Postman assertion thatid/createdDateare 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. |
| ID string `json:"id,omitempty"` // server-managed surrogate key; read-only | ||
| CreatedDate string `json:"createdDate,omitempty"` // server-set on insert; read-only | ||
| SoftDelete bool `json:"softDelete"` // no omitempty: emit false to distinguish from absent | ||
| ControlMode string `json:"controlMode,omitempty"` // AMT control mode (ACM/CCM) | ||
| UPID string `json:"upid,omitempty"` // device Unique Platform ID | ||
| SKU string `json:"sku,omitempty"` // manageability SKU (vPro/ISM) | ||
| ConnectionType string `json:"connectionType,omitempty"` // device connection type (CIRA/Direct) |
| // id and createddate are server-managed: a stable surrogate key and | ||
| // the insertion timestamp. Client-supplied values are ignored. Nanosecond | ||
| // precision (UTC) keeps the string lexicographically sortable and avoids | ||
| // collisions when many devices are added within the same second. | ||
| d1.ID = uuid.New().String() | ||
| d1.CreatedDate = time.Now().UTC().Format(time.RFC3339Nano) |
Adds seven additive columns to the devices table across all three backends (SQLite, Postgres, MongoDB) for issue #843 part 2: - id: app-generated surrogate key (UUID), stable and immutable - createddate: server-set insertion timestamp (RFC3339Nano), immutable - softdelete: logical-deletion flag (column + plumbing only) - controlmode: AMT control mode (ACM/CCM) - upid: device Unique Platform ID - sku: manageability SKU (vPro/ISM) - connectiontype: device connection type (CIRA/Direct) id and createddate are server-managed and immutable: they are set in UseCase.Insert, omitted from the UPDATE/$set paths, and absent from the PATCH field setters. The remaining columns are client-mutable. A partial unique index on id (SQL: WHERE id <> ''; Mongo: $gt "") enforces surrogate-key dedup while excluding backfilled legacy rows.
c2cc9a6 to
6b6866c
Compare
| CreatedDate string `json:"createdDate,omitempty"` // server-set on insert; read-only | ||
| SoftDelete bool `json:"softDelete"` // no omitempty: emit false to distinguish from absent | ||
| ControlMode string `json:"controlMode,omitempty"` // AMT control mode (ACM/CCM) | ||
| UPID string `json:"upid,omitempty"` // device Unique Platform ID |
There was a problem hiding this comment.
As part of the Discovery ADR https://github.com/device-management-toolkit/console/wiki/ADR-discovery we agreed to have UPID as part of the DeviceInfo also the UPID format is as below returned by amtinfo. How are you planning to convert this to a string.
{"oemPlatformIdType":"Not Set (0)","oemId":"","csmeId":"4A45A39C5ED94620…82510000"}
Adds seven additive columns to the devices table across all three
backends (SQLite, Postgres, MongoDB) for issue #843
id and createddate are server-managed and immutable: they are set in
UseCase.Insert, omitted from the UPDATE/$set paths, and absent from the
PATCH field setters. The remaining columns are client-mutable. A partial
unique index on id (SQL: WHERE id <> ''; Mongo: $gt "") enforces
surrogate-key dedup while excluding backfilled legacy rows.