fix repository uniqueness per namespace

This commit is contained in:
Jabberwocky238
2026-07-30 01:30:12 -04:00
parent 8d299013f9
commit 8d99f3bc20
+11 -1
View File
@@ -24,7 +24,7 @@ type Namespace struct {
type Repo struct {
BaseModel `xorm:"extends"`
NamespaceID int64 `xorm:"notnull unique(cred)" json:"namespace_id"`
Name string `xorm:"varchar(255) notnull" json:"reponame"`
Name string `xorm:"varchar(255) notnull unique(cred)" json:"reponame"`
IsPrivate bool `xorm:"default false" json:"is_private"`
}
@@ -111,5 +111,15 @@ func migrateLegacySQLite(engine *xorm.Engine) error {
return fmt.Errorf("migrate repo column repo_name to name: %w", err)
}
}
if len(columns) > 0 {
// Older schemas accidentally made namespace_id unique by itself, limiting
// a namespace to one repository. The model key is (namespace_id, name).
if _, err := engine.Exec("DROP INDEX IF EXISTS UQE_repo_cred"); err != nil {
return fmt.Errorf("drop legacy repo unique index: %w", err)
}
if _, err := engine.Exec("CREATE UNIQUE INDEX IF NOT EXISTS UQE_repo_cred ON repo (namespace_id, name)"); err != nil {
return fmt.Errorf("create repo unique index: %w", err)
}
}
return nil
}