diff options
author | Earl Warren <contact@earl-warren.org> | 2024-12-23 10:15:41 +0100 |
---|---|---|
committer | Earl Warren <contact@earl-warren.org> | 2024-12-24 10:05:59 +0100 |
commit | 9524d6d43064b3f9ee35d66b4156183d6daf2f7d (patch) | |
tree | cba1862e3548ab81654d77d0ad0cfd55b441c8f4 /models | |
parent | fix: xorm:version default is inconsistent (diff) | |
download | forgejo-9524d6d43064b3f9ee35d66b4156183d6daf2f7d.tar.xz forgejo-9524d6d43064b3f9ee35d66b4156183d6daf2f7d.zip |
fix: keying SQLite migration
Also run the keying migration when upgrading from Gitea.
Add type change support for SQLite field from TEXT to BLOB.
Diffstat (limited to 'models')
-rw-r--r-- | models/forgejo_migrations/v25.go | 25 | ||||
-rw-r--r-- | models/migrations/migrations.go | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/models/forgejo_migrations/v25.go b/models/forgejo_migrations/v25.go index 2e9641929c..e2316007cf 100644 --- a/models/forgejo_migrations/v25.go +++ b/models/forgejo_migrations/v25.go @@ -20,9 +20,34 @@ import ( func MigrateTwoFactorToKeying(x *xorm.Engine) 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 { case schemas.MYSQL: _, 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: _, err = x.Exec("ALTER TABLE `two_factor` ALTER COLUMN `secret` SET DATA TYPE bytea USING secret::text::bytea") } diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 1c55bcd63d..1674af08cd 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -365,6 +365,7 @@ func prepareMigrationTasks() []*migration { // Migration to Forgejo v10 newMigration(303, "Gitea last drop", v1_23.GiteaLastDrop), + newMigration(304, "Migrate `secret` column to store keying material", forgejo_migrations.MigrateTwoFactorToKeying), } return preparedMigrations } |