mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-06 10:25:22 +02:00
fix: migrate repository.topics column for SQLite (#8019)
XORM is unable to migrate a column type for SQLite, it has to be done manually. Refs: forgejo/forgejo#7920 Note: testing is done by setting the `run-end-to-end-tests` label. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8019 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
240d958c0f
commit
48671975f1
1 changed files with 32 additions and 3 deletions
|
@ -10,16 +10,45 @@ import (
|
||||||
|
|
||||||
func SetTopicsAsEmptySlice(x *xorm.Engine) error {
|
func SetTopicsAsEmptySlice(x *xorm.Engine) error {
|
||||||
var err error
|
var err error
|
||||||
if x.Dialect().URI().DBType == schemas.POSTGRES {
|
switch x.Dialect().URI().DBType {
|
||||||
|
case schemas.MYSQL:
|
||||||
|
_, err = x.Exec("UPDATE `repository` SET topics = '[]' WHERE topics IS NULL OR topics = 'null'")
|
||||||
|
case schemas.SQLITE:
|
||||||
|
_, err = x.Exec("UPDATE `repository` SET topics = '[]' WHERE topics IS NULL OR topics = 'null'")
|
||||||
|
case schemas.POSTGRES:
|
||||||
_, err = x.Exec("UPDATE `repository` SET topics = '[]' WHERE topics IS NULL OR topics::text = 'null'")
|
_, err = x.Exec("UPDATE `repository` SET topics = '[]' WHERE topics IS NULL OR topics::text = 'null'")
|
||||||
} else {
|
|
||||||
_, err = x.Exec("UPDATE `repository` SET topics = '[]' WHERE topics IS NULL")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if x.Dialect().URI().DBType == schemas.SQLITE {
|
||||||
|
sessMigration := x.NewSession()
|
||||||
|
defer sessMigration.Close()
|
||||||
|
if err := sessMigration.Begin(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = sessMigration.Exec("ALTER TABLE `repository` RENAME COLUMN `topics` TO `topics_backup`")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = sessMigration.Exec("ALTER TABLE `repository` ADD COLUMN `topics` TEXT NOT NULL DEFAULT '[]'")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = sessMigration.Exec("UPDATE `repository` SET `topics` = `topics_backup`")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = sessMigration.Exec("ALTER TABLE `repository` DROP COLUMN `topics_backup`")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sessMigration.Commit()
|
||||||
|
}
|
||||||
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
Topics []string `xorm:"TEXT JSON NOT NULL"`
|
Topics []string `xorm:"TEXT JSON NOT NULL"`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue