Bug 7441: Upgrading to 4.19.0 might fail due to migration (#7446)

* Make Change software vendor width mig. more robust

If there are two or more entries in the software table with the same name, version, source, release and arch but different vendors then the migration used for increasing the vendor width will fail.
This commit is contained in:
Juan Fernandez 2022-08-30 11:20:48 -04:00 committed by GitHub
parent 8157359f84
commit 87717df1da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 12 deletions

View file

@ -0,0 +1,2 @@
If there are two or more entries in the software table with the same name, version, source, release
and arch but different vendors then the migration used for increasing the vendor width will fail.

View file

@ -16,17 +16,11 @@ func Up_20220818101352(tx *sql.Tx) error {
//-----------------
// Add temp column.
//-----------------
if _, err := tx.Exec(
`ALTER TABLE software ADD COLUMN vendor_wide varchar(114) DEFAULT '' NOT NULL, ALGORITHM=INPLACE, LOCK=NONE`); err != nil {
return errors.Wrapf(err, "creating temp column for vendor")
}
//---------------------
// Add uniq constraint
//---------------------
if _, err := tx.Exec(
"ALTER TABLE software ADD constraint unq_name UNIQUE (name, version, source, `release`, vendor_wide, arch)"); err != nil {
return errors.Wrapf(err, "adding new uniquess constraint")
if !columnExists(tx, "software", "vendor_wide") {
if _, err := tx.Exec(
`ALTER TABLE software ADD COLUMN vendor_wide varchar(114) DEFAULT '' NOT NULL, ALGORITHM=INPLACE, LOCK=NONE`); err != nil {
return errors.Wrapf(err, "creating temp column for vendor")
}
}
//------------------
@ -38,6 +32,14 @@ func Up_20220818101352(tx *sql.Tx) error {
return errors.Wrapf(err, "updating temp vendor column")
}
//---------------------
// Add uniq constraint
//---------------------
if _, err := tx.Exec(
"ALTER TABLE software ADD constraint unq_name UNIQUE (name, version, source, `release`, vendor_wide, arch)"); err != nil {
return errors.Wrapf(err, "adding new uniquess constraint")
}
//----------------
// Drop old index
//----------------

View file

@ -12,6 +12,7 @@ func TestUp_20220818101352(t *testing.T) {
_, err := db.Exec(`INSERT INTO software (name, version, source, bundle_identifier, vendor, arch)
VALUES
('zchunk-libs', '1.2.1', 'rpm_packages', '', 'Fedora Project', 'x86_64'),
('zchunk-libs', '1.2.1', 'rpm_packages', '', 'Fedora Project II', 'x86_64'),
('word', '1.2.1', 'rpm_packages', '', 'Fake MS', 'x86_64'),
('excel', '1.2.1', 'rpm_packages', '', '', 'x86_64')
`)
@ -24,7 +25,7 @@ func TestUp_20220818101352(t *testing.T) {
var vendors []string
err = db.Select(&vendors, `SELECT vendor FROM software`)
require.NoError(t, err)
require.ElementsMatch(t, []string{"Fedora Project", "Fake MS", ""}, vendors)
require.ElementsMatch(t, []string{"Fedora Project", "Fedora Project II", "Fake MS", ""}, vendors)
// Check we can store a longer vendors
randVendor := `