Skip to content

Conversation

@getvictor
Copy link
Member

@getvictor getvictor commented Jan 8, 2026

Related issue: Resolves #37244

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.

Testing

  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Refactor

    • Internal MySQL utility package reorganized and all internal imports updated to the new platform location; no changes to end-user functionality or behavior.
  • Documentation

    • Added platform package documentation describing infrastructure responsibilities and architectural boundaries to guide maintainers.

✏️ Tip: You can customize this high-level summary in your review settings.

@getvictor
Copy link
Member Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

✅ Actions performed

Full review triggered.

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.81%. Comparing base (bc0c7f1) to head (4e81d48).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #38017      +/-   ##
==========================================
- Coverage   65.82%   65.81%   -0.01%     
==========================================
  Files        2387     2387              
  Lines      190158   190158              
  Branches     8428     8428              
==========================================
- Hits       125168   125160       -8     
- Misses      53609    53613       +4     
- Partials    11381    11385       +4     
Flag Coverage Δ
backend 67.66% <ø> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@getvictor getvictor marked this pull request as ready for review January 8, 2026 03:48
@getvictor getvictor requested a review from a team as a code owner January 8, 2026 03:48
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

Walkthrough

Refactors the MySQL common utilities package by moving server/datastore/mysql/common_mysqlserver/platform/mysql, updates imports across the codebase, renames package declarations to mysql, adds platform README, and moves the architecture dependency test to server/platform/arch_test.go.

Changes

Cohort / File(s) Summary
Platform package & docs
changes/37244-refactor-common_mysql, server/platform/README.md, server/platform/arch_test.go
Added platform README and new architecture test enforcing that server/platform/mysql does not depend on domain packages; documents platform/domain responsibilities.
Platform mysql package files
server/platform/mysql/* (e.g. batch.go, common.go, config.go, errors.go, list_options.go, retry.go, batch_test.go)
Renamed package from common_mysqlmysql (package declaration changes) and adjusted test package name.
Datastore code (bulk import updates)
server/datastore/mysql/* (e.g. android.go, apple_mdm.go, certificate_authorities.go, config.go, errors.go, host_identity_scep.go, hosts.go, mysql.go, nanomdm_storage.go, operating_systems.go, policies.go, scim.go, software.go, software_titles.go, migrations migrations/tables/20250502222222_AddMdmEnrollTables.go)
Replaced imports referencing server/datastore/mysql/common_mysql with server/platform/mysql (aliased as common_mysql in many files); no logic changes shown.
Datastore tests & test utilities
server/datastore/mysql/*_test.go, server/datastore/mysql/testing_utils.go, server/datastore/mysql/migrations_test.go, server/datastore/mysql/*_test.go
Updated test imports to use server/platform/mysql and server/platform/mysql/testing_utils; no test logic changes.
Enterprise & service files
ee/server/service/*, server/service/*, server/service/integrationtest/suite.go (examples: ee/server/service/certificate_authorities_test.go, ee/server/service/condaccess/idp_test.go, ee/server/service/hostidentity/depot/depot.go, ee/server/service/request_certificate_test.go, ee/server/service/software_installers.go, server/service/labels_test.go, server/service/osquery_utils/queries_test.go, server/service/software_title_icons_test.go)
Updated imports to server/platform/mysql (aliased as common_mysql) where previously pointed to datastore/mysql/common_mysql.
MDM & nanomdm storage
server/mdm/*, server/mdm/nanomdm/storage/mysql/* (examples: server/mdm/android/service/pubsub_test.go, server/mdm/nanomdm/storage/mysql/mysql.go, queue.go)
Updated imports to server/platform/mysql and retained use of helper functions (e.g., WithRetryTxx).
Tools & external tests
tools/mysql-tests/rds/iam_auth.go, server/platform/mysql/testing_utils/testing_utils.go, server/platform/mysql/testing_utils/*
Updated imports to use server/platform/mysql and its testing utilities.
Removed legacy arch test
server/datastore/mysql/common_mysql/arch_test.go
Deleted the old dependency-check test from the former location.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • cdcme
  • JordanMontgomery
  • lucasmrod
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: moving the common_mysql package to server/platform/mysql.
Description check ✅ Passed The description includes the related issue reference and confirms a changes file was added and manual testing was performed, but lacks detail about the refactoring scope.
Linked Issues check ✅ Passed The PR successfully moves the common_mysql package to server/platform/mysql, updates all import paths across 50+ files, updates the package name from common_mysql to mysql, and adds architecture tests to enforce platform-domain separation.
Out of Scope Changes check ✅ Passed All changes are directly related to the refactoring objective. The package relocation, import updates, package renaming, architecture test addition, and README documentation are all in scope for this architectural refactoring.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor/37244-move-common_mysql

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 19

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (14)
server/datastore/mysql/apple_mdm_test.go (1)

18-37: Fix import alias for moved common_mysql package and avoid mysql name collision

The new import

"github.com/fleetdm/fleet/v4/server/platform/mysql"

introduces two problems:

  • There is no imported symbol named common_mysql, but the file still uses common_mysql.NotFoundError, which will not compile.
  • Without an alias this package would get the local name mysql, colliding with github.com/go-sql-driver/mysql also imported as mysql.

Alias the new path to common_mysql (preserving existing call sites) and avoid the mysql name clash:

🔧 Suggested import fix
@@
-	"github.com/fleetdm/fleet/v4/server/mdm/nanomdm/push"
-	"github.com/fleetdm/fleet/v4/server/platform/mysql"
+	"github.com/fleetdm/fleet/v4/server/mdm/nanomdm/push"
+	common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"
server/datastore/mysql/android_enterprises.go (1)

31-31: Critical: Update references to use new import path.

The import was changed to platform/mysql (line 10), but these lines still reference common_mysql.NotFound. Without an import alias, the package name is mysql, so these should be updated to mysql.NotFound.

🔧 Proposed fix
-		return nil, common_mysql.NotFound("Android enterprise").WithID(id)
+		return nil, mysql.NotFound("Android enterprise").WithID(id)
-		return nil, common_mysql.NotFound("Android enterprise")
+		return nil, mysql.NotFound("Android enterprise")
-		return nil, common_mysql.NotFound("Android enterprise")
+		return nil, mysql.NotFound("Android enterprise")
-		return common_mysql.NotFound("Android enterprise").WithID(enterprise.ID)
+		return mysql.NotFound("Android enterprise").WithID(enterprise.ID)

Also applies to: 44-44, 57-57, 80-80

server/datastore/mysql/vulnerabilities_test.go (1)

176-177: Critical: Update references to use new import path.

The import was changed to platform/mysql (line 10), but these lines still reference common_mysql.NotFoundError. The package should now be referenced as mysql.NotFoundError.

🔧 Proposed fix
-	var nfe *common_mysql.NotFoundError
+	var nfe *mysql.NotFoundError
 	require.ErrorAs(t, err, &nfe)

Also applies to: 285-286

server/datastore/mysql/operating_system_vulnerabilities.go (1)

1038-1038: Critical: Update reference to use new import path.

The import was changed to platform/mysql (line 12), but this line still references common_mysql.BatchProcessSimple. It should be updated to mysql.BatchProcessSimple.

🔧 Proposed fix
-		err := common_mysql.BatchProcessSimple(cveList, batchSize, func(batch []string) error {
+		err := mysql.BatchProcessSimple(cveList, batchSize, func(batch []string) error {
server/datastore/mysql/apple_mdm.go (1)

21-36: Broken common_mysql reference after import path move

The new import at Line 29 points to server/platform/mysql without an alias, but the code still refers to common_mysql.DBReadTx and common_mysql.BatchProcessSimple (e.g., Lines 3256, 3286, 5547). As written:

  • common_mysql is now an undefined identifier → compile error.
  • The imported github.com/fleetdm/fleet/v4/server/platform/mysql package is unused → additional compile/lint error.

If the intent is to keep the existing common_mysql API surface while changing its location, you should alias the new package to common_mysql so the rest of the file compiles unchanged.

🔧 Suggested fix: alias the new platform mysql package
@@
-	"github.com/fleetdm/fleet/v4/server/mdm/nanomdm/mdm"
-	"github.com/fleetdm/fleet/v4/server/platform/mysql"
+	"github.com/fleetdm/fleet/v4/server/mdm/nanomdm/mdm"
+	common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"

This preserves all existing common_mysql.DBReadTx and common_mysql.BatchProcessSimple usages without further changes in this file.

Also applies to: 3253-3266, 5547-5563

tools/mysql-tests/rds/iam_auth.go (1)

11-17: Resolve MySQL import conflict and restore common_mysql.DBOptions

This file now imports both:

  • github.com/fleetdm/fleet/v4/server/datastore/mysql
  • github.com/fleetdm/fleet/v4/server/platform/mysql

without aliasing, while still using common_mysql.DBOptions. This leads to:

  • A name clash on mysql between the two imports.
  • common_mysql being undefined.

Alias the new platform package as common_mysql so DBOptions resolves and the datastore mysql import remains unchanged.

🔧 Suggested import change
-	"github.com/fleetdm/fleet/v4/server/platform/mysql"
+	common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"

With this change:

  • mysql.NewDB(...) continues to refer to server/datastore/mysql.
  • dbOpts := &common_mysql.DBOptions{...} compiles against server/platform/mysql.
server/service/software_title_icons_test.go (1)

11-21: Alias moved MySQL helpers to common_mysql in tests

This test still constructs errors using &common_mysql.NotFoundError{...}, but now imports server/platform/mysql without an alias. As written:

  • common_mysql is undefined.
  • mysql is imported but never used.

Mirror the old alias by importing the new package as common_mysql:

Suggested import fix
 import (
@@
-	"github.com/fleetdm/fleet/v4/server/mock"
-	"github.com/fleetdm/fleet/v4/server/platform/mysql"
+	"github.com/fleetdm/fleet/v4/server/mock"
+	common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"

This keeps all common_mysql.NotFoundError uses compiling against the relocated package.

Also applies to: 50-60, 147-155, 185-191, 229-239, 289-296, 381-383, 461-463

server/datastore/mysql/policies.go (1)

15-22: Wire WithRetryTxx/BatchProcessSimple to new platform/mysql package

After switching the import to server/platform/mysql, this file still references common_mysql.WithRetryTxx and common_mysql.BatchProcessSimple, but no longer imports common_mysql. The new mysql import is otherwise unused.

Alias the new package so existing helper calls compile:

Suggested import fix
 import (
@@
-	"github.com/fleetdm/fleet/v4/server/fleet"
-	"github.com/fleetdm/fleet/v4/server/platform/mysql"
+	"github.com/fleetdm/fleet/v4/server/fleet"
+	common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"

With that alias:

  • common_mysql.WithRetryTxx in cleanupPolicy will resolve correctly.
  • common_mysql.BatchProcessSimple in getPoliciesBySoftwareTitleIDs will also bind to the relocated utilities.

Also applies to: 441-446, 2163-2179

server/datastore/mysql/hosts_test.go (1)

30-40: Broken common_mysql reference after import refactor—will not compile

The import was changed to server/platform/mysql but line 40 still calls common_mysql.GetDefaultNonZeroTime(). Since common_mysql is not imported, this will fail to compile. Also, importing platform/mysql without an alias in package mysql creates ambiguity.

Alias the import and update the usage:

Proposed fix
-	"github.com/fleetdm/fleet/v4/server/platform/mysql"
+	platformmysql "github.com/fleetdm/fleet/v4/server/platform/mysql"
-var expLastExec = common_mysql.GetDefaultNonZeroTime()
+var expLastExec = platformmysql.GetDefaultNonZeroTime()
server/datastore/mysql/scim.go (3)

693-693: Critical: Update package reference to match new import.

The import was changed to github.com/fleetdm/fleet/v4/server/platform/mysql (line 12), which provides the package name mysql, but this line still references common_mysql.BatchProcessSimple. This will cause a compilation error.

🔧 Required fix
-	return common_mysql.BatchProcessSimple(userIDs, batchSize, func(userIDsInBatch []uint) error {
+	return mysql.BatchProcessSimple(userIDs, batchSize, func(userIDsInBatch []uint) error {

879-879: Critical: Update package reference to match new import.

The package reference must be updated from common_mysql to mysql to match the new import path.

🔧 Required fix
-			err = common_mysql.BatchProcessSimple(usersToRemove, batchSize, func(usersToRemoveInBatch []uint) error {
+			err = mysql.BatchProcessSimple(usersToRemove, batchSize, func(usersToRemoveInBatch []uint) error {

1381-1381: Critical: Update package reference to match new import.

The package reference must be updated from common_mysql to mysql to match the new import path.

🔧 Required fix
-	err := common_mysql.BatchProcessSimple(ids, batchSize, func(batchIDs []uint) error {
+	err := mysql.BatchProcessSimple(ids, batchSize, func(batchIDs []uint) error {
server/datastore/mysql/errors.go (1)

20-24: Critical: Update package references to match new import.

The import was changed to github.com/fleetdm/fleet/v4/server/platform/mysql (line 16), which provides the package name mysql, but lines 20-21 still reference common_mysql.NotFoundError. This will cause compilation errors.

🔧 Required fix
-func notFound(kind string) *common_mysql.NotFoundError {
-	return &common_mysql.NotFoundError{
+func notFound(kind string) *mysql.NotFoundError {
+	return &mysql.NotFoundError{
 		ResourceType: kind,
 	}
 }
server/mdm/nanomdm/storage/mysql/mysql.go (1)

341-341: Critical: Update package reference to match new import.

The import was changed to github.com/fleetdm/fleet/v4/server/platform/mysql (line 16), which provides the package name mysql, but this line still references common_mysql.WithRetryTxx. This will cause a compilation error.

🔧 Required fix
-	err = common_mysql.WithRetryTxx(ctx, sqlx.NewDb(s.db, ""), func(tx sqlx.ExtContext) error {
+	err = mysql.WithRetryTxx(ctx, sqlx.NewDb(s.db, ""), func(tx sqlx.ExtContext) error {
🤖 Fix all issues with AI agents
In @ee/server/service/certificate_authorities_test.go:
- Line 21: The test import was changed to use the package name mysql but the
code still calls common_mysql.NotFound(...) causing undefined/unused import
errors; restore the import alias by importing the package with the alias
common_mysql (i.e., import common_mysql
"github.com/fleetdm/fleet/v4/server/platform/mysql") or alternatively update all
calls to common_mysql.NotFound to mysql.NotFound so the symbol and import match;
update references at the noted call sites (functions/lines that call
common_mysql.NotFound) to keep the import and usage consistent.

In @ee/server/service/condaccess/idp_test.go:
- Line 14: The test imports the moved package under the plain name mysql but the
code still calls common_mysql.NotFound("certificate"), leaving common_mysql
undefined and mysql unused; update the import to use the original alias (e.g.,
common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql") or rename all
call sites to use mysql.NotFound so the symbol resolves; apply the same alias
fix to the other occurrences noted around lines 307-309 that reference
common_mysql.NotFound.

In @ee/server/service/hostidentity/depot/depot.go:
- Around line 21-22: The compile error is caused by calling
common_mysql.WithRetryTxx while the import is named mysql; in the Put method
replace common_mysql.WithRetryTxx(...) with mysql.WithRetryTxx(...) (keeping the
same arguments, including context.Background()), so the call uses the imported
github.com/fleetdm/fleet/v4/server/platform/mysql package; ensure the Put
function references mysql.WithRetryTxx and no other behavioral changes are made.

In @ee/server/service/request_certificate_test.go:
- Line 20: The test imports were changed to platform/mysql but code still uses
the old symbol common_mysql.NotFound; update all references to the undefined
symbol (e.g., common_mysql.NotFound) to use the imported package name
(mysql.NotFound) or adjust the import alias to match the symbol used in the file
(for example, alias platform/mysql as common_mysql) so the symbol resolves in
request_certificate_test.go (ensure you update the reference around the
assertion at the NotFound check and any other occurrences).

In @ee/server/service/software_installers.go:
- Around line 30-31: The import uses the package name mysql but the code still
calls common_mysql.NotFound; update all references of common_mysql.* in this
file to use mysql.* (e.g., change common_mysql.NotFound(...) to
mysql.NotFound(...)) so the unaliased import is actually used, and scan the file
for any other lingering common_mysql identifiers and replace them with mysql.

In @server/datastore/mysql/android_device_test.go:
- Around line 13-15: The tests reference common_mysql.NotFound and
common_mysql.NotFoundError but the import was changed to an unaliased path;
update the import list in android_device_test.go (and also
software_installers_test.go and policies_test.go) to alias
github.com/fleetdm/fleet/v4/server/platform/mysql as common_mysql so all
existing references to common_mysql.NotFound and common_mysql.NotFoundError
resolve to the new package name.

In @server/datastore/mysql/config.go:
- Around line 6-10: The file imports server/platform/mysql but the code still
references common_mysql.DBOptions (e.g., in DBOption and helpers), causing
undefined symbol and unused import errors; change the import statement to alias
the package as common_mysql (import common_mysql
"github.com/fleetdm/fleet/v4/server/platform/mysql") so all existing references
to common_mysql.DBOptions compile, and remove any unused plain mysql import
references if present.

In @server/datastore/mysql/hosts.go:
- Line 23: The import for platform/mysql must be aliased to common_mysql because
the code uses common_mysql.DefaultNonZeroTime in this file; update the import
line that currently imports "github.com/fleetdm/fleet/v4/server/platform/mysql"
to use the alias common_mysql (e.g., common_mysql
"github.com/fleetdm/fleet/v4/server/platform/mysql") so references to
common_mysql.DefaultNonZeroTime compile.

In
@server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go:
- Around line 9-13: The code still calls common_mysql.BatchProcessSimple but the
import for server/platform/mysql was added without the common_mysql alias (and
the plain mysql import is now unused); change the import line that currently
imports server/platform/mysql to use the alias common_mysql (e.g., import
common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql") so
common_mysql.BatchProcessSimple resolves, and remove any unused plain mysql
import to keep the build clean.

In @server/datastore/mysql/mysql.go:
- Line 33: The file imports the package as
"github.com/fleetdm/fleet/v4/server/platform/mysql" but the code still
references the old package name `common_mysql`; replace all `common_mysql`
identifiers with `mysql` throughout the file (e.g., change types and usages like
`common_mysql.MysqlConfig`, `common_mysql.TxFn`, `common_mysql.WithRetryTxx`,
`common_mysql.WithTxx`, `common_mysql.ReadTxFn`, `common_mysql.WithReadOnlyTxx`,
`common_mysql.DBConnections`, `common_mysql.DBOptions`, `common_mysql.NewDB`,
`common_mysql.LoggingConfig`, `common_mysql.SanitizeColumn`, and
`common_mysql.AppendListOptionsWithParams` to use `mysql`), ensuring every
occurrence is updated so the import and references match.

In @server/datastore/mysql/nanomdm_storage.go:
- Line 20: The import path was changed to mysql but the code still calls
common_mysql.WithRetryTxx; update every call site to use mysql.WithRetryTxx
instead of common_mysql.WithRetryTxx (i.e., replace the symbol
common_mysql.WithRetryTxx with mysql.WithRetryTxx in nanomdm_storage.go for all
occurrences).

In @server/datastore/mysql/policies_test.go:
- Line 18: The test no longer compiles because the import was changed to
"github.com/fleetdm/fleet/v4/server/platform/mysql" but call sites still
reference the old alias common_mysql and the new mysql import is unused; fix by
either restoring the explicit alias (change the import to common_mysql
"github.com/fleetdm/fleet/v4/server/platform/mysql" and remove the unused plain
mysql import) or update all usages of common_mysql in policies_test.go (and the
other affected files) to use the current package identifier (mysql), ensuring
there are no unused imports left.

In @server/datastore/mysql/software_installers_test.go:
- Around line 19-21: The test references common_mysql.NotFoundError but the
package was renamed; update the imports so the existing references work by
aliasing the new import "github.com/fleetdm/fleet/v4/server/platform/mysql" as
common_mysql (so common_mysql.NotFoundError resolves) in
software_installers_test.go (affecting testDeleteSoftwareInstallers and the
other occurrences noted); remove any unused import warnings by replacing the
unused direct mysql import with the aliased common_mysql import.

In @server/datastore/mysql/software_titles.go:
- Line 15: The code still references common_mysql.BatchProcessSimple even though
the import was changed to "github.com/fleetdm/fleet/v4/server/platform/mysql";
replace all uses of common_mysql.BatchProcessSimple (e.g., the call in the
function around the software titles processing at Line ~352) with
mysql.BatchProcessSimple and ensure any other references to common_mysql are
updated to mysql to match the current import name.

In @server/datastore/mysql/software.go:
- Line 19: The import currently bringing in
"github.com/fleetdm/fleet/v4/server/platform/mysql" must be aliased to
common_mysql so existing call sites using common_mysql.RetryableError and
common_mysql.BatchProcessSimple continue to compile; update the import to use
the alias common_mysql and remove any unused plain mysql import to avoid name
conflict with the package itself.

In @server/datastore/mysql/testing_utils.go:
- Around line 34-35: The code imports the package as "mysql" but still
references "common_mysql", causing undefined symbol errors; update all
references of common_mysql (e.g., common_mysql.TestSQLMode,
common_mysql.DBOptions) to use the imported alias "mysql" (mysql.TestSQLMode,
mysql.DBOptions), or alternatively change the import to use the alias
`common_mysql` if you prefer that name—make the reference and import names
consistent (affecting TestSQLMode and DBOptions usages).

In @server/mdm/android/service/pubsub_test.go:
- Line 18: Update all references to the old import alias common_mysql to the new
import alias mysql: replace occurrences like common_mysql.NotFound(...) with
mysql.NotFound(...) throughout the file (e.g., the calls to NotFound used in
tests/assertions such as common_mysql.NotFound at the spots where errors are
compared). Ensure every reference (previously common_mysql.NotFound at multiple
locations) is changed to mysql.NotFound so the code compiles against the updated
import.

In @server/mdm/nanomdm/storage/mysql/queue.go:
- Line 12: The code still refers to the old package alias common_mysql but the
import uses mysql; update all references to the new package name (replace
common_mysql.WithRetryTxx and common_mysql.BatchProcessSimple with
mysql.WithRetryTxx and mysql.BatchProcessSimple) so the calls at the spots using
WithRetryTxx (around the function referencing retry wrappers) and
BatchProcessSimple (the batch processing call) use the imported mysql package
symbol; ensure the import line remains `mysql` (or add an explicit alias
`common_mysql` if you prefer the old name) and adjust any usages accordingly so
names match.

In @server/service/osquery_utils/queries_test.go:
- Around line 31-32: Tests currently reference common_mysql.NotFound(...) but
the import was changed to github.com/fleetdm/fleet/v4/server/platform/mysql,
leaving common_mysql undefined and mysql unused; update all occurrences of
common_mysql.NotFound(...) to mysql.NotFound(...) (e.g., in
TestDirectIngestMDMWindows, LUKS tests, SCIM-related tests) so the tests compile
and use the new package name, and remove any remaining unused imports if
necessary.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc0c7f1 and 74113fc.

📒 Files selected for processing (55)
  • changes/37244-refactor-common_mysql
  • ee/server/service/certificate_authorities_test.go
  • ee/server/service/condaccess/idp_test.go
  • ee/server/service/hostidentity/depot/depot.go
  • ee/server/service/request_certificate_test.go
  • ee/server/service/software_installers.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/android_mysql.go
  • server/datastore/mysql/android_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/certificate_authorities.go
  • server/datastore/mysql/common_mysql/arch_test.go
  • server/datastore/mysql/config.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/host_identity_scep.go
  • server/datastore/mysql/hosts.go
  • server/datastore/mysql/hosts_test.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/migrations_test.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/policies.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/software.go
  • server/datastore/mysql/software_installers_test.go
  • server/datastore/mysql/software_titles.go
  • server/datastore/mysql/testing_utils.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/mdm/android/service/pubsub_test.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/platform/README.md
  • server/platform/arch_test.go
  • server/platform/mysql/batch.go
  • server/platform/mysql/batch_test.go
  • server/platform/mysql/common.go
  • server/platform/mysql/config.go
  • server/platform/mysql/errors.go
  • server/platform/mysql/list_options.go
  • server/platform/mysql/retry.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/service/integrationtest/suite.go
  • server/service/labels_test.go
  • server/service/osquery_utils/queries_test.go
  • server/service/software_title_icons_test.go
  • tools/mysql-tests/rds/iam_auth.go
💤 Files with no reviewable changes (1)
  • server/datastore/mysql/common_mysql/arch_test.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

⚙️ CodeRabbit configuration file

When reviewing SQL queries that are added or modified, ensure that appropriate filtering criteria are applied—especially when a query is intended to return data for a specific entity (e.g., a single host). Check for missing WHERE clauses or incorrect filtering that could lead to incorrect or non-deterministic results (e.g., returning the first row instead of the correct one). Flag any queries that may return unintended results due to lack of precise scoping.

Files:

  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/testing_utils.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/platform/arch_test.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/migrations_test.go
  • server/datastore/mysql/android_test.go
  • server/service/labels_test.go
  • ee/server/service/request_certificate_test.go
  • server/service/integrationtest/suite.go
  • server/datastore/mysql/software_installers_test.go
  • server/service/osquery_utils/queries_test.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/host_identity_scep.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/hosts.go
  • ee/server/service/software_installers.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • ee/server/service/condaccess/idp_test.go
  • server/mdm/android/service/pubsub_test.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • ee/server/service/certificate_authorities_test.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/service/software_title_icons_test.go
  • server/datastore/mysql/android_mysql.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/datastore/mysql/policies.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/certificate_authorities.go
  • server/datastore/mysql/software_titles.go
  • tools/mysql-tests/rds/iam_auth.go
  • server/datastore/mysql/config.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/hosts_test.go
  • ee/server/service/hostidentity/depot/depot.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/datastore/mysql/software.go
🧠 Learnings (14)
📚 Learning: 2025-08-08T07:40:05.301Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: Fleet repo targets Go 1.24.5 (root go.mod), which supports testing.T.Context(). Do not flag usage of t.Context() or suggest replacing it with context.Background() in tests (e.g., server/datastore/mysql/labels_test.go Line 2031 and similar).

Applied to files:

  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/testing_utils.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/platform/arch_test.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/migrations_test.go
  • changes/37244-refactor-common_mysql
  • server/datastore/mysql/android_test.go
  • server/service/labels_test.go
  • ee/server/service/request_certificate_test.go
  • server/service/integrationtest/suite.go
  • server/datastore/mysql/software_installers_test.go
  • server/service/osquery_utils/queries_test.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/hosts.go
  • ee/server/service/software_installers.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • ee/server/service/condaccess/idp_test.go
  • server/mdm/android/service/pubsub_test.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • ee/server/service/certificate_authorities_test.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/service/software_title_icons_test.go
  • server/datastore/mysql/android_mysql.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/datastore/mysql/policies.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/certificate_authorities.go
  • server/datastore/mysql/software_titles.go
  • tools/mysql-tests/rds/iam_auth.go
  • server/datastore/mysql/config.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/hosts_test.go
  • ee/server/service/hostidentity/depot/depot.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/datastore/mysql/software.go
📚 Learning: 2025-08-08T07:40:05.301Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: In fleetdm/fleet repository tests (server/datastore/mysql/labels_test.go and similar), using testing.T.Context() is valid because the project targets a recent Go version where testing.T.Context() exists. Do not suggest replacing t.Context() with context.Background() in this codebase.

Applied to files:

  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/testing_utils.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/platform/arch_test.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/migrations_test.go
  • changes/37244-refactor-common_mysql
  • server/datastore/mysql/android_test.go
  • server/service/labels_test.go
  • ee/server/service/request_certificate_test.go
  • server/service/integrationtest/suite.go
  • server/datastore/mysql/software_installers_test.go
  • server/service/osquery_utils/queries_test.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/host_identity_scep.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/hosts.go
  • ee/server/service/software_installers.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • ee/server/service/condaccess/idp_test.go
  • server/mdm/android/service/pubsub_test.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • ee/server/service/certificate_authorities_test.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/service/software_title_icons_test.go
  • server/datastore/mysql/android_mysql.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/datastore/mysql/policies.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/certificate_authorities.go
  • server/datastore/mysql/software_titles.go
  • tools/mysql-tests/rds/iam_auth.go
  • server/datastore/mysql/config.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/hosts_test.go
  • ee/server/service/hostidentity/depot/depot.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/datastore/mysql/software.go
📚 Learning: 2025-08-01T15:08:16.858Z
Learnt from: sgress454
Repo: fleetdm/fleet PR: 31508
File: server/datastore/mysql/schema.sql:102-116
Timestamp: 2025-08-01T15:08:16.858Z
Learning: The schema.sql file in server/datastore/mysql/ is auto-generated from migrations for use with tests, so it cannot be manually edited. Any changes must be made through migrations.

Applied to files:

  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/migrations_test.go
📚 Learning: 2025-08-13T18:20:42.136Z
Learnt from: titanous
Repo: fleetdm/fleet PR: 31075
File: tools/redis-tests/elasticache/iam_auth.go:4-10
Timestamp: 2025-08-13T18:20:42.136Z
Learning: For test harnesses and CLI tools in the Fleet codebase, resource cleanup on error paths (like closing connections before log.Fatalf) may not be necessary since the OS handles cleanup when the process exits. These tools prioritize simplicity over defensive programming patterns used in production code.

Applied to files:

  • server/datastore/mysql/scripts_test.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/migrations_test.go
  • server/datastore/mysql/android_test.go
  • server/service/labels_test.go
  • server/service/integrationtest/suite.go
  • server/datastore/mysql/software_installers_test.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • ee/server/service/condaccess/idp_test.go
  • server/datastore/mysql/policies_test.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/service/software_title_icons_test.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/policies.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/certificate_authorities.go
  • server/platform/README.md
  • server/datastore/mysql/software_titles.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/datastore/mysql/software.go
📚 Learning: 2025-08-08T07:40:05.301Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: In fleetdm/fleet, tests may validly use testing.T.Context() when the module/toolchain targets Go 1.24+. Do not flag t.Context() usage in this codebase if go.mod/toolchain indicates Go >= 1.24.

Applied to files:

  • server/datastore/mysql/testing_utils.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/migrations_test.go
  • server/service/labels_test.go
  • server/service/integrationtest/suite.go
  • server/datastore/mysql/software_installers_test.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/android_mysql.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/datastore/mysql/policies.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/certificate_authorities.go
  • server/datastore/mysql/software_titles.go
  • server/datastore/mysql/android_device_test.go
📚 Learning: 2025-07-08T16:12:48.797Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.

Applied to files:

  • server/datastore/mysql/host_identity_scep.go
  • server/datastore/mysql/android_mysql.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/datastore/mysql/operating_systems.go
  • ee/server/service/hostidentity/depot/depot.go
📚 Learning: 2025-07-08T16:06:54.576Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 30589
File: ee/server/service/hostidentity/depot/depot.go:104-119
Timestamp: 2025-07-08T16:06:54.576Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the security concern where shared challenges allow certificate revocation (lines 104-119) is a known issue that will be addressed in a later feature, not an immediate concern to fix.

Applied to files:

  • server/datastore/mysql/host_identity_scep.go
  • ee/server/service/hostidentity/depot/depot.go
📚 Learning: 2025-08-20T21:24:59.261Z
Learnt from: sgress454
Repo: fleetdm/fleet PR: 31075
File: server/datastore/mysql/common_mysql/aws_iam_auth.go:111-130
Timestamp: 2025-08-20T21:24:59.261Z
Learning: In Fleet's MySQL IAM authentication implementation, the TLS and AllowCleartextPasswords configuration is handled in the generateMysqlConnectionString function in server/datastore/mysql/common_mysql/common.go, not in the awsIAMAuthConnector.Connect method. The connector receives a base DSN that already includes the necessary IAM authentication parameters.

Applied to files:

  • server/datastore/mysql/host_identity_scep.go
  • server/datastore/mysql/mysql.go
  • tools/mysql-tests/rds/iam_auth.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/apple_mdm_test.go
📚 Learning: 2025-07-08T16:11:49.555Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 30589
File: ee/server/service/hostidentity/depot/depot.go:115-115
Timestamp: 2025-07-08T16:11:49.555Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the error from result.RowsAffected() is intentionally ignored because the information is only used for logging purposes, not for critical program logic.

Applied to files:

  • server/datastore/mysql/host_identity_scep.go
  • ee/server/service/hostidentity/depot/depot.go
📚 Learning: 2025-12-11T23:02:59.284Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 36978
File: server/mdm/android/service/profiles.go:441-449
Timestamp: 2025-12-11T23:02:59.284Z
Learning: Fleet’s server/mdm/android/service.Service has fields ds (type fleet.AndroidDatastore) and fleetDS (type fleet.Datastore). The fleet.Datastore interface embeds AndroidDatastore (server/fleet/datastore.go), so assigning r.DS (a fleet.Datastore) to Service.ds is valid in Go due to interface-to-interface assignment using the dynamic type.

Applied to files:

  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/hosts.go
  • ee/server/service/software_installers.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/datastore/mysql/hosts_test.go
  • server/datastore/mysql/apple_mdm_test.go
📚 Learning: 2025-12-11T23:02:52.191Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 36978
File: server/mdm/android/service/profiles.go:441-449
Timestamp: 2025-12-11T23:02:52.191Z
Learning: In server/mdm/android/service, Go allows assigning an interface value of type fleet.Datastore to a field ds of type fleet.Datastore because the underlying dynamic type implements both the embedded AndroidDatastore (via fleet.Datastore embedding AndroidDatastore). When reviewing code in profiles.go and related files, verify assignments between interfaces respect embedding and ensure the concrete type actually implements all required interfaces. This pattern is valid wherever fleet.Datastore embeds AndroidDatastore and the receiver expects fleetDS or similar fields; prefer keeping interface boundaries clear and rely on the dynamic type to satisfy both interfaces.

Applied to files:

  • server/mdm/android/service/pubsub_test.go
📚 Learning: 2025-10-03T18:16:11.482Z
Learnt from: MagnusHJensen
Repo: fleetdm/fleet PR: 33805
File: server/service/integration_mdm_test.go:1248-1251
Timestamp: 2025-10-03T18:16:11.482Z
Learning: In server/service/integration_mdm_test.go, the helper createAppleMobileHostThenEnrollMDM(platform string) is exclusively for iOS/iPadOS hosts (mobile). Do not flag macOS model/behavior issues based on changes within this helper; macOS provisioning uses different helpers such as createHostThenEnrollMDM.

Applied to files:

  • server/datastore/mysql/apple_mdm.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/apple_mdm_test.go
📚 Learning: 2025-12-31T23:23:07.852Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 37245
File: server/datastore/mysql/common_mysql/list_options.go:56-73
Timestamp: 2025-12-31T23:23:07.852Z
Learning: In server/datastore/mysql/common_mysql/list_options.go, the strings.HasSuffix(orderKey, "id") check at line 62 never matches because orderKey is already sanitized with backticks, making the integer conversion code at line 63 unreachable dead code. However, this doesn't cause functional issues because MySQL automatically coerces string parameters to integers when comparing with integer columns in WHERE clauses.

Applied to files:

  • server/datastore/mysql/software_titles.go
📚 Learning: 2025-08-20T21:24:59.261Z
Learnt from: sgress454
Repo: fleetdm/fleet PR: 31075
File: server/datastore/mysql/common_mysql/aws_iam_auth.go:111-130
Timestamp: 2025-08-20T21:24:59.261Z
Learning: In Fleet's MySQL IAM authentication implementation, the TLS and AllowCleartextPasswords configuration is handled in the generateMysqlConnectionString function in server/datastore/mysql/common_mysql/common.go. When no password is configured and the endpoint is an RDS endpoint, the function automatically sets allowCleartextPasswords=true and configures appropriate TLS settings. The awsIAMAuthConnector receives a properly configured base DSN and only needs to inject the IAM token as the password.

Applied to files:

  • tools/mysql-tests/rds/iam_auth.go
🧬 Code graph analysis (1)
server/platform/arch_test.go (2)
server/ptr/ptr.go (1)
  • T (86-88)
server/archtest/archtest.go (1)
  • NewPackageTest (43-45)
🔇 Additional comments (16)
server/datastore/mysql/android_mysql.go (1)

10-10: Critical: Import package identifier mismatch with usage below.

The import at line 10 uses the default package name mysql, but lines 47-52 reference common_mysql.TxFn, common_mysql.WithRetryTxx, and common_mysql.WithTxx. This code will not compile.

Resolution options:

  1. Add an import alias: common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"
  2. OR update all references below from common_mysql.* to mysql.*
⛔ Skipped due to learnings
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: In fleetdm/fleet repository tests (server/datastore/mysql/labels_test.go and similar), using testing.T.Context() is valid because the project targets a recent Go version where testing.T.Context() exists. Do not suggest replacing t.Context() with context.Background() in this codebase.
Learnt from: getvictor
Repo: fleetdm/fleet PR: 37245
File: server/datastore/mysql/common_mysql/list_options.go:56-73
Timestamp: 2025-12-31T23:23:07.852Z
Learning: In server/datastore/mysql/common_mysql/list_options.go, the strings.HasSuffix(orderKey, "id") check at line 62 never matches because orderKey is already sanitized with backticks, making the integer conversion code at line 63 unreachable dead code. However, this doesn't cause functional issues because MySQL automatically coerces string parameters to integers when comparing with integer columns in WHERE clauses.
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: Fleet repo targets Go 1.24.5 (root go.mod), which supports testing.T.Context(). Do not flag usage of t.Context() or suggest replacing it with context.Background() in tests (e.g., server/datastore/mysql/labels_test.go Line 2031 and similar).
Learnt from: sgress454
Repo: fleetdm/fleet PR: 31075
File: server/datastore/mysql/common_mysql/aws_iam_auth.go:111-130
Timestamp: 2025-08-20T21:24:59.261Z
Learning: In Fleet's MySQL IAM authentication implementation, the TLS and AllowCleartextPasswords configuration is handled in the generateMysqlConnectionString function in server/datastore/mysql/common_mysql/common.go, not in the awsIAMAuthConnector.Connect method. The connector receives a base DSN that already includes the necessary IAM authentication parameters.
server/datastore/mysql/android.go (1)

11-19: Import path refactor to platform/mysql looks correct

The updated import to github.com/fleetdm/fleet/v4/server/platform/mysql is consistent with the common_mysql → platform/mysql move and doesn’t alter any call sites, so behavior should remain unchanged as long as the moved package preserves the same API.

server/datastore/mysql/android_test.go (1)

11-19: Test import updated to new platform/mysql location

Switching the MySQL helper import to github.com/fleetdm/fleet/v4/server/platform/mysql matches the refactor and leaves test logic intact.

server/datastore/mysql/scripts_test.go (1)

12-20: Scripts tests correctly updated to use platform/mysql

The import now points at github.com/fleetdm/fleet/v4/server/platform/mysql, which aligns with the common_mysql relocation without impacting the test behavior.

server/datastore/mysql/host_identity_scep.go (1)

13-16: Host-identity SCEP datastore now imports platform/mysql

Updating the helper import to github.com/fleetdm/fleet/v4/server/platform/mysql keeps the retry/transaction behavior the same while matching the new package location.

server/datastore/mysql/certificate_authorities.go (1)

11-16: Certificate authority datastore correctly switched to platform/mysql

The import now targets github.com/fleetdm/fleet/v4/server/platform/mysql, which matches the common_mysql move; the rest of the CA logic remains untouched.

server/platform/README.md (1)

1-16: Platform README clearly documents architecture boundaries

The description of platform vs domain responsibilities and the “platform must not import domain” rule is clear and matches the new arch tests. No changes needed.

changes/37244-refactor-common_mysql (1)

1-1: Changelog entry matches the refactor

The note correctly summarizes moving common_mysql to server/platform/mysql. Looks good.

server/service/labels_test.go (1)

14-18: Import migration to platform/mysql/testing_utils looks correct

The test now pulls DatastoreTestOptions and CreateMySQLDSWithOptions from server/platform/mysql/testing_utils, and the call sites compile cleanly and preserve behavior. No further changes needed here.

Also applies to: 434-436

server/datastore/mysql/migrations_test.go (1)

12-12: LGTM! Import path updated correctly.

The import path has been successfully updated to server/platform/mysql/testing_utils, and all references to the testing_utils package throughout the file remain correct.

server/platform/mysql/testing_utils/testing_utils.go (1)

12-12: Critical: Package references not updated after import change.

The import path was updated to server/platform/mysql at line 12, but the code still uses common_mysql references:

  1. Line 49: common_mysql.WithTxx should be mysql.WithTxx
  2. Lines 167-174: Function returns *common_mysql.MysqlConfig should be *mysql.MysqlConfig

These will cause compilation failures.

🔧 Required fixes
-	require.NoError(t, common_mysql.WithTxx(ctx, db, func(tx sqlx.ExtContext) error {
+	require.NoError(t, mysql.WithTxx(ctx, db, func(tx sqlx.ExtContext) error {
-func MysqlTestConfig(testName string) *common_mysql.MysqlConfig {
-	return &common_mysql.MysqlConfig{
+func MysqlTestConfig(testName string) *mysql.MysqlConfig {
+	return &mysql.MysqlConfig{

Also applies to: 49-49, 167-174

⛔ Skipped due to learnings
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: In fleetdm/fleet repository tests (server/datastore/mysql/labels_test.go and similar), using testing.T.Context() is valid because the project targets a recent Go version where testing.T.Context() exists. Do not suggest replacing t.Context() with context.Background() in this codebase.
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: Fleet repo targets Go 1.24.5 (root go.mod), which supports testing.T.Context(). Do not flag usage of t.Context() or suggest replacing it with context.Background() in tests (e.g., server/datastore/mysql/labels_test.go Line 2031 and similar).
Learnt from: sgress454
Repo: fleetdm/fleet PR: 31075
File: server/datastore/mysql/common_mysql/aws_iam_auth.go:111-130
Timestamp: 2025-08-20T21:24:59.261Z
Learning: In Fleet's MySQL IAM authentication implementation, the TLS and AllowCleartextPasswords configuration is handled in the generateMysqlConnectionString function in server/datastore/mysql/common_mysql/common.go, not in the awsIAMAuthConnector.Connect method. The connector receives a base DSN that already includes the necessary IAM authentication parameters.
server/service/integrationtest/suite.go (1)

12-12: LGTM! Import path refactored correctly.

The import path has been successfully updated to reference the new platform location, and all usages in the file remain consistent.

server/datastore/mysql/mysql_test.go (1)

25-25: LGTM! Import path updated correctly.

The testing utilities import has been successfully migrated to the platform package location.

server/datastore/mysql/android_enterprise_test.go (1)

3-11: Import path migration for testing_utils looks correct

The switch to server/platform/mysql/testing_utils while continuing to call testing_utils.TruncateTables is consistent with the package move and keeps the test behavior unchanged.

Also applies to: 25-31

server/platform/arch_test.go (1)

93-110: LGTM! Well-structured architecture test.

The new test properly enforces that the platform/mysql package maintains decoupling from Fleet domain packages, consistent with the other platform package tests in this file.

server/datastore/mysql/operating_systems.go (1)

10-10: The code is correct as-is and requires no changes.

In Go, when you import a package without an alias, the package is referenced by its package declaration, not by its directory name or import path. Since all files in server/platform/mysql/ declare package common_mysql, the import statement "github.com/fleetdm/fleet/v4/server/platform/mysql" at line 10 automatically makes the package available as common_mysql. This is why common_mysql.DoRetryErr at line 102 compiles correctly and the import is actively used.

Likely an incorrect or invalid review comment.

@getvictor
Copy link
Member Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

✅ Actions performed

Full review triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
server/platform/mysql/list_options.go (1)

1-23: ListOptions interface + helpers look correct for platform boundary

The new ListOptions interface and AppendListOptionsWithParams mirror the previous pagination behavior while removing the direct dependency on fleet.ListOptions, which is appropriate for server/platform/mysql. Cursor predicate, ordering, and LIMIT/OFFSET are applied safely on sanitized column names.

Optionally, you might update the comment on Line 13 to say “this package” instead of “common_mysql package” to avoid confusion, but that’s purely cosmetic.

Also applies to: 53-103

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc0c7f1 and 4e81d48.

📒 Files selected for processing (55)
  • changes/37244-refactor-common_mysql
  • ee/server/service/certificate_authorities_test.go
  • ee/server/service/condaccess/idp_test.go
  • ee/server/service/hostidentity/depot/depot.go
  • ee/server/service/request_certificate_test.go
  • ee/server/service/software_installers.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/android_mysql.go
  • server/datastore/mysql/android_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/certificate_authorities.go
  • server/datastore/mysql/common_mysql/arch_test.go
  • server/datastore/mysql/config.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/host_identity_scep.go
  • server/datastore/mysql/hosts.go
  • server/datastore/mysql/hosts_test.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/migrations_test.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/policies.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/software.go
  • server/datastore/mysql/software_installers_test.go
  • server/datastore/mysql/software_titles.go
  • server/datastore/mysql/testing_utils.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/mdm/android/service/pubsub_test.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/platform/README.md
  • server/platform/arch_test.go
  • server/platform/mysql/batch.go
  • server/platform/mysql/batch_test.go
  • server/platform/mysql/common.go
  • server/platform/mysql/config.go
  • server/platform/mysql/errors.go
  • server/platform/mysql/list_options.go
  • server/platform/mysql/retry.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/service/integrationtest/suite.go
  • server/service/labels_test.go
  • server/service/osquery_utils/queries_test.go
  • server/service/software_title_icons_test.go
  • tools/mysql-tests/rds/iam_auth.go
💤 Files with no reviewable changes (1)
  • server/datastore/mysql/common_mysql/arch_test.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

⚙️ CodeRabbit configuration file

When reviewing SQL queries that are added or modified, ensure that appropriate filtering criteria are applied—especially when a query is intended to return data for a specific entity (e.g., a single host). Check for missing WHERE clauses or incorrect filtering that could lead to incorrect or non-deterministic results (e.g., returning the first row instead of the correct one). Flag any queries that may return unintended results due to lack of precise scoping.

Files:

  • server/platform/mysql/config.go
  • server/datastore/mysql/android_mysql.go
  • ee/server/service/hostidentity/depot/depot.go
  • server/service/integrationtest/suite.go
  • ee/server/service/request_certificate_test.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/datastore/mysql/policies.go
  • ee/server/service/condaccess/idp_test.go
  • server/datastore/mysql/host_identity_scep.go
  • server/platform/arch_test.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/platform/mysql/common.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/software_installers_test.go
  • tools/mysql-tests/rds/iam_auth.go
  • server/service/labels_test.go
  • server/datastore/mysql/android_test.go
  • server/datastore/mysql/migrations_test.go
  • server/service/software_title_icons_test.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • ee/server/service/certificate_authorities_test.go
  • server/platform/mysql/list_options.go
  • server/platform/mysql/errors.go
  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/mdm/android/service/pubsub_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/config.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • server/platform/mysql/batch.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/policies_test.go
  • server/platform/mysql/batch_test.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/software.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/datastore/mysql/certificate_authorities.go
  • ee/server/service/software_installers.go
  • server/platform/mysql/retry.go
  • server/datastore/mysql/software_titles.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/testing_utils.go
  • server/datastore/mysql/hosts.go
  • server/service/osquery_utils/queries_test.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/hosts_test.go
🧠 Learnings (14)
📚 Learning: 2025-08-08T07:40:05.301Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: In fleetdm/fleet repository tests (server/datastore/mysql/labels_test.go and similar), using testing.T.Context() is valid because the project targets a recent Go version where testing.T.Context() exists. Do not suggest replacing t.Context() with context.Background() in this codebase.

Applied to files:

  • server/datastore/mysql/android_mysql.go
  • ee/server/service/hostidentity/depot/depot.go
  • server/service/integrationtest/suite.go
  • ee/server/service/request_certificate_test.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/datastore/mysql/policies.go
  • ee/server/service/condaccess/idp_test.go
  • server/platform/arch_test.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/platform/mysql/common.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/software_installers_test.go
  • tools/mysql-tests/rds/iam_auth.go
  • server/service/labels_test.go
  • server/datastore/mysql/android_test.go
  • server/datastore/mysql/migrations_test.go
  • server/service/software_title_icons_test.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • ee/server/service/certificate_authorities_test.go
  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/mdm/android/service/pubsub_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/config.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • server/datastore/mysql/errors.go
  • changes/37244-refactor-common_mysql
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/software.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/datastore/mysql/certificate_authorities.go
  • ee/server/service/software_installers.go
  • server/platform/mysql/retry.go
  • server/datastore/mysql/software_titles.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/testing_utils.go
  • server/datastore/mysql/hosts.go
  • server/service/osquery_utils/queries_test.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/hosts_test.go
📚 Learning: 2025-08-08T07:40:05.301Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: Fleet repo targets Go 1.24.5 (root go.mod), which supports testing.T.Context(). Do not flag usage of t.Context() or suggest replacing it with context.Background() in tests (e.g., server/datastore/mysql/labels_test.go Line 2031 and similar).

Applied to files:

  • server/datastore/mysql/android_mysql.go
  • ee/server/service/hostidentity/depot/depot.go
  • server/service/integrationtest/suite.go
  • ee/server/service/request_certificate_test.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/datastore/mysql/policies.go
  • ee/server/service/condaccess/idp_test.go
  • server/platform/arch_test.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/platform/mysql/common.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/software_installers_test.go
  • tools/mysql-tests/rds/iam_auth.go
  • server/service/labels_test.go
  • server/datastore/mysql/android_test.go
  • server/datastore/mysql/migrations_test.go
  • server/service/software_title_icons_test.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • ee/server/service/certificate_authorities_test.go
  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/apple_mdm.go
  • server/mdm/android/service/pubsub_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/config.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • server/datastore/mysql/errors.go
  • changes/37244-refactor-common_mysql
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/software.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/datastore/mysql/certificate_authorities.go
  • ee/server/service/software_installers.go
  • server/platform/mysql/retry.go
  • server/datastore/mysql/software_titles.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go
  • server/datastore/mysql/testing_utils.go
  • server/datastore/mysql/hosts.go
  • server/service/osquery_utils/queries_test.go
  • server/datastore/mysql/android_enterprises.go
  • server/datastore/mysql/hosts_test.go
📚 Learning: 2025-08-08T07:40:05.301Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 31726
File: server/datastore/mysql/labels_test.go:2031-2031
Timestamp: 2025-08-08T07:40:05.301Z
Learning: In fleetdm/fleet, tests may validly use testing.T.Context() when the module/toolchain targets Go 1.24+. Do not flag t.Context() usage in this codebase if go.mod/toolchain indicates Go >= 1.24.

Applied to files:

  • server/datastore/mysql/android_mysql.go
  • server/service/integrationtest/suite.go
  • server/datastore/mysql/policies.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/software_installers_test.go
  • server/service/labels_test.go
  • server/datastore/mysql/migrations_test.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/mysql_test.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/software_titles.go
  • server/datastore/mysql/testing_utils.go
  • server/service/osquery_utils/queries_test.go
📚 Learning: 2025-07-08T16:12:48.797Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.

Applied to files:

  • server/datastore/mysql/android_mysql.go
  • ee/server/service/hostidentity/depot/depot.go
  • server/datastore/mysql/nanomdm_storage.go
  • server/platform/mysql/common.go
  • server/platform/mysql/retry.go
  • server/datastore/mysql/android_enterprises.go
📚 Learning: 2025-07-08T16:11:49.555Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 30589
File: ee/server/service/hostidentity/depot/depot.go:115-115
Timestamp: 2025-07-08T16:11:49.555Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the error from result.RowsAffected() is intentionally ignored because the information is only used for logging purposes, not for critical program logic.

Applied to files:

  • ee/server/service/hostidentity/depot/depot.go
📚 Learning: 2025-07-08T16:06:54.576Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 30589
File: ee/server/service/hostidentity/depot/depot.go:104-119
Timestamp: 2025-07-08T16:06:54.576Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the security concern where shared challenges allow certificate revocation (lines 104-119) is a known issue that will be addressed in a later feature, not an immediate concern to fix.

Applied to files:

  • ee/server/service/hostidentity/depot/depot.go
  • ee/server/service/request_certificate_test.go
  • ee/server/service/condaccess/idp_test.go
  • ee/server/service/certificate_authorities_test.go
📚 Learning: 2025-08-13T18:20:42.136Z
Learnt from: titanous
Repo: fleetdm/fleet PR: 31075
File: tools/redis-tests/elasticache/iam_auth.go:4-10
Timestamp: 2025-08-13T18:20:42.136Z
Learning: For test harnesses and CLI tools in the Fleet codebase, resource cleanup on error paths (like closing connections before log.Fatalf) may not be necessary since the OS handles cleanup when the process exits. These tools prioritize simplicity over defensive programming patterns used in production code.

Applied to files:

  • server/service/integrationtest/suite.go
  • server/datastore/mysql/vulnerabilities_test.go
  • server/datastore/mysql/policies.go
  • ee/server/service/condaccess/idp_test.go
  • server/datastore/mysql/android_enterprise_test.go
  • server/datastore/mysql/software_installers_test.go
  • server/service/labels_test.go
  • server/datastore/mysql/android_test.go
  • server/datastore/mysql/migrations_test.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/operating_systems.go
  • server/datastore/mysql/operating_system_vulnerabilities.go
  • server/platform/README.md
  • server/datastore/mysql/scripts_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/mysql_test.go
  • server/mdm/nanomdm/storage/mysql/mysql.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/android.go
  • server/datastore/mysql/software.go
  • server/platform/mysql/testing_utils/testing_utils.go
  • server/datastore/mysql/certificate_authorities.go
  • server/datastore/mysql/software_titles.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/service/osquery_utils/queries_test.go
📚 Learning: 2025-12-31T23:23:07.852Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 37245
File: server/datastore/mysql/common_mysql/list_options.go:56-73
Timestamp: 2025-12-31T23:23:07.852Z
Learning: In server/datastore/mysql/common_mysql/list_options.go, the strings.HasSuffix(orderKey, "id") check at line 62 never matches because orderKey is already sanitized with backticks, making the integer conversion code at line 63 unreachable dead code. However, this doesn't cause functional issues because MySQL automatically coerces string parameters to integers when comparing with integer columns in WHERE clauses.

Applied to files:

  • ee/server/service/condaccess/idp_test.go
  • server/datastore/mysql/nanomdm_storage.go
  • tools/mysql-tests/rds/iam_auth.go
  • server/datastore/mysql/android_device_test.go
  • server/datastore/mysql/mysql.go
  • ee/server/service/certificate_authorities_test.go
  • server/platform/mysql/list_options.go
  • server/mdm/android/service/pubsub_test.go
  • server/datastore/mysql/policies_test.go
  • server/datastore/mysql/software.go
  • ee/server/service/software_installers.go
  • server/datastore/mysql/software_titles.go
  • server/mdm/nanomdm/storage/mysql/queue.go
  • server/datastore/mysql/testing_utils.go
  • server/datastore/mysql/hosts.go
  • server/service/osquery_utils/queries_test.go
📚 Learning: 2025-08-20T21:24:59.261Z
Learnt from: sgress454
Repo: fleetdm/fleet PR: 31075
File: server/datastore/mysql/common_mysql/aws_iam_auth.go:111-130
Timestamp: 2025-08-20T21:24:59.261Z
Learning: In Fleet's MySQL IAM authentication implementation, the TLS and AllowCleartextPasswords configuration is handled in the generateMysqlConnectionString function in server/datastore/mysql/common_mysql/common.go, not in the awsIAMAuthConnector.Connect method. The connector receives a base DSN that already includes the necessary IAM authentication parameters.

Applied to files:

  • tools/mysql-tests/rds/iam_auth.go
  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/errors.go
  • server/datastore/mysql/apple_mdm_test.go
📚 Learning: 2025-08-20T21:24:59.261Z
Learnt from: sgress454
Repo: fleetdm/fleet PR: 31075
File: server/datastore/mysql/common_mysql/aws_iam_auth.go:111-130
Timestamp: 2025-08-20T21:24:59.261Z
Learning: In Fleet's MySQL IAM authentication implementation, the TLS and AllowCleartextPasswords configuration is handled in the generateMysqlConnectionString function in server/datastore/mysql/common_mysql/common.go. When no password is configured and the endpoint is an RDS endpoint, the function automatically sets allowCleartextPasswords=true and configures appropriate TLS settings. The awsIAMAuthConnector receives a properly configured base DSN and only needs to inject the IAM token as the password.

Applied to files:

  • tools/mysql-tests/rds/iam_auth.go
📚 Learning: 2025-08-01T15:08:16.858Z
Learnt from: sgress454
Repo: fleetdm/fleet PR: 31508
File: server/datastore/mysql/schema.sql:102-116
Timestamp: 2025-08-01T15:08:16.858Z
Learning: The schema.sql file in server/datastore/mysql/ is auto-generated from migrations for use with tests, so it cannot be manually edited. Any changes must be made through migrations.

Applied to files:

  • server/datastore/mysql/migrations_test.go
📚 Learning: 2025-12-11T23:02:59.284Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 36978
File: server/mdm/android/service/profiles.go:441-449
Timestamp: 2025-12-11T23:02:59.284Z
Learning: Fleet’s server/mdm/android/service.Service has fields ds (type fleet.AndroidDatastore) and fleetDS (type fleet.Datastore). The fleet.Datastore interface embeds AndroidDatastore (server/fleet/datastore.go), so assigning r.DS (a fleet.Datastore) to Service.ds is valid in Go due to interface-to-interface assignment using the dynamic type.

Applied to files:

  • server/datastore/mysql/mysql.go
  • server/datastore/mysql/apple_mdm.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/datastore/mysql/policies_test.go
  • ee/server/service/software_installers.go
  • server/datastore/mysql/hosts.go
  • server/datastore/mysql/hosts_test.go
📚 Learning: 2025-10-03T18:16:11.482Z
Learnt from: MagnusHJensen
Repo: fleetdm/fleet PR: 33805
File: server/service/integration_mdm_test.go:1248-1251
Timestamp: 2025-10-03T18:16:11.482Z
Learning: In server/service/integration_mdm_test.go, the helper createAppleMobileHostThenEnrollMDM(platform string) is exclusively for iOS/iPadOS hosts (mobile). Do not flag macOS model/behavior issues based on changes within this helper; macOS provisioning uses different helpers such as createHostThenEnrollMDM.

Applied to files:

  • server/datastore/mysql/apple_mdm.go
  • server/datastore/mysql/apple_mdm_test.go
📚 Learning: 2025-12-11T23:02:52.191Z
Learnt from: getvictor
Repo: fleetdm/fleet PR: 36978
File: server/mdm/android/service/profiles.go:441-449
Timestamp: 2025-12-11T23:02:52.191Z
Learning: In server/mdm/android/service, Go allows assigning an interface value of type fleet.Datastore to a field ds of type fleet.Datastore because the underlying dynamic type implements both the embedded AndroidDatastore (via fleet.Datastore embedding AndroidDatastore). When reviewing code in profiles.go and related files, verify assignments between interfaces respect embedding and ensure the concrete type actually implements all required interfaces. This pattern is valid wherever fleet.Datastore embeds AndroidDatastore and the receiver expects fleetDS or similar fields; prefer keeping interface boundaries clear and rely on the dynamic type to satisfy both interfaces.

Applied to files:

  • server/mdm/android/service/pubsub_test.go
🧬 Code graph analysis (1)
server/platform/arch_test.go (1)
server/archtest/archtest.go (1)
  • NewPackageTest (43-45)
🔇 Additional comments (52)
server/datastore/mysql/mysql_test.go (1)

25-25: LGTM! Clean import path update.

The import path update correctly reflects the package relocation from server/datastore/mysql/common_mysql/testing_utils to server/platform/mysql/testing_utils, consistent with the PR's refactoring objectives. All usages of testing_utils throughout the file remain syntactically valid.

ee/server/service/hostidentity/depot/depot.go (1)

21-21: LGTM! Clean refactoring with minimal changes.

The import path has been correctly updated to reference the new package location at server/platform/mysql, while preserving the common_mysql alias. This approach minimizes changes by keeping all usage sites (like line 125's common_mysql.WithRetryTxx) unchanged. The refactoring is consistent with the PR objective to relocate the common MySQL utilities.

server/datastore/mysql/host_identity_scep.go (1)

14-14: LGTM! Import path updated correctly.

The import path has been successfully updated to reference the relocated platform/mysql package with the common_mysql alias maintained for backward compatibility.

changes/37244-refactor-common_mysql (1)

1-1: LGTM! Changelog entry is clear and accurate.

The changelog appropriately documents the package refactoring and relocation to support bounded contexts within the Fleet codebase.

server/datastore/mysql/android.go (1)

14-14: LGTM! Import path updated correctly.

The import path has been successfully updated to reference the relocated platform/mysql package with the common_mysql alias. All usages of common_mysql.GetDefaultNonZeroTime() and common_mysql.NotFound() throughout the file remain consistent with the new import path.

server/datastore/mysql/operating_system_vulnerabilities.go (1)

12-12: LGTM! Import path updated correctly.

The import path has been successfully updated to reference the relocated platform/mysql package with the common_mysql alias. The usage of common_mysql.BatchProcessSimple() at line 1038 remains consistent with the new import path.

server/service/software_title_icons_test.go (1)

17-17: LGTM! Import path updated correctly.

The import path has been successfully updated to reference the relocated platform/mysql package with the common_mysql alias. All test mock functions using &common_mysql.NotFoundError{} throughout the file remain consistent with the new import path.

server/datastore/mysql/config.go (1)

7-7: LGTM! Import alias correctly applied.

The import now properly aliases server/platform/mysql as common_mysql, which aligns with all the common_mysql.DBOptions references throughout the file (lines 18-77). This resolves the concern from the previous review.

server/platform/mysql/testing_utils/testing_utils.go (1)

12-12: LGTM! Import path successfully updated.

The import correctly references the new server/platform/mysql location with the common_mysql alias, maintaining compatibility with all existing usages throughout the file.

server/datastore/mysql/migrations_test.go (1)

12-12: LGTM! Testing utilities import updated.

The import path correctly points to the new location at server/platform/mysql/testing_utils, and all references to testing_utils constants remain intact.

server/datastore/mysql/android_enterprise_test.go (1)

8-8: LGTM! Import path updated correctly.

The import now references server/platform/mysql/testing_utils, consistent with the package reorganization. Usage at line 27 remains unchanged.

server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go (2)

10-10: LGTM! Import alias correctly applied.

The import properly aliases server/platform/mysql as common_mysql, which aligns with the usage at line 248 (common_mysql.BatchProcessSimple). This resolves the concern from the previous review.


72-81: SQL queries properly scoped.

All SQL queries in this migration include appropriate filtering:

  • Lines 72-81: JOIN with WHERE clause to filter by fleet_enroll_ref
  • Lines 87-102: JOIN with WHERE clause filtering by source
  • Lines 123-135: Proper ordering for deterministic results
  • Lines 161-168: JOIN to match accounts by UUID
  • Lines 237-245: INSERT with ON DUPLICATE KEY UPDATE for idempotency

Also applies to: 87-102, 123-135, 161-168, 237-245

server/datastore/mysql/scripts_test.go (1)

13-13: LGTM: Import path correctly updated.

The import path has been properly updated to reflect the new package location at server/platform/mysql, while preserving the common_mysql alias to maintain compatibility with existing references throughout the test file.

server/platform/mysql/batch_test.go (1)

1-1: LGTM: Package declaration correctly updated.

The package name has been appropriately changed from common_mysql to mysql, aligning with the new directory structure and following Go naming conventions where the package name matches the directory name.

server/datastore/mysql/policies_test.go (1)

15-25: Import alias now correctly targets platform/mysql

Using common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql" keeps existing common_mysql.NotFoundError usages compiling and aligns this test with the new package location. No further changes needed here.

tools/mysql-tests/rds/iam_auth.go (1)

11-17: RDS test tool correctly updated to use platform/mysql DBOptions

The alias switch to server/platform/mysql and continued use of common_mysql.DBOptions with mysql.NewDB is consistent with the new shared MySQL utilities; IAM and TLS behavior remain centralized in the platform package.

Also applies to: 55-58, 65-67

server/datastore/mysql/mysql.go (1)

20-41: common_mysql alias correctly re-pointed to platform/mysql

Rebinding common_mysql to server/platform/mysql while keeping all existing common_mysql.* usages (DBOptions/DBConnections, Tx helpers, NewDB, list-options facades) preserves behavior and fixes the earlier broken import/alias combination. The datastore continues to treat platform/mysql as the shared MySQL utility layer without pulling in domain types into the platform package.

Also applies to: 72-75, 207-227, 232-283, 382-446, 829-846

server/datastore/mysql/apple_mdm.go (1)

29-29: Import alias update to platform/mysql is consistent

The alias common_mysql now pointing at server/platform/mysql matches the refactor and keeps existing usages (e.g., common_mysql.BatchProcessSimple, common_mysql.DBReadTx) working without behavioral change.

server/platform/mysql/batch.go (1)

1-1: Package rename to mysql aligns with new platform package

Renaming the package to mysql under server/platform/mysql is consistent with the refactor, and existing callers that import it as common_mysql remain valid.

server/mdm/nanomdm/storage/mysql/mysql.go (1)

16-16: WithRetryTxx import moved to platform/mysql without behavior change

Switching common_mysql to server/platform/mysql keeps updateLastSeenBatch’s WithRetryTxx usage intact and matches the new shared MySQL helpers location.

server/platform/mysql/retry.go (1)

1-1: Retry helper package renamed to mysql as expected

The retry utilities now live under server/platform/mysql with package mysql; callers importing this as common_mysql continue to work with unchanged behavior.

server/service/labels_test.go (1)

17-17: Label service tests now target platform/mysql testing utilities

Updating the testing utilities import to server/platform/mysql/testing_utils aligns with the common_mysql → platform/mysql move without altering test behavior.

server/platform/mysql/config.go (1)

1-1: LGTM! Package declaration correctly updated.

The package declaration has been correctly changed from package common_mysql to package mysql, aligning with the new location at server/platform/mysql. Import sites maintain backward compatibility by aliasing the import as common_mysql.

server/datastore/mysql/android_enterprises.go (1)

10-10: LGTM! Import correctly updated with alias.

The import has been successfully updated to reference the new server/platform/mysql location with the common_mysql alias. All usages of common_mysql.NotFound throughout the file (Lines 31, 44, 57, 80) remain correct.

server/datastore/mysql/vulnerabilities_test.go (1)

10-10: LGTM! Test import correctly updated.

The import has been successfully updated to the new server/platform/mysql path with the common_mysql alias preserved. All usages of common_mysql.NotFoundError (Lines 176, 285) remain correct and compilation-safe.

ee/server/service/condaccess/idp_test.go (1)

14-14: LGTM! Import path correctly updated with alias.

The import has been properly updated to reference the new platform/mysql location while preserving the common_mysql alias, ensuring all existing call sites (like line 308's common_mysql.NotFound("certificate")) continue to work without modification.

server/platform/mysql/errors.go (1)

1-1: LGTM! Package renamed as part of refactor.

The package declaration correctly changes from common_mysql to mysql as part of the relocation to server/platform/mysql. This aligns with the PR objective to move and reorganize the MySQL utilities under the platform package.

server/mdm/nanomdm/storage/mysql/queue.go (1)

12-12: LGTM! Import migration complete and correct.

The import path has been successfully updated to server/platform/mysql with the common_mysql alias, ensuring all usages of common_mysql.WithRetryTxx (lines 69, 271) and common_mysql.BatchProcessSimple (line 297) remain functional without code changes.

server/service/integrationtest/suite.go (1)

12-12: LGTM! Test utilities import path updated correctly.

The import path for testing_utils has been properly migrated from the old datastore/mysql/common_mysql/testing_utils location to the new platform/mysql/testing_utils path, maintaining compatibility with existing usage at line 57.

server/datastore/mysql/android_mysql.go (1)

10-10: LGTM! Android datastore import successfully migrated.

The import has been correctly updated to reference server/platform/mysql with the common_mysql alias, preserving all existing references to common_mysql.TxFn and the retry helper functions at lines 47-48 and 51-52.

server/datastore/mysql/operating_systems.go (1)

10-10: Import alias points correctly to relocated common MySQL helpers

The alias common_mysql now targets server/platform/mysql while preserving existing usages (e.g., common_mysql.DoRetryErr), so this refactor is consistent and safe.

server/datastore/mysql/hosts.go (1)

23-23: Alias for platform/mysql correctly matches existing usages

Using common_mysql as an alias for server/platform/mysql aligns with all common_mysql.DefaultNonZeroTime references and fixes the earlier missing-alias problem.

server/mdm/android/service/pubsub_test.go (1)

18-18: Test import alias correctly updated to new platform package

The common_mysql alias now targets server/platform/mysql, so all common_mysql.NotFound(...) test expectations remain valid and compile.

server/datastore/mysql/android_test.go (1)

13-13: LGTM! Import path correctly updated.

The import path has been successfully updated from the old server/datastore/mysql/common_mysql location to the new server/platform/mysql location, maintaining the common_mysql alias to preserve existing code references (e.g., line 1733). This change aligns with the PR's objective to consolidate MySQL utilities under the platform package.

server/datastore/mysql/apple_mdm_test.go (1)

29-29: Import path relocation looks correct and non-breaking

The alias common_mysql is preserved while updating the import to server/platform/mysql, so existing uses (e.g., common_mysql.NotFoundError) remain valid and the change cleanly aligns tests with the new package location.

ee/server/service/certificate_authorities_test.go (1)

21-21: Import refactor correctly implemented.

The import path has been successfully updated to the new location with the common_mysql alias, and all references throughout the file use this alias correctly. The past review concerns about compilation errors have been resolved.

ee/server/service/request_certificate_test.go (1)

20-20: Import path correctly updated.

The import has been properly updated to reference the new package location with the common_mysql alias, and line 146's usage of common_mysql.NotFound is correct.

server/datastore/mysql/certificate_authorities.go (1)

13-13: Import refactor correctly applied.

The import path update is correct with the common_mysql alias properly maintained. All references to common_mysql.NotFound throughout the file (lines 57, 389, 406) are consistent with the alias.

server/platform/mysql/common.go (1)

1-1: Package rename correctly implemented.

The package declaration has been appropriately changed from common_mysql to mysql to align with the new location at server/platform/mysql. Import sites maintain backward compatibility by using the common_mysql alias.

server/datastore/mysql/nanomdm_storage.go (1)

20-20: Import path successfully updated.

The import has been correctly updated to the new location with the common_mysql alias. All references to common_mysql.WithRetryTxx throughout the file (lines 199, 246, 272, 314) properly use the alias and will compile without errors.

server/datastore/mysql/scim.go (1)

12-12: Import alias correctly updated to new common MySQL utilities

Aliasing server/platform/mysql as common_mysql keeps existing common_mysql.BatchProcessSimple call sites compiling and avoids any package-name conflict with the local mysql package. Looks good.

server/datastore/mysql/software.go (1)

19-19: Alias to platform MySQL utilities is consistent with call sites

The import now correctly aliases server/platform/mysql as common_mysql, matching usages of common_mysql.RetryableError and common_mysql.BatchProcessSimple and avoiding any name clash with the mysql package.

ee/server/service/software_installers.go (1)

30-30: Import alias correctly updated to platform/mysql

The common_mysql alias now points to server/platform/mysql and matches the common_mysql.NotFound(...) usage later in the file, so the refactor compiles cleanly and behavior remains unchanged.

server/datastore/mysql/testing_utils.go (1)

34-35: Platform MySQL imports and alias are now consistent with usages

common_mysql is aliased to server/platform/mysql, and testing_utils to server/platform/mysql/testing_utils, matching all common_mysql.TestSQLMode / common_mysql.DBOptions and testing_utils.MysqlTestConfig usages so tests will build correctly after the move.

server/datastore/mysql/software_installers_test.go (1)

19-20: Alias common_mysql now correctly targets platform/mysql

The tests now import server/platform/mysql as common_mysql, so common_mysql.NotFoundError and the shared MySQL helpers resolve correctly, and the new testing_utils path matches the refactored location.

server/datastore/mysql/policies.go (1)

17-17: LGTM! Clean import path update.

The import path has been correctly updated to reference the new package location while maintaining the common_mysql alias for backward compatibility with existing usages in this file (lines 443 and 2164).

server/datastore/mysql/hosts_test.go (1)

30-40: Import relocation to server/platform/mysql is correct and non-breaking

The alias remains common_mysql and GetDefaultNonZeroTime() is used exactly as before, so this cleanly switches the dependency to the new shared platform/mysql package without behavioral changes. This matches the PR’s refactor goal.

server/service/osquery_utils/queries_test.go (1)

31-31: LGTM! Import path correctly updated.

The import path has been successfully updated to use server/platform/mysql with the common_mysql alias, maintaining compatibility with existing usages throughout the test file.

server/platform/README.md (1)

1-16: Excellent documentation of architectural boundaries.

This README clearly explains the platform vs domain separation, provides concrete guidelines, and references the enforcement mechanism via arch_test.go. The documentation will help maintainers understand and respect these architectural boundaries.

server/platform/arch_test.go (1)

94-110: Well-structured architectural test.

The TestMysqlPackageDependencies test correctly enforces that the mysql platform package doesn't depend on Fleet domain packages. It follows the same pattern as other tests in this file and appropriately ignores internal platform dependencies.

server/datastore/mysql/errors.go (1)

16-16: Import correctly updated.

The import path now references server/platform/mysql with the common_mysql alias, maintaining compatibility with the existing notFound function and other error helpers.

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

Nit: Worth sticking to one either platform_ or common_ for import prefixing (we used platform_http for imports of server/platform/http).

@getvictor
Copy link
Member Author

Nit: Worth sticking to one either platform_ or common_ for import prefixing (we used platform_http for imports of server/platform/http).

Yes, I prefer platform_mysql. I just kept common_mysql here to minimize the diffs.

@getvictor getvictor merged commit 5069014 into main Jan 8, 2026
49 checks passed
@getvictor getvictor deleted the victor/37244-move-common_mysql branch January 8, 2026 19: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.

Refactor common_mysql into platform/mysql

5 participants