mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 05:33:52 +03:00
fix: keying SQLite migration
Also run the keying migration when upgrading from Gitea. Add type change support for SQLite field from TEXT to BLOB.
This commit is contained in:
parent
2dc167cbb9
commit
9524d6d430
2 changed files with 26 additions and 0 deletions
|
@ -20,9 +20,34 @@ import (
|
||||||
func MigrateTwoFactorToKeying(x *xorm.Engine) error {
|
func MigrateTwoFactorToKeying(x *xorm.Engine) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// When upgrading from Forgejo v9 to v10, this migration will already be
|
||||||
|
// called from models/migrations/migrations.go migration 304 and must not
|
||||||
|
// be run twice.
|
||||||
|
var version int
|
||||||
|
_, err = x.Table("version").Where("`id` = 1").Select("version").Get(&version)
|
||||||
|
if err != nil {
|
||||||
|
// the version table does not exist when a test environment only applies Forgejo migrations
|
||||||
|
} else if version > 304 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
switch x.Dialect().URI().DBType {
|
switch x.Dialect().URI().DBType {
|
||||||
case schemas.MYSQL:
|
case schemas.MYSQL:
|
||||||
_, err = x.Exec("ALTER TABLE `two_factor` MODIFY `secret` BLOB")
|
_, err = x.Exec("ALTER TABLE `two_factor` MODIFY `secret` BLOB")
|
||||||
|
case schemas.SQLITE:
|
||||||
|
_, err = x.Exec("ALTER TABLE `two_factor` RENAME COLUMN `secret` TO `secret_backup`")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = x.Exec("ALTER TABLE `two_factor` ADD COLUMN `secret` BLOB")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = x.Exec("UPDATE `two_factor` SET `secret` = `secret_backup`")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = x.Exec("ALTER TABLE `two_factor` DROP COLUMN `secret_backup`")
|
||||||
case schemas.POSTGRES:
|
case schemas.POSTGRES:
|
||||||
_, err = x.Exec("ALTER TABLE `two_factor` ALTER COLUMN `secret` SET DATA TYPE bytea USING secret::text::bytea")
|
_, err = x.Exec("ALTER TABLE `two_factor` ALTER COLUMN `secret` SET DATA TYPE bytea USING secret::text::bytea")
|
||||||
}
|
}
|
||||||
|
|
|
@ -365,6 +365,7 @@ func prepareMigrationTasks() []*migration {
|
||||||
|
|
||||||
// Migration to Forgejo v10
|
// Migration to Forgejo v10
|
||||||
newMigration(303, "Gitea last drop", v1_23.GiteaLastDrop),
|
newMigration(303, "Gitea last drop", v1_23.GiteaLastDrop),
|
||||||
|
newMigration(304, "Migrate `secret` column to store keying material", forgejo_migrations.MigrateTwoFactorToKeying),
|
||||||
}
|
}
|
||||||
return preparedMigrations
|
return preparedMigrations
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue