Fixed issue with duplicated category index on PiwigoId when Id is not yet known

release/legacyGoVersion
Philipp Häfelfinger 5 years ago
parent 321c18b6bd
commit 355d2a5f51

@ -488,7 +488,7 @@ func (d *LocalDataStore) createTablesIfNeeded(db *sql.DB) error {
return err
}
_, err = db.Exec("CREATE UNIQUE INDEX IF NOT EXISTS UX_Category_PiwigoId ON category (piwigoId);")
_, err = db.Exec("CREATE UNIQUE INDEX IF NOT EXISTS UX_Category_PiwigoId ON category (piwigoId) WHERE piwigoId > 0;")
if err != nil {
return err
}

@ -306,6 +306,34 @@ func Test_saveCategory_should_store_records(t *testing.T) {
}
}
func Test_saveCategory_should_store_multiple_records_with_piwigoid_zero(t *testing.T) {
if !dbinitOk {
t.Skip("Skipping test as TestDataStoreInitialize failed!")
}
dataStore := setupDatabase(t)
defer cleanupDatabase(t)
category1 := getExampleCategoryData("2019")
category1.PiwigoId = 0
category2 := getExampleCategoryData("2020")
category2.PiwigoId = 0
saveCategoryShouldNotFail("addcategory", dataStore, category1, t)
category1.CategoryId = 1
saveCategoryShouldNotFail("addcategory", dataStore, category2, t)
category2.CategoryId = 2
_, err := dataStore.GetCategoryByKey(category1.Key)
if err != nil {
t.Fatalf("Could not query category! %s", err)
}
_, err = dataStore.GetCategoryByKey(category2.Key)
if err != nil {
t.Fatalf("Could not query category! %s", err)
}
}
func Test_saveCategory_should_update_records(t *testing.T) {
if !dbinitOk {
t.Skip("Skipping test as TestDataStoreInitialize failed!")

Loading…
Cancel
Save