mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-28 06:25:50 +00:00
646ea0f253
Deploy keys only work over SSH. A deploy token is their counterpart for HTTPS: a repository scoped credential, used as the password of a Git request, with read or read and write access. It covers Git operations and LFS, and can be regenerated in place. Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: Claude Mythos <noreply@anthropic.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: bircni <bircni@icloud.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
39 lines
1.0 KiB
Go
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
|
|
}
|