Fixed violation of the unique constraint for v68 migration
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
This commit is contained in:
parent
0b3ea42847
commit
6554ff104e
|
|
@ -45,6 +45,8 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
|
||||||
if models.ValidateTopic(topic.Name) {
|
if models.ValidateTopic(topic.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
log.Info("Incorrect topic: id = %v, name = %q", topic.ID, topic.Name)
|
||||||
|
|
||||||
topic.Name = strings.Replace(strings.TrimSpace(strings.ToLower(topic.Name)), " ", "-", -1)
|
topic.Name = strings.Replace(strings.TrimSpace(strings.ToLower(topic.Name)), " ", "-", -1)
|
||||||
|
|
||||||
if err := sess.Table("repo_topic").Cols("repo_id").
|
if err := sess.Table("repo_topic").Cols("repo_id").
|
||||||
|
|
@ -56,14 +58,20 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if models.ValidateTopic(topic.Name) {
|
if models.ValidateTopic(topic.Name) {
|
||||||
log.Info("Updating topic: id = %v, name = %v", topic.ID, topic.Name)
|
count, err := sess.Where("name = ?", topic.Name).Count(&Topic{})
|
||||||
if _, err := sess.Table("topic").ID(topic.ID).
|
if err != nil {
|
||||||
Update(&Topic{Name: topic.Name}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
if count == 0 {
|
||||||
delTopicIDs = append(delTopicIDs, topic.ID)
|
log.Info("Updating topic: id = %v, name = %q", topic.ID, topic.Name)
|
||||||
|
if _, err := sess.Table("topic").ID(topic.ID).
|
||||||
|
Update(&Topic{Name: topic.Name}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
delTopicIDs = append(delTopicIDs, topic.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user