diff --git a/server/model.go b/server/model.go index 83c27ef0..e9e662f8 100644 --- a/server/model.go +++ b/server/model.go @@ -132,7 +132,7 @@ func (name *TokenV2) BeforeSave(tx *gorm.DB) error { type Artist struct { gorm.Model - Name string `gorm:"uniqueIndex:idx_artist_name,where:current_artist_id IS NULL AND deleted_at IS NULL"` + Name string `gorm:"uniqueIndex:idx_artist_name_v2,where:current_artist_id IS NULL AND deleted_at IS NULL"` AdditionalNames []AdditionalName `gorm:"many2many:artists_additional_name"` CurrentArtistID *uint CurrentArtist *Artist @@ -189,8 +189,8 @@ var MediaTypes []MediaType = []MediaType{ type MediaDB struct { gorm.Model - Name string `json:"name" example:"Shinseiki Evangelion" gorm:"uniqueIndex:idx_media_name_type,where:current_media_id IS NULL AND deleted_at IS NULL"` - Type string `json:"media_type" example:"ANIME" gorm:"uniqueIndex:idx_media_name_type,where:current_media_id IS NULL AND deleted_at IS NULL"` + Name string `json:"name" example:"Shinseiki Evangelion" gorm:"uniqueIndex:idx_media_name_type_v2,where:current_media_id IS NULL AND deleted_at IS NULL"` + Type string `json:"media_type" example:"ANIME" gorm:"uniqueIndex:idx_media_name_type_v2,where:current_media_id IS NULL AND deleted_at IS NULL"` AdditionalNames []AdditionalName `json:"additional_name" gorm:"many2many:media_additional_name"` CurrentMediaID *uint CurrentMedia *MediaDB @@ -458,6 +458,20 @@ func init_model(db *gorm.DB) { if err != nil { panic(err) } + + // PR #73 + if db.Migrator().HasIndex(&Artist{}, "idx_artist_name") { + err = db.Migrator().DropIndex(&Artist{}, "idx_artist_name") + if err != nil { + panic(err) + } + } + if db.Migrator().HasIndex(&MediaDB{}, "idx_media_name_type") { + err = db.Migrator().DropIndex(&MediaDB{}, "idx_media_name_type") + if err != nil { + panic(err) + } + } } func createAdditionalNames(names []string) []AdditionalName {