-
Notifications
You must be signed in to change notification settings - Fork 925
Add "Support" default software category #47923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
allenhouchins
wants to merge
1
commit into
main
Choose a base branch
from
allen/add-support-software-category
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Added "π Support" as a new default self-service software category. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
server/datastore/mysql/migrations/tables/20260619120000_AddSupportSoftwareCategory.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package tables | ||
|
|
||
| import ( | ||
| "database/sql" | ||
|
|
||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| func init() { | ||
| MigrationClient.AddMigration(Up_20260619120000, Down_20260619120000) | ||
| } | ||
|
|
||
| func Up_20260619120000(tx *sql.Tx) error { | ||
| // Add the new "π Support" default self-service software category so it | ||
| // matches fleet.DefaultSelfServiceCategoryNames, which is used when seeding | ||
| // categories for newly created fleets. | ||
|
|
||
| // Global (team_id=0) default row. Pin both timestamps to the same constant | ||
| // the previous category migration used so the generated schema stays | ||
| // deterministic across repeated runs of make dump-test-schema. | ||
| if _, err := tx.Exec(` | ||
| INSERT IGNORE INTO software_categories (name, team_id, created_at, updated_at) | ||
| VALUES ('π Support', 0, '2026-05-29 00:00:00', '2026-05-29 00:00:00') | ||
| `); err != nil { | ||
| return errors.Wrap(err, "inserting default Support software category") | ||
| } | ||
|
|
||
| // Give every existing fleet its own copy of the new default, matching the | ||
| // per-fleet backfill done when the categories were first scoped by team. | ||
| if _, err := tx.Exec(` | ||
| INSERT IGNORE INTO software_categories (name, team_id) | ||
| SELECT 'π Support', t.id FROM teams t | ||
| `); err != nil { | ||
| return errors.Wrap(err, "backfilling Support category per fleet") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func Down_20260619120000(tx *sql.Tx) error { | ||
| return nil | ||
| } |
49 changes: 49 additions & 0 deletions
49
server/datastore/mysql/migrations/tables/20260619120000_AddSupportSoftwareCategory_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package tables | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestUp_20260619120000(t *testing.T) { | ||
| db := applyUpToPrev(t) | ||
|
|
||
| // The global defaults seeded by earlier migrations should not yet include | ||
| // the new "π Support" category. | ||
| var preCount int | ||
| require.NoError(t, db.Get(&preCount, | ||
| `SELECT COUNT(*) FROM software_categories WHERE team_id = 0 AND name = 'π Support'`)) | ||
| require.Equal(t, 0, preCount, "Support should not exist before this migration") | ||
|
|
||
| // Two existing fleets so the per-fleet backfill has rows to touch. | ||
| teamA := uint(execNoErrLastID(t, db, `INSERT INTO teams (name) VALUES (?)`, "team-a")) //nolint:gosec // dismiss G115 | ||
| teamB := uint(execNoErrLastID(t, db, `INSERT INTO teams (name) VALUES (?)`, "team-b")) //nolint:gosec // dismiss G115 | ||
|
|
||
| applyNext(t, db) | ||
|
|
||
| // The global default now exists exactly once at team_id=0. | ||
| type categoryRow struct { | ||
| ID uint `db:"id"` | ||
| Name string `db:"name"` | ||
| TeamID uint `db:"team_id"` | ||
| CreatedAt time.Time `db:"created_at"` | ||
| UpdatedAt time.Time `db:"updated_at"` | ||
| } | ||
| var globalRows []categoryRow | ||
| require.NoError(t, db.Select(&globalRows, | ||
| `SELECT id, name, team_id, created_at, updated_at FROM software_categories WHERE team_id = 0 AND name = 'π Support'`)) | ||
| require.Len(t, globalRows, 1, "Support should be added exactly once at team_id=0") | ||
| // Timestamps are pinned to a constant so the generated schema stays stable. | ||
| require.Equal(t, "2026-05-29", globalRows[0].CreatedAt.Format("2006-01-02"), "timestamps should be pinned for schema-dump stability") | ||
| require.Equal(t, "2026-05-29", globalRows[0].UpdatedAt.Format("2006-01-02")) | ||
|
|
||
| // Each existing fleet got its own copy. | ||
| for _, teamID := range []uint{teamA, teamB} { | ||
| var count int | ||
| require.NoError(t, db.Get(&count, | ||
| `SELECT COUNT(*) FROM software_categories WHERE team_id = ? AND name = 'π Support'`, teamID)) | ||
| require.Equal(t, 1, count, "fleet %d should have its own Support category", teamID) | ||
| } | ||
| } | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.