Files
upstream-mirror 52ae0c5802
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:41:59 +05:00

39 lines
1.0 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v28
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm"
)
func AddTokenToDeployKey(ctx context.Context, x base.EngineMigration) error {
// Drop the old UNIQUE(s) index on (key_id, repo_id). Every token row carries key
// id 0, so the pair can no longer be unique. AddDeployKey still checks it in code.
indexes, err := x.Dialect().GetIndexes(x.DB(), ctx, "deploy_key")
if err != nil {
return err
}
if idx, ok := indexes["s"]; ok {
if _, err := x.Exec(x.Dialect().DropIndexSQL("deploy_key", idx)); err != nil {
return err
}
}
type DeployKey struct {
KeyID int64 `xorm:"INDEX"`
RepoID int64 `xorm:"INDEX"`
KeyType int `xorm:"NOT NULL DEFAULT 1"` // every existing row is an SSH key
TokenHash string `xorm:"INDEX"`
}
_, err = x.SyncWithOptions(xorm.SyncOptions{
IgnoreConstrains: true,
IgnoreDropIndices: true, // the bean only describes the new columns
}, new(DeployKey))
return err
}