feat: versioning in awards definition
This commit is contained in:
@@ -99,6 +99,35 @@ type Def struct {
|
||||
|
||||
Total int `json:"total"` // known denominator (0 = unknown / derive from list)
|
||||
Builtin bool `json:"builtin"` // shipped default (informational)
|
||||
|
||||
// --- Catalog updates ---
|
||||
// Version is the revision of a SHIPPED award. Bump it in the catalog JSON when
|
||||
// you fix a definition (a better OR chain, a corrected reference list) and want
|
||||
// that fix to reach operators who already run the award: on startup, a catalog
|
||||
// award whose Version is higher than the stored one REPLACES it, definition and
|
||||
// references. Awards created by the operator have no version and are never touched.
|
||||
Version int `json:"version,omitempty"`
|
||||
// UserEdited marks an award the operator has changed. A catalog update then
|
||||
// SKIPS it: their work outranks ours. Set the moment the award (or its reference
|
||||
// list) is saved to something other than what the catalog ships.
|
||||
UserEdited bool `json:"user_edited,omitempty"`
|
||||
}
|
||||
|
||||
// SameContent reports whether two definitions describe the same award — ignoring
|
||||
// the bookkeeping fields (version, the user-edited flag, the derived builtin bit),
|
||||
// which say where a definition came from, not what it does. Used to decide whether
|
||||
// a save actually changed anything.
|
||||
func (d Def) SameContent(o Def) bool {
|
||||
a, b := d, o
|
||||
a.Version, b.Version = 0, 0
|
||||
a.UserEdited, b.UserEdited = false, false
|
||||
a.Builtin, b.Builtin = false, false
|
||||
ja, err1 := json.Marshal(a)
|
||||
jb, err2 := json.Marshal(b)
|
||||
if err1 != nil || err2 != nil {
|
||||
return false
|
||||
}
|
||||
return string(ja) == string(jb)
|
||||
}
|
||||
|
||||
// OrRule is one additional search OR'd with the award's primary matching rule.
|
||||
|
||||
Reference in New Issue
Block a user