Get the last time a model was modified and return it in BaseModel. This will help with discovering what items can be garbage collected during incomplete backup cleanup as we don't want to accidentally delete in-flight backups. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) * #3217 #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
85 lines
2.6 KiB
Go
85 lines
2.6 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/kopia/kopia/repo/manifest"
|
|
)
|
|
|
|
type (
|
|
// StableID is used by BaseModel.ID to uniquely identify objects
|
|
// stored in the modelStore.
|
|
StableID string
|
|
Schema int
|
|
)
|
|
|
|
func (id StableID) String() string {
|
|
return string(id)
|
|
}
|
|
|
|
// Schema constants denote the type of model stored. The integer values of the
|
|
// constants can be changed without issue, but the string values should remain
|
|
// the same. If the string values are changed, additional code will be needed to
|
|
// transform from the old value to the new value.
|
|
//
|
|
//go:generate go run golang.org/x/tools/cmd/stringer -type=Schema
|
|
const (
|
|
UnknownSchema Schema = 0
|
|
BackupOpSchema Schema = 1
|
|
RestoreOpSchema Schema = 2
|
|
BackupSchema Schema = 3
|
|
BackupDetailsSchema Schema = 4
|
|
RepositorySchema Schema = 5
|
|
)
|
|
|
|
// common tags for filtering
|
|
const (
|
|
ServiceTag = "service"
|
|
BackupTypeTag = "backup-type"
|
|
AssistBackup = "assist-backup"
|
|
MergeBackup = "merge-backup"
|
|
)
|
|
|
|
// Valid returns true if the ModelType value fits within the const range.
|
|
func (mt Schema) Valid() bool {
|
|
return mt > 0 && mt < RepositorySchema+1
|
|
}
|
|
|
|
type Model interface {
|
|
// Returns a handle to the BaseModel for this model.
|
|
Base() *BaseModel
|
|
}
|
|
|
|
// BaseModel defines required fields for models stored in ModelStore. Structs
|
|
// that wish to be stored should embed this struct. This struct also represents
|
|
// the common metadata the ModelStore will fill out/use.
|
|
type BaseModel struct {
|
|
// ID is an identifier that other objects can use to refer to this
|
|
// object in the ModelStore.
|
|
// Once generated (during Put), it is guaranteed not to change. This field
|
|
// should be treated as read-only by users.
|
|
ID StableID `json:"ID,omitempty"`
|
|
// ModelStoreID is an internal ID for the model in the store. If present it
|
|
// can be used for efficient lookups, but should not be used by other models
|
|
// to refer to this one. This field may change if the model is updated. This
|
|
// field should be treated as read-only by users.
|
|
ModelStoreID manifest.ID `json:"-"`
|
|
// ModelVersion is a version number that can help track changes across models.
|
|
// TODO(ashmrtn): Reference version control documentation.
|
|
ModelVersion int `json:"-"`
|
|
// Tags associated with this model in the store to facilitate lookup. Tags in
|
|
// the struct are not serialized directly into the stored model, but are part
|
|
// of the metadata for the model.
|
|
Tags map[string]string `json:"-"`
|
|
ModTime time.Time `json:"-"`
|
|
}
|
|
|
|
func (bm *BaseModel) Base() *BaseModel {
|
|
return bm
|
|
}
|
|
|
|
// GetID returns the baseModel.ID as a string rather than a model.StableID.
|
|
func (bm *BaseModel) GetID() string {
|
|
return string(bm.ID)
|
|
}
|