From e58e7bf0883c6b878f34ff2677b48efba4d3cbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Thu, 5 Oct 2023 10:45:49 +0200 Subject: [PATCH] [GITEA] rework long-term authentication (squash) add migration Reminder: the migration is run via integration tests as explained in the commit "[DB] run all Forgejo migrations in integration tests" (cherry picked from commit 4accf7443c1c59b4d2e7787d6a6c602d725da403) --- models/forgejo_migrations/migrate.go | 2 ++ models/forgejo_migrations/v1_20/v3.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 models/forgejo_migrations/v1_20/v3.go diff --git a/models/forgejo_migrations/migrate.go b/models/forgejo_migrations/migrate.go index c1bc8e793c..93b89d43ed 100644 --- a/models/forgejo_migrations/migrate.go +++ b/models/forgejo_migrations/migrate.go @@ -40,6 +40,8 @@ var migrations = []*Migration{ NewMigration("Add Forgejo Blocked Users table", forgejo_v1_20.AddForgejoBlockedUser), // v2 -> v3 NewMigration("create the forgejo_sem_ver table", forgejo_v1_20.CreateSemVerTable), + // v2 -> v3 + NewMigration("create the forgejo_auth_token table", forgejo_v1_20.CreateAuthorizationTokenTable), } // GetCurrentDBVersion returns the current Forgejo database version. diff --git a/models/forgejo_migrations/v1_20/v3.go b/models/forgejo_migrations/v1_20/v3.go new file mode 100644 index 0000000000..38c29bed03 --- /dev/null +++ b/models/forgejo_migrations/v1_20/v3.go @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT + +package forgejo_v1_20 //nolint:revive + +import ( + "code.gitea.io/gitea/modules/timeutil" + + "xorm.io/xorm" +) + +type AuthorizationToken struct { + ID int64 `xorm:"pk autoincr"` + UID int64 `xorm:"INDEX"` + LookupKey string `xorm:"INDEX UNIQUE"` + HashedValidator string + Expiry timeutil.TimeStamp +} + +func (AuthorizationToken) TableName() string { + return "forgejo_auth_token" +} + +func CreateAuthorizationTokenTable(x *xorm.Engine) error { + return x.Sync(new(AuthorizationToken)) +}