From 7b8fab33a56cad4aa9e3fdf92453d97a25f1fe08 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 6 Apr 2024 13:04:36 +0200 Subject: [PATCH] fix(kanban): Make sure all saved taskBucket positions are saved with their project view id When the tasks were migrated from belonging directly to a bucket to only belonging to a view, I forgot to add the view in that migration, resulting in task buckets where the view was 0. These entries were not deleted when a task was moved between buckets, but the new task bucket relation nevertheless inserted. This resulted in tasks showing up multiple times on the kanban board. This change adds a new migration which adds the correct project view id (as derived from the bucket) and fixes the old migration as well. Resolves https://community.vikunja.io/t/no-longer-able-to-properly-move-tasks-between-kanban-columns/2175 --- pkg/migration/20240315110428.go | 5 +- pkg/migration/20240406125227.go | 83 +++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 pkg/migration/20240406125227.go 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 + }, + }) +}