CSUD: add migration to track update profiles#46433
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
There was a problem hiding this comment.
Pull request overview
Adds a new MySQL migration that creates the mdm_configuration_profile_update_settings table to track which Windows configuration profiles and Apple declarations enforce software update settings, and backfills rows for existing user-uploaded profiles/declarations that contain update settings.
Changes:
- New migration
20260529091823_AddUpdateProfileSettingsTrackingTable.gocreating the tracking table with FK cascades and an "exactly one of windows/apple" CHECK constraint. - Backfill logic that scans existing Apple declarations (looking for
com.apple.configuration.softwareupdate.enforcement.specific) and Windows profiles (looking forsyncml.FleetOSUpdateTargetLocURI) and inserts rows. - Migration test verifying inclusion/exclusion of matching rows, the exactly-one CHECK constraint, and FK cascade deletes; corresponding
schema.sqlupdate.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| server/datastore/mysql/migrations/tables/20260529091823_AddUpdateProfileSettingsTrackingTable.go | New migration creating the table and backfilling rows |
| server/datastore/mysql/migrations/tables/20260529091823_AddUpdateProfileSettingsTrackingTable_test.go | Tests for table creation, backfill, CHECK constraint, and FK cascades |
| server/datastore/mysql/schema.sql | Reflects the new table and bumps migration AUTO_INCREMENT/INSERT list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThis PR adds a migration that creates the mdm_configuration_profile_update_settings table (id, created_at, nullable apple_declaration_uuid/windows_profile_uuid), enforces exactly one UUID per row, registers the migration, backfills qualifying Apple declarations and Windows profiles by scanning raw_json and syncml content, updates migration_status_tables, and adds tests verifying population, the mutual-exclusion CHECK, and ON DELETE CASCADE behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In
`@server/datastore/mysql/migrations/tables/20260529091823_AddUpdateProfileSettingsTrackingTable_test.go`:
- Around line 18-28: The fixtures currently insert rows into
mdm_apple_declarations and mdm_windows_configuration_profiles without setting
uploaded_at, which conflicts with the user-uploaded-only backfill contract;
update the INSERT statements that reference decl1UUID/decl2UUID and
profile1UUID/profile2UUID to include the uploaded_at column and set a non-null
timestamp for the rows you intend to mark as "user-uploaded" and explicitly set
uploaded_at = NULL for rows that should not be considered user-uploaded so the
migration only backfills the intended records.
In
`@server/datastore/mysql/migrations/tables/20260529091823_AddUpdateProfileSettingsTrackingTable.go`:
- Line 40: The backfill query is selecting all rows from mdm_apple_declarations
(and the analogous windows_profiles query) instead of only user-uploaded
records; update the SQL in the tx.Query calls that reference
mdm_apple_declarations and windows_profiles to include filtering for uploaded_at
IS NOT NULL (e.g., add a WHERE uploaded_at IS NOT NULL clause) so only
user-uploaded rows are iterated and tracked during the backfill.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7e28adf8-2abf-4055-bf5c-6dc17ddc08f3
📒 Files selected for processing (3)
server/datastore/mysql/migrations/tables/20260529091823_AddUpdateProfileSettingsTrackingTable.goserver/datastore/mysql/migrations/tables/20260529091823_AddUpdateProfileSettingsTrackingTable_test.goserver/datastore/mysql/schema.sql
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #46433 +/- ##
==========================================
+ Coverage 66.90% 66.92% +0.02%
==========================================
Files 2797 2799 +2
Lines 223494 223547 +53
Branches 11297 11297
==========================================
+ Hits 149519 149610 +91
+ Misses 60432 60380 -52
- Partials 13543 13557 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Related issue: Resolves #45281
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/oree/fleetd-chrome/changes.See Changes files for more information. Will be added in the backend work PR
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
Database migrations
COLLATE utf8mb4_unicode_ci).Summary by CodeRabbit
Chores
Tests