From ef0e7c9769288134c8847a1b1a00a45898e0c8a9 Mon Sep 17 00:00:00 2001 From: konrad Date: Thu, 18 Jul 2019 19:56:34 +0000 Subject: [PATCH] Use longtext instead of varchar(1000) on description fields (#88) --- Featurecreep.md | 2 +- pkg/migration/20190718200716.go | 48 +++++++++++++++++++++++++++++++++ pkg/migration/migration.go | 16 +++++++++++ pkg/models/label.go | 2 +- pkg/models/list.go | 2 +- pkg/models/list_tasks.go | 2 +- pkg/models/namespace.go | 2 +- pkg/models/teams.go | 2 +- 8 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 pkg/migration/20190718200716.go diff --git a/Featurecreep.md b/Featurecreep.md index e4d6480610..3531d1485b 100644 --- a/Featurecreep.md +++ b/Featurecreep.md @@ -215,7 +215,7 @@ Sorry for some of them being in German, I'll tranlate them at some point. * [x] Check if something changed at all before running everything * [x] Editable via task edit, like assignees * [x] "One endpoint to rule them all" -> Array-addable -* [ ] Description should be longtext +* [x] Description should be longtext * [ ] Attachments * [ ] Related tasks -> settable with a "kind" of relation like blocked, or just related or so * [ ] Percent done - For now just a float, may later depend on how many sub tasks are done or so diff --git a/pkg/migration/20190718200716.go b/pkg/migration/20190718200716.go new file mode 100644 index 0000000000..3b557ade07 --- /dev/null +++ b/pkg/migration/20190718200716.go @@ -0,0 +1,48 @@ +// Vikunja is a todo-list application to facilitate your life. +// Copyright 2019 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 General Public License 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package migration + +import ( + "github.com/go-xorm/xorm" + "src.techknowlogick.com/xormigrate" +) + +func init() { + tables := []string{"namespaces", "labels", "teams", "tasks", "list"} + migrations = append(migrations, &xormigrate.Migration{ + ID: "20190718200716", + Description: "Update description definition to be longtext", + Migrate: func(tx *xorm.Engine) error { + for _, table := range tables { + err := modifyColumn(tx, table, "description", "longtext null") + if err != nil { + return err + } + } + return nil + }, + Rollback: func(tx *xorm.Engine) error { + for _, table := range tables { + err := modifyColumn(tx, table, "description", "varchar(1000) null") + if err != nil { + return err + } + } + return nil + }, + }) +} diff --git a/pkg/migration/migration.go b/pkg/migration/migration.go index 48fe4047ef..70ba8625be 100644 --- a/pkg/migration/migration.go +++ b/pkg/migration/migration.go @@ -117,6 +117,22 @@ func dropTableColum(x *xorm.Engine, tableName, col string) error { return nil } +// Modifies a column definition +func modifyColumn(x *xorm.Engine, tableName, col, newDefinition string) error { + switch config.DatabaseType.GetString() { + case "sqlite": + log.Log.Warning("Unable to modify columns in SQLite") + case "mysql": + _, err := x.Exec("ALTER TABLE " + tableName + " MODIFY COLUMN " + col + " " + newDefinition) + if err != nil { + return err + } + default: + log.Log.Fatal("Unknown db.") + } + return nil +} + func initSchema(tx *xorm.Engine) error { return tx.Sync2( models.GetTables()..., diff --git a/pkg/models/label.go b/pkg/models/label.go index 388a039c06..b73796293d 100644 --- a/pkg/models/label.go +++ b/pkg/models/label.go @@ -28,7 +28,7 @@ type Label struct { // The title of the lable. You'll see this one on tasks associated with it. Title string `xorm:"varchar(250) not null" json:"title" valid:"runelength(3|250)" minLength:"3" maxLength:"250"` // The label description. - Description string `xorm:"varchar(250) null" json:"description" valid:"runelength(0|250)" maxLength:"250"` + Description string `xorm:"longtext null" json:"description" valid:"runelength(0|250)" maxLength:"250"` // The color this label has HexColor string `xorm:"varchar(6) null" json:"hex_color" valid:"runelength(0|6)" maxLength:"6"` diff --git a/pkg/models/list.go b/pkg/models/list.go index b5e02a537d..97ed3132f3 100644 --- a/pkg/models/list.go +++ b/pkg/models/list.go @@ -28,7 +28,7 @@ type List struct { // The title of the list. You'll see this in the namespace overview. Title string `xorm:"varchar(250) not null" json:"title" valid:"required,runelength(3|250)" minLength:"3" maxLength:"250"` // The description of the list. - Description string `xorm:"varchar(1000) null" json:"description" valid:"runelength(0|1000)" maxLength:"1000"` + Description string `xorm:"longtext null" json:"description" valid:"runelength(0|1000)" maxLength:"1000"` OwnerID int64 `xorm:"int(11) INDEX not null" json:"-"` NamespaceID int64 `xorm:"int(11) INDEX not null" json:"-" param:"namespace"` diff --git a/pkg/models/list_tasks.go b/pkg/models/list_tasks.go index 423ad25268..4706cf0411 100644 --- a/pkg/models/list_tasks.go +++ b/pkg/models/list_tasks.go @@ -32,7 +32,7 @@ type ListTask struct { // The task text. This is what you'll see in the list. Text string `xorm:"varchar(250) not null" json:"text" valid:"runelength(3|250)" minLength:"3" maxLength:"250"` // The task description. - Description string `xorm:"varchar(250)" json:"description" valid:"runelength(0|250)" maxLength:"250"` + Description string `xorm:"longtext null" json:"description" valid:"runelength(0|250)" maxLength:"250"` // Whether a task is done or not. Done bool `xorm:"INDEX null" json:"done"` // The unix timestamp when a task was marked as done. diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index 3c2bb5ea70..aff317e91e 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -30,7 +30,7 @@ type Namespace struct { // The name of this namespace. Name string `xorm:"varchar(250) not null" json:"name" valid:"required,runelength(5|250)" minLength:"5" maxLength:"250"` // The description of the namespace - Description string `xorm:"varchar(1000) null" json:"description" valid:"runelength(0|250)" maxLength:"250"` + Description string `xorm:"longtext null" json:"description" valid:"runelength(0|250)" maxLength:"250"` OwnerID int64 `xorm:"int(11) not null INDEX" json:"-"` // The user who owns this namespace diff --git a/pkg/models/teams.go b/pkg/models/teams.go index f0ad3817bc..937a24a4dd 100644 --- a/pkg/models/teams.go +++ b/pkg/models/teams.go @@ -28,7 +28,7 @@ type Team struct { // The name of this team. Name string `xorm:"varchar(250) not null" json:"name" valid:"required,runelength(5|250)" minLength:"5" maxLength:"250"` // The team's description. - Description string `xorm:"varchar(250)" json:"description" valid:"runelength(0|250)" minLength:"0" maxLength:"250"` + Description string `xorm:"longtext null" json:"description" valid:"runelength(0|250)" minLength:"0" maxLength:"250"` CreatedByID int64 `xorm:"int(11) not null INDEX" json:"-"` // The user who created this team.