Skip to content

Commit

Permalink
server: artist/media create new index, drop previous one
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Aug 24, 2024
1 parent b2f80cc commit 0c6c391
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions server/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0c6c391

Please sign in to comment.