diff --git a/pkg/migration/20200322214440.go b/pkg/migration/20200322214440.go new file mode 100644 index 000000000..77f369a79 --- /dev/null +++ b/pkg/migration/20200322214440.go @@ -0,0 +1,45 @@ +// Copyright 2020 Vikunja and contriubtors. All rights reserved. +// +// This file is part of Vikunja. +// +// Vikunja 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. +// +// Vikunja 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 Vikunja. If not, see . + +package migration + +import ( + "src.techknowlogick.com/xormigrate" + "xorm.io/xorm" +) + +type namespace20200322214440 struct { + HexColor string `xorm:"varchar(6) null"` +} + +func (s namespace20200322214440) TableName() string { + return "namespaces" +} + +func init() { + migrations = append(migrations, &xormigrate.Migration{ + ID: "20200322214440", + Description: "Add hex color property to namepaces", + Migrate: func(tx *xorm.Engine) error { + return tx.Sync2(namespace20200322214440{}) + }, + Rollback: func(tx *xorm.Engine) error { + return tx.DropTables(namespace20200322214440{}) + }, + }) + +} diff --git a/pkg/migration/20200322214624.go b/pkg/migration/20200322214624.go new file mode 100644 index 000000000..d369c6f0e --- /dev/null +++ b/pkg/migration/20200322214624.go @@ -0,0 +1,45 @@ +// Copyright 2020 Vikunja and contriubtors. All rights reserved. +// +// This file is part of Vikunja. +// +// Vikunja 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. +// +// Vikunja 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 Vikunja. If not, see . + +package migration + +import ( + "src.techknowlogick.com/xormigrate" + "xorm.io/xorm" +) + +type list20200322214624 struct { + HexColor string `xorm:"varchar(6) null"` +} + +func (s list20200322214624) TableName() string { + return "list" +} + +func init() { + migrations = append(migrations, &xormigrate.Migration{ + ID: "20200322214624", + Description: "Add hex color property to list", + Migrate: func(tx *xorm.Engine) error { + return tx.Sync2(list20200322214624{}) + }, + Rollback: func(tx *xorm.Engine) error { + return tx.DropTables(list20200322214624{}) + }, + }) + +} diff --git a/pkg/models/list.go b/pkg/models/list.go index 1cbb0eb1b..365949444 100644 --- a/pkg/models/list.go +++ b/pkg/models/list.go @@ -34,6 +34,8 @@ type List struct { Description string `xorm:"longtext null" json:"description"` // The unique list short identifier. Used to build task identifiers. Identifier string `xorm:"varchar(10) null" json:"identifier" valid:"runelength(0|10)" minLength:"0" maxLength:"10"` + // The hex color of this list + HexColor string `xorm:"varchar(6) null" json:"hex_color" valid:"runelength(0|6)" maxLength:"6"` OwnerID int64 `xorm:"int(11) INDEX not null" json:"-"` NamespaceID int64 `xorm:"int(11) INDEX not null" json:"-" param:"namespace"` @@ -382,6 +384,9 @@ func CreateOrUpdateList(list *List) (err error) { if list.Identifier != "" { colsToUpdate = append(colsToUpdate, "identifier") } + if list.HexColor != "" { + colsToUpdate = append(colsToUpdate, "hex_color") + } _, err = x. ID(list.ID). diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index 3e5714bc6..552f80059 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -36,6 +36,9 @@ type Namespace struct { Description string `xorm:"longtext null" json:"description"` OwnerID int64 `xorm:"int(11) not null INDEX" json:"-"` + // The hex color of this namespace + HexColor string `xorm:"varchar(6) null" json:"hex_color" valid:"runelength(0|6)" maxLength:"6"` + // Whether or not a namespace is archived. IsArchived bool `xorm:"not null default false" json:"is_archived" query:"is_archived"` @@ -461,6 +464,9 @@ func (n *Namespace) Update() (err error) { if n.Description != "" { colsToUpdate = append(colsToUpdate, "description") } + if n.HexColor != "" { + colsToUpdate = append(colsToUpdate, "hex_color") + } // Do the actual update _, err = x.