Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
feat: #164 add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Feb 18, 2022
1 parent 9d3fac3 commit 3bfc290
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server-go/storage/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"gorm.io/gorm"
)

// VersionsRepository persistence layer for Versions
type VersionsRepository struct {
db *gorm.DB
}

// findLastHighestVersionNumber Finds latest backup's version number
func (vr VersionsRepository) findLastHighestVersionNumber(collectionId string) (int, error) {
maxNum := 0
err := vr.db.Model(&UploadedVersion{}).Select("uploaded_versions.version_number").Where("uploaded_versions.collection_id = ?", collectionId).Order("uploaded_versions.version_number DESC").Limit(1).Find(&maxNum).Error
Expand All @@ -17,6 +19,7 @@ func (vr VersionsRepository) findLastHighestVersionNumber(collectionId string) (
return maxNum, nil
}

// findAllVersionsForCollectionId Finds multiple versions for given collection by it's id
func (vr VersionsRepository) findAllVersionsForCollectionId(collectionId string) ([]UploadedVersion, error) {
var foundVersions []UploadedVersion

Expand All @@ -27,15 +30,18 @@ func (vr VersionsRepository) findAllVersionsForCollectionId(collectionId string)
return foundVersions, nil
}

// delete Deletes entry from database
func (vr VersionsRepository) delete(version *UploadedVersion) (error, bool) {
var result bool
return vr.db.Model(&UploadedVersion{}).Where("uploaded_versions.id = ?", version.Id).Delete(&result).Error, result
}

// create Creates an entry in database
func (vr VersionsRepository) create(version *UploadedVersion) error {
return vr.db.Create(version).Error
}

// InitializeModel connects model to migrations
func InitializeModel(db *gorm.DB) error {
return db.AutoMigrate(&UploadedVersion{})
}
6 changes: 6 additions & 0 deletions server-go/storage/rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
)

// RotationStrategy defines how old backups should be rotated
type RotationStrategy interface {
// CanUpload returns nil if YES, error if NO
CanUpload(version UploadedVersion) error
Expand All @@ -21,10 +22,12 @@ type FifoRotationStrategy struct {
existingVersions []UploadedVersion
}

// CanUpload RotationStrategy can decide if we can still upload
func (frs *FifoRotationStrategy) CanUpload(version UploadedVersion) error {
return nil
}

// GetVersionsThatShouldBeDeletedIfThisVersionUploaded interface implementation that allows RotationStrategy to decide which versions should be deleted right now, when uploading a new version
func (frs *FifoRotationStrategy) GetVersionsThatShouldBeDeletedIfThisVersionUploaded(version UploadedVersion) []UploadedVersion {
existingVersions := frs.existingVersions

Expand All @@ -42,9 +45,12 @@ func (frs *FifoRotationStrategy) GetVersionsThatShouldBeDeletedIfThisVersionUplo
return existingVersions[0:1]
}

// NewFifoRotationStrategy is a factorial method
func NewFifoRotationStrategy(collection *collections.Collection, existingVersions []UploadedVersion) *FifoRotationStrategy {
return &FifoRotationStrategy{
collection: collection,
existingVersions: existingVersions,
}
}

// todo: implement "fifo-plus-older"

0 comments on commit 3bfc290

Please sign in to comment.