diff --git a/pkg/migration/20240315110428.go b/pkg/migration/20240315110428.go index b2ae07ba8..dd421dfba 100644 --- a/pkg/migration/20240315110428.go +++ b/pkg/migration/20240315110428.go @@ -78,8 +78,9 @@ func init() { if view.ViewKind == 3 { // Kanban view pos := taskBuckets20240315110428{ - TaskID: task.ID, - BucketID: task.BucketID, + TaskID: task.ID, + BucketID: task.BucketID, + ProjectViewID: view.ID, } _, err = tx.Insert(pos) diff --git a/pkg/migration/20240406125227.go b/pkg/migration/20240406125227.go new file mode 100644 index 000000000..0bc145bb6 --- /dev/null +++ b/pkg/migration/20240406125227.go @@ -0,0 +1,83 @@ +// Vikunja is a to-do list application to facilitate your life. +// Copyright 2018-present Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public Licensee as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public Licensee for more details. +// +// You should have received a copy of the GNU Affero General Public Licensee +// along with this program. If not, see . + +package migration + +import ( + "src.techknowlogick.com/xormigrate" + "xorm.io/xorm" +) + +type taskBucket20240406125227 struct { + BucketID int64 `xorm:"bigint not null index"` + TaskID int64 `xorm:"bigint not null index"` + ProjectViewID int64 `xorm:"bigint not null index"` +} + +func (taskBucket20240406125227) TableName() string { + return "task_buckets" +} + +type bucket20240406125227 struct { + ID int64 `xorm:"bigint autoincr not null unique pk" json:"id" param:"bucket"` + ProjectViewID int64 `xorm:"bigint not null" json:"project_view_id" param:"view"` +} + +func (bucket20240406125227) TableName() string { + return "buckets" +} + +func init() { + migrations = append(migrations, &xormigrate.Migration{ + ID: "20240406125227", + Description: "Add correct project_view_id to task_buckets", + Migrate: func(tx *xorm.Engine) error { + + buckets := make(map[int64]*bucket20240406125227) + + err := tx.Find(&buckets) + if err != nil { + return err + } + + tbs := []*taskBucket20240406125227{} + err = tx.Where("project_view_id = 0").Find(&tbs) + if err != nil { + return err + } + + if len(tbs) == 0 { + return nil + } + + for _, tb := range tbs { + tb.ProjectViewID = buckets[tb.BucketID].ProjectViewID + _, err = tx. + Where("task_id = ? AND bucket_id = ?", tb.TaskID, tb.BucketID). + Cols("project_view_id"). + Update(tb) + if err != nil { + return err + } + } + + return nil + }, + Rollback: func(tx *xorm.Engine) error { + return nil + }, + }) +}