storj/private/dbutil/dbschema/snapshot.go

42 lines
913 B
Go
Raw Normal View History

2019-02-14 13:33:42 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package dbschema
2019-02-14 21:55:21 +00:00
import "sort"
2019-02-14 13:33:42 +00:00
// Snapshots defines a collection of snapshot
type Snapshots struct {
List []*Snapshot
}
// Snapshot defines a particular snapshot of schema and data.
type Snapshot struct {
Version int
Script string
*Schema
*Data
}
// Add adds a new snapshot.
func (snapshots *Snapshots) Add(snap *Snapshot) {
snapshots.List = append(snapshots.List, snap)
}
// FindVersion finds a snapshot with the specified version.
func (snapshots *Snapshots) FindVersion(version int) (*Snapshot, bool) {
for _, snap := range snapshots.List {
if snap.Version == version {
return snap, true
}
}
return nil, false
}
2019-02-14 21:55:21 +00:00
// Sort sorts the snapshots by version
func (snapshots *Snapshots) Sort() {
sort.Slice(snapshots.List, func(i, k int) bool {
return snapshots.List[i].Version < snapshots.List[k].Version
})
}