feat(migration): ignore namespace changes
This commit is contained in:
parent
386e218b95
commit
ac0d84a7d8
@ -30,7 +30,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// InsertFromStructure takes a fully nested Vikunja data structure and a user and then creates everything for this user
|
// 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) {
|
func InsertFromStructure(str []*models.ProjectWithTasksAndBuckets, user *user.User) (err error) {
|
||||||
s := db.NewSession()
|
s := db.NewSession()
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
@ -52,28 +52,16 @@ func insertFromStructure(s *xorm.Session, str []*models.ProjectWithTasksAndBucke
|
|||||||
labels := make(map[string]*models.Label)
|
labels := make(map[string]*models.Label)
|
||||||
|
|
||||||
archivedProjects := []int64{}
|
archivedProjects := []int64{}
|
||||||
archivedNamespaces := []int64{}
|
|
||||||
|
|
||||||
// Create all namespaces
|
// Create all namespaces
|
||||||
for _, p := range str {
|
for _, p := range str {
|
||||||
p.ID = 0
|
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)
|
err = p.Create(s, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if wasArchived {
|
|
||||||
archivedNamespaces = append(archivedNamespaces, p.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("[creating structure] Created project %d", p.ID)
|
log.Debugf("[creating structure] Created project %d", p.ID)
|
||||||
log.Debugf("[creating structure] Creating %d projects", len(p.ChildProjects))
|
log.Debugf("[creating structure] Creating %d projects", len(p.ChildProjects))
|
||||||
|
|
||||||
@ -290,16 +278,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")
|
log.Debugf("[creating structure] Done inserting new task structure")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user