From 358661e060a07bf915d11d48fcdad8eb45496046 Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 9 Jul 2021 19:46:47 +0200 Subject: [PATCH] Change task title to TEXT instead of varchar(250) to allow for longer task titles --- pkg/migration/20210709191101.go | 53 +++++++++++++++++++++++++++++++++ pkg/models/tasks.go | 2 +- pkg/swagger/docs.go | 2 -- pkg/swagger/swagger.json | 2 -- pkg/swagger/swagger.yaml | 2 -- 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 pkg/migration/20210709191101.go diff --git a/pkg/migration/20210709191101.go b/pkg/migration/20210709191101.go new file mode 100644 index 00000000000..bc6e40d3cb0 --- /dev/null +++ b/pkg/migration/20210709191101.go @@ -0,0 +1,53 @@ +// Vikunja is a to-do list application to facilitate your life. +// Copyright 2018-2021 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 ( + "code.vikunja.io/api/pkg/config" + "code.vikunja.io/api/pkg/log" + "src.techknowlogick.com/xormigrate" + "xorm.io/xorm" +) + +func init() { + migrations = append(migrations, &xormigrate.Migration{ + ID: "20210709191101", + Description: "Make the task title type TEXT instead of varchar(250)", + Migrate: func(tx *xorm.Engine) error { + switch config.DatabaseType.GetString() { + case "sqlite": + // Sqlite only has a "TEXT" type so we don't need to modify it + case "mysql": + _, err := tx.Exec("alter table tasks modify title text not null") + if err != nil { + return err + } + case "postgres": + _, err := tx.Exec("alter table tasks alter column title type text using title::text") + if err != nil { + return err + } + default: + log.Fatal("Unknown db.") + } + return nil + }, + Rollback: func(tx *xorm.Engine) error { + return nil + }, + }) +} diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 219e5b3d27f..b016b982d92 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -49,7 +49,7 @@ type Task struct { // The unique, numeric id of this task. ID int64 `xorm:"bigint autoincr not null unique pk" json:"id" param:"listtask"` // The task text. This is what you'll see in the list. - Title string `xorm:"varchar(250) not null" json:"title" valid:"runelength(1|250)" minLength:"1" maxLength:"250"` + Title string `xorm:"TEXT not null" json:"title" valid:"minstringlength(1)" minLength:"1"` // The task description. Description string `xorm:"longtext null" json:"description"` // Whether a task is done or not. diff --git a/pkg/swagger/docs.go b/pkg/swagger/docs.go index b84260c24e3..027fe625985 100644 --- a/pkg/swagger/docs.go +++ b/pkg/swagger/docs.go @@ -7385,7 +7385,6 @@ var doc = `{ "title": { "description": "The task text. This is what you'll see in the list.", "type": "string", - "maxLength": 250, "minLength": 1 }, "updated": { @@ -7955,7 +7954,6 @@ var doc = `{ "title": { "description": "The task text. This is what you'll see in the list.", "type": "string", - "maxLength": 250, "minLength": 1 }, "updated": { diff --git a/pkg/swagger/swagger.json b/pkg/swagger/swagger.json index f3f52a2ed31..11712ea6485 100644 --- a/pkg/swagger/swagger.json +++ b/pkg/swagger/swagger.json @@ -7368,7 +7368,6 @@ "title": { "description": "The task text. This is what you'll see in the list.", "type": "string", - "maxLength": 250, "minLength": 1 }, "updated": { @@ -7938,7 +7937,6 @@ "title": { "description": "The task text. This is what you'll see in the list.", "type": "string", - "maxLength": 250, "minLength": 1 }, "updated": { diff --git a/pkg/swagger/swagger.yaml b/pkg/swagger/swagger.yaml index 2c17c828bb7..f2652ba181b 100644 --- a/pkg/swagger/swagger.yaml +++ b/pkg/swagger/swagger.yaml @@ -244,7 +244,6 @@ definitions: type: array title: description: The task text. This is what you'll see in the list. - maxLength: 250 minLength: 1 type: string updated: @@ -722,7 +721,6 @@ definitions: Will only returned when retreiving one task. title: description: The task text. This is what you'll see in the list. - maxLength: 250 minLength: 1 type: string updated: