-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated software_titles unique index
idx_sw_titles
to use bundle
identifier when present This allows software with different names but the same bundle identifier to be grouped under the same title. It also allows for software with the same name but different bundle identifiers to be under two separate titles.
- Loading branch information
Showing
6 changed files
with
250 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
* Updated software_titles unique index `idx_sw_titles` to use `bundle_identifier` when present instead of `name`. |
48 changes: 48 additions & 0 deletions
48
server/datastore/mysql/migrations/tables/20250124194347_UpdateSoftwareTitlesUniqueIndex.go
This file contains 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,48 @@ | ||
package tables | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
) | ||
|
||
func init() { | ||
MigrationClient.AddMigration(Up_20250124194347, Down_20250124194347) | ||
} | ||
|
||
func Up_20250124194347(tx *sql.Tx) error { | ||
if _, err := tx.Exec(` | ||
ALTER TABLE software_titles | ||
ADD COLUMN coalesce_bundle_name VARCHAR(255) GENERATED ALWAYS AS (COALESCE(bundle_identifier, name)) STORED; | ||
`); err != nil { | ||
return fmt.Errorf("failed to add generated column: %w", err) | ||
} | ||
|
||
if _, err := tx.Exec(` | ||
ALTER TABLE software_titles | ||
DROP INDEX idx_sw_titles, | ||
ADD UNIQUE INDEX idx_sw_titles (coalesce_bundle_name, source, browser); | ||
`); err != nil { | ||
return fmt.Errorf("failed to add vpp_apps_teams_id to policies: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Down_20250124194347(tx *sql.Tx) error { | ||
if _, err := tx.Exec(` | ||
ALTER TABLE software_titles | ||
DROP COLUMN coalesce_bundle_name | ||
`); err != nil { | ||
return fmt.Errorf("failed to remove generated column: %w", err) | ||
} | ||
|
||
if _, err := tx.Exec(` | ||
ALTER TABLE software_titles | ||
DROP INDEX idx_sw_titles, | ||
ADD UNIQUE KEY idx_sw_titles (name, source, browser); | ||
`); err != nil { | ||
return fmt.Errorf("failed to add vpp_apps_teams_id to policies: %w", err) | ||
} | ||
|
||
return nil | ||
} |
50 changes: 50 additions & 0 deletions
50
.../datastore/mysql/migrations/tables/20250124194347_UpdateSoftwareTitlesUniqueIndex_test.go
This file contains 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,50 @@ | ||
package tables | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestUp_20250124194347(t *testing.T) { | ||
db := applyUpToPrev(t) | ||
|
||
var softwareTitles []struct { | ||
ColumnName string `db:"COLUMN_NAME"` | ||
} | ||
|
||
sel := `SELECT COLUMN_NAME | ||
FROM information_schema.statistics | ||
WHERE table_schema = DATABASE() | ||
AND table_name = 'software_titles' | ||
AND index_name = 'idx_sw_titles' | ||
ORDER BY seq_in_index;` | ||
|
||
err := db.Select(&softwareTitles, sel) | ||
if err != nil { | ||
t.Fatalf("Failed to get index information: %v", err) | ||
} | ||
expected := []struct { | ||
ColumnName string `db:"COLUMN_NAME"` | ||
}{ | ||
{ColumnName: "name"}, | ||
{ColumnName: "source"}, | ||
{ColumnName: "browser"}, | ||
} | ||
require.Equal(t, expected, softwareTitles) | ||
|
||
applyNext(t, db) | ||
|
||
err = db.Select(&softwareTitles, sel) | ||
if err != nil { | ||
t.Fatalf("Failed to get index information: %v", err) | ||
} | ||
expected = []struct { | ||
ColumnName string `db:"COLUMN_NAME"` | ||
}{ | ||
{ColumnName: "coalesce_bundle_name"}, | ||
{ColumnName: "source"}, | ||
{ColumnName: "browser"}, | ||
} | ||
require.Equal(t, expected, softwareTitles) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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