Merge pull request #9364 from wy65701436/fix-migration-rerun

fix quota migration still execute on launch even data sync success
This commit is contained in:
Wenkai Yin(尹文开) 2019-10-11 11:23:17 +08:00 committed by GitHub
commit 64f7e3bc65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,17 +85,22 @@ func updateInitPassword(userID int, password string) error {
// Quota migration
func quotaSync() error {
usages, err := dao.ListQuotaUsages()
if err != nil {
log.Errorf("list quota usage error, %v", err)
return err
}
projects, err := dao.GetProjects(nil)
if err != nil {
log.Errorf("list project error, %v", err)
return err
}
var pids []string
for _, project := range projects {
pids = append(pids, strconv.FormatInt(project.ProjectID, 10))
}
usages, err := dao.ListQuotaUsages(&models.QuotaUsageQuery{Reference: "project", ReferenceIDs: pids})
if err != nil {
log.Errorf("list quota usage error, %v", err)
return err
}
// The condition handles these two cases:
// 1, len(project) > 1 && len(usages) == 1. existing projects without usage, as we do always has 'library' usage in DB.
// 2, migration fails at the phase of inserting usage into DB, and parts of them are inserted successfully.