fix repository uniqueness per namespace
This commit is contained in:
+11
-1
@@ -24,7 +24,7 @@ type Namespace struct {
|
|||||||
type Repo struct {
|
type Repo struct {
|
||||||
BaseModel `xorm:"extends"`
|
BaseModel `xorm:"extends"`
|
||||||
NamespaceID int64 `xorm:"notnull unique(cred)" json:"namespace_id"`
|
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"`
|
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)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user