Skip to content

SAAD: DDM Asset table migration - #48866

Merged
MagnusHJensen merged 1 commit into
mainfrom
48566-ddm-assets-migration
Jul 8, 2026
Merged

SAAD: DDM Asset table migration#48866
MagnusHJensen merged 1 commit into
mainfrom
48566-ddm-assets-migration

Conversation

@MagnusHJensen

@MagnusHJensen MagnusHJensen commented Jul 7, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #48566

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information. Coming in bigger backend story.

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.

  • Timeouts are implemented and retries are limited to avoid infinite loops

  • If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes

Testing

Summary by CodeRabbit

  • New Features

    • Added support for tracking Apple declaration assets, including a new asset record and a link table for associating assets with declarations.
    • Added a new timestamp on declarations to reflect the latest asset update time.
  • Bug Fixes

    • Strengthened database constraints to prevent duplicate asset entries and enforce valid asset/declaration references.
    • Improved delete behavior so referenced declarations clean up related links automatically.

Copilot AI review requested due to automatic review settings July 7, 2026 15:42
@MagnusHJensen
MagnusHJensen requested a review from a team as a code owner July 7, 2026 15:42

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR adds a new MySQL migration that creates two tables, mdm_apple_declaration_assets and mdm_apple_declaration_asset_references, and adds an assets_updated_at column to host_mdm_apple_declarations. The asset table includes a generated token column derived from raw_json and secrets_updated_at, with uniqueness constraints on team/identifier and team/name. The reference table enforces foreign keys, cascading deletes from declarations while restricting deletes of referenced assets. A migration test validates these constraints, and schema.sql is regenerated to reflect the changes, including an incremented migration_status_tables AUTO_INCREMENT and seed row. The Down migration is a no-op.

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding the DDM asset table migration.
Description check ✅ Passed The description matches the template well, includes the related issue, checklist, and testing section, and is mostly complete.
Linked Issues check ✅ Passed The migration, schema update, and test cover the required tables, column, keys, and no-op down behavior from issue #48566.
Out of Scope Changes check ✅ Passed No clearly unrelated code changes are present beyond the expected schema regeneration and migration test updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 48566-ddm-assets-migration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
server/datastore/mysql/migrations/tables/20260707140752_AddDDMAssetsTable_test.go (1)

31-57: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider asserting the generated token value.

FK/cascade/restrict coverage is thorough, but the test never reads back token to confirm it's actually derived from raw_json/secrets_updated_at as intended. Since the PR objectives state asset changes must propagate via the token so referenced configs re-sync hosts, a quick assertion (e.g., SELECT HEX(token) ... compared to an expected MD5 hash, or verifying token changes after an UPDATE raw_json) would directly validate the core sync mechanism this migration exists to support.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@server/datastore/mysql/migrations/tables/20260707140752_AddDDMAssetsTable_test.go`
around lines 31 - 57, The migration test for AddDDMAssetsTable currently
verifies foreign keys and cascade behavior but does not validate the token
column used for sync propagation. In the test function in
20260707140752_AddDDMAssetsTable_test.go, add a readback/assertion for the
generated token on mdm_apple_declaration_assets, either by querying it after
insert and comparing it to the expected value derived from raw_json and
secrets_updated_at or by updating raw_json and confirming the token changes
accordingly. Use the existing db.ExecContext and db.QueryRowContext flow in the
test to keep the assertion alongside the current FK coverage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@server/datastore/mysql/migrations/tables/20260707140752_AddDDMAssetsTable_test.go`:
- Around line 31-57: The migration test for AddDDMAssetsTable currently verifies
foreign keys and cascade behavior but does not validate the token column used
for sync propagation. In the test function in
20260707140752_AddDDMAssetsTable_test.go, add a readback/assertion for the
generated token on mdm_apple_declaration_assets, either by querying it after
insert and comparing it to the expected value derived from raw_json and
secrets_updated_at or by updating raw_json and confirming the token changes
accordingly. Use the existing db.ExecContext and db.QueryRowContext flow in the
test to keep the assertion alongside the current FK coverage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 844cda6b-7909-4c92-be79-b482c880b123

📥 Commits

Reviewing files that changed from the base of the PR and between da59512 and dcd1c63.

📒 Files selected for processing (3)
  • server/datastore/mysql/migrations/tables/20260707140752_AddDDMAssetsTable.go
  • server/datastore/mysql/migrations/tables/20260707140752_AddDDMAssetsTable_test.go
  • server/datastore/mysql/schema.sql

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 the initial MySQL schema support for SAAD DDM “asset” declarations by introducing new asset tables and wiring asset change propagation into host-level DDM tokens via a new timestamp column.

Changes:

  • Added mdm_apple_declaration_assets and mdm_apple_declaration_asset_references tables with generated token + FK constraints.
  • Added host_mdm_apple_declarations.assets_updated_at column.
  • Updated server/datastore/mysql/schema.sql to reflect the new schema and migration list.

Reviewed changes

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

File Description
server/datastore/mysql/schema.sql Adds the new DDM asset tables and assets_updated_at column to the canonical schema dump.
server/datastore/mysql/migrations/tables/20260707140752_AddDDMAssetsTable.go Introduces the migration creating the asset tables and adding assets_updated_at.
server/datastore/mysql/migrations/tables/20260707140752_AddDDMAssetsTable_test.go Tests uniqueness/FK behavior for the new asset tables.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +18
asset_uuid varchar(37) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
team_id int unsigned NOT NULL,
identifier varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
name varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was thinking we don't want this to be more explicit, that way we catch bugs earlier in code. With this it would default to team_id 0 (unassigned) which is less visible than empty name. I would like to continue not having default for require fields either way (especially on new tables), lmk.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that's fine

Comment on lines +36 to +38
declaration_uuid varchar(37) COLLATE utf8mb4_unicode_ci NOT NULL,
asset_uuid varchar(37) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (declaration_uuid, asset_uuid),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also fine

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.22222% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.05%. Comparing base (da59512) to head (dcd1c63).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rations/tables/20260707140752_AddDDMAssetsTable.go 82.22% 5 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #48866      +/-   ##
==========================================
- Coverage   68.05%   68.05%   -0.01%     
==========================================
  Files        3693     3694       +1     
  Lines      234406   234451      +45     
  Branches    12460    12460              
==========================================
+ Hits       159535   159565      +30     
- Misses      60543    60552       +9     
- Partials    14328    14334       +6     
Flag Coverage Δ
backend 69.71% <82.22%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MagnusHJensen
MagnusHJensen merged commit ace8cf0 into main Jul 8, 2026
44 of 45 checks passed
@MagnusHJensen
MagnusHJensen deleted the 48566-ddm-assets-migration branch July 8, 2026 07:17
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.

SAAD: Migrations for DDM Asset tables

3 participants