-
Notifications
You must be signed in to change notification settings - Fork 12
feat(api): add device identity and lifecycle columns #1029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
madhavilosetty-intel
wants to merge
1
commit into
main
Choose a base branch
from
feat/device-identity-columns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
internal/app/migrations/20260526000000_migrate_device_identity.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /********************************************************************* | ||
| * Copyright (c) Intel Corporation 2026 | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| **********************************************************************/ | ||
|
|
||
| DROP INDEX IF EXISTS idx_devices_id; | ||
| ALTER TABLE devices DROP COLUMN connectiontype; | ||
| ALTER TABLE devices DROP COLUMN producttype; | ||
| ALTER TABLE devices DROP COLUMN deleteddate; | ||
| ALTER TABLE devices DROP COLUMN isdeleted; | ||
| ALTER TABLE devices DROP COLUMN createddate; | ||
| ALTER TABLE devices DROP COLUMN id; |
22 changes: 22 additions & 0 deletions
22
internal/app/migrations/20260526000000_migrate_device_identity.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /********************************************************************* | ||
| * Copyright (c) Intel Corporation 2026 | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| **********************************************************************/ | ||
|
|
||
| -- Device identity & lifecycle columns (issue #843). | ||
| -- All TEXT columns are NOT NULL DEFAULT '' so the ALTER backfills existing | ||
| -- rows with a non-NULL value (the modernc sqlite driver cannot scan NULL into | ||
| -- a Go string). `id` is an app-generated surrogate key; the partial unique | ||
| -- index excludes the backfilled empty values on pre-existing rows. | ||
| -- createddate: server-set insert timestamp. isdeleted/deleteddate: logical- | ||
| -- deletion flag + server-set timestamp (column + plumbing only; soft-delete | ||
| -- behavior lands in a separate PR). producttype: manageability SKU (vPro/ISM). | ||
| -- connectiontype: CIRA/Direct. | ||
| ALTER TABLE devices ADD COLUMN id TEXT NOT NULL DEFAULT ''; | ||
| ALTER TABLE devices ADD COLUMN createddate TEXT NOT NULL DEFAULT ''; | ||
| ALTER TABLE devices ADD COLUMN isdeleted BOOLEAN NOT NULL DEFAULT FALSE; | ||
| ALTER TABLE devices ADD COLUMN deleteddate TEXT NOT NULL DEFAULT ''; | ||
| ALTER TABLE devices ADD COLUMN producttype TEXT NOT NULL DEFAULT ''; | ||
| ALTER TABLE devices ADD COLUMN connectiontype TEXT NOT NULL DEFAULT ''; | ||
|
madhavilosetty-intel marked this conversation as resolved.
|
||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_devices_id ON devices (id) WHERE id <> ''; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package dto | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestDevice_JSONContract locks two intentional serialization decisions for the | ||
| // identity/lifecycle columns on the /api/v1 device shape: | ||
| // - isDeleted has NO omitempty, so it is always emitted and callers can | ||
| // distinguish a false value from an absent field. | ||
| // - the other new fields ARE omitempty, so they stay absent on empty/legacy | ||
| // payloads and don't change the wire shape existing v1 consumers expect. | ||
| func TestDevice_JSONContract(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| t.Run("zero value emits isDeleted but omits optional identity fields", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| out := deviceJSONFields(t, Device{}) | ||
|
|
||
| require.Contains(t, out, "isDeleted", "isDeleted must always be present") | ||
| require.JSONEq(t, `false`, string(out["isDeleted"])) | ||
|
|
||
| for _, k := range []string{"id", "createdDate", "deletedDate", "productType", "connectionType"} { | ||
| require.NotContains(t, out, k, "%s must be omitempty on an empty device", k) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("populated values serialize under the expected keys", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| out := deviceJSONFields(t, Device{ | ||
| ID: "id-1", | ||
| CreatedDate: "2026-05-26T12:00:00Z", | ||
| IsDeleted: true, | ||
| DeletedDate: "2026-05-27T08:00:00Z", | ||
| ProductType: "vpro", | ||
| ConnectionType: "CIRA", | ||
| }) | ||
|
|
||
| require.JSONEq(t, `"id-1"`, string(out["id"])) | ||
| require.JSONEq(t, `"2026-05-26T12:00:00Z"`, string(out["createdDate"])) | ||
| require.JSONEq(t, `true`, string(out["isDeleted"])) | ||
| require.JSONEq(t, `"2026-05-27T08:00:00Z"`, string(out["deletedDate"])) | ||
| require.JSONEq(t, `"vpro"`, string(out["productType"])) | ||
| require.JSONEq(t, `"CIRA"`, string(out["connectionType"])) | ||
| }) | ||
| } | ||
|
|
||
| // deviceJSONFields marshals d and returns its top-level JSON object keyed by | ||
| // field name, so a test can assert on key presence/absence and values. | ||
| func deviceJSONFields(t *testing.T, d Device) map[string]json.RawMessage { | ||
| t.Helper() | ||
|
|
||
| b, err := json.Marshal(d) | ||
| require.NoError(t, err) | ||
|
|
||
| var m map[string]json.RawMessage | ||
| require.NoError(t, json.Unmarshal(b, &m)) | ||
|
|
||
| return m | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.