Files
Gitea/modelmigration/v1_28/v346.go
T
TheFox0x7 e23fe79e5e feat(licenses): support REUSE specification in licenses (#38720)
extends the current license detection to support two modes:
- legacy which is using classification and was expanded to handle more
paths (extensions, different spelling or GNU copying file)
- REUSE which avoids classification by relying on the spec dictating
that license must be named as SPDX-ID.extension. Newly created
repositories will default to REUSE based paths

Use of styles at the same time is not allowed by design.

Extends the UI to show all the detected licenses and paths to them,
deduplicating them per SPDX-ID in database as is in github

closes: https://github.com/go-gitea/gitea/issues/28672


---------

Assisted-By: omp:glm5.2
Assisted-By: omp:mimo-v2.5-pro
Assisted-By: omp:mimimax-m3
Assisted-By: omp:kimi-k3
Assisted-By: omp:deepseek-v4-flash
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-08-03 07:34:53 +00:00

53 lines
1.5 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v1_28
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
)
func AddLicensePathToRepoLicense(ctx context.Context, x base.EngineMigration) error {
// Drop the old 2-column UNIQUE(s) index on (repo_id, license) and, on
// re-runs, the index created under the new name.
// xorm Sync cannot reliably update an index when its column set changes.
indexes, err := x.Dialect().GetIndexes(x.DB(), ctx, "repo_license")
if err != nil {
return err
}
for _, idx := range indexes {
if idx.Name == "s" || idx.Name == "path" {
if _, err := x.Exec(x.Dialect().DropIndexSQL("repo_license", idx)); err != nil {
return err
}
}
}
// Add license_path column. The DEFAULT backfills existing rows: all repos
// created before this migration used the single LICENSE file convention.
type RepoLicense struct {
LicensePath string `xorm:"VARCHAR(255) NOT NULL DEFAULT 'LICENSE'"`
}
if _, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreDropIndices: true,
IgnoreConstrains: true,
}, new(RepoLicense)); err != nil {
return err
}
// Create new 3-column UNIQUE(path) index on (repo_id, license, license_path);
// xorm prefixes the name to UQE_repo_license_path.
newIndex := schemas.NewIndex("path", schemas.UniqueType)
newIndex.AddColumn("repo_id", "license", "license_path")
if _, err := x.Exec(x.Dialect().CreateIndexSQL("repo_license", newIndex)); err != nil {
return err
}
return nil
}