-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow software titles for software named the same but with different
bundle identifiers Updated software_titles unique index `idx_sw_titles` to include bundle identifier. Changed the column type of `software_titles.source` & `software_titles.bundle_identifier` to use ascii. Using `utf8mb4` caused the `idx_sw_titles` index to be too large when including `name`, `source`,`browser`,`bundle_identifier`.
- Loading branch information
Showing
6 changed files
with
251 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,2 @@ | ||
* Updated software_titles.source & software_titles.bundle_identifier to use ascii | ||
* Updated software_titles unique index idx_sw_titles to include bundle_identifier. Code modified to handle software named the same but have different bundle identifiers |
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 (source, coalesce_bundle_name, 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: "source"}, | ||
{ColumnName: "coalesce_bundle_name"}, | ||
{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