feat(migration): ignore namespace changes

This commit is contained in:
kolaente 2022-12-29 18:13:07 +01:00
parent e8e2e205f4
commit c05ed95ba9
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 1 additions and 23 deletions

View File

@ -30,7 +30,7 @@ import (
)
// InsertFromStructure takes a fully nested Vikunja data structure and a user and then creates everything for this user
// (Namespaces, tasks, etc. Even attachments and relations.)
// (Projects, tasks, etc. Even attachments and relations.)
func InsertFromStructure(str []*models.ProjectWithTasksAndBuckets, user *user.User) (err error) {
s := db.NewSession()
defer s.Close()
@ -52,28 +52,16 @@ func insertFromStructure(s *xorm.Session, str []*models.ProjectWithTasksAndBucke
labels := make(map[string]*models.Label)
archivedProjects := []int64{}
archivedNamespaces := []int64{}
// Create all namespaces
for _, p := range str {
p.ID = 0
// Saving the archived status to archive the namespace again after creating it
var wasArchived bool
if p.IsArchived {
p.IsArchived = false
wasArchived = true
}
err = p.Create(s, user)
if err != nil {
return
}
if wasArchived {
archivedNamespaces = append(archivedNamespaces, p.ID)
}
log.Debugf("[creating structure] Created project %d", p.ID)
log.Debugf("[creating structure] Creating %d projects", len(p.ChildProjects))
@ -287,16 +275,6 @@ func insertFromStructure(s *xorm.Session, str []*models.ProjectWithTasksAndBucke
}
}
if len(archivedNamespaces) > 0 {
_, err = s.
Cols("is_archived").
In("id", archivedNamespaces).
Update(&models.Project{IsArchived: true})
if err != nil {
return err
}
}
log.Debugf("[creating structure] Done inserting new task structure")
return nil