From 3bfc290bd594824d59f99d9931036b1909b965d5 Mon Sep 17 00:00:00 2001 From: blackandred Date: Fri, 18 Feb 2022 22:50:29 +0100 Subject: [PATCH] feat: #164 add docs --- server-go/storage/repository.go | 6 ++++++ server-go/storage/rotation.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/server-go/storage/repository.go b/server-go/storage/repository.go index b6859f39..db9a46d9 100644 --- a/server-go/storage/repository.go +++ b/server-go/storage/repository.go @@ -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 @@ -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 @@ -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{}) } diff --git a/server-go/storage/rotation.go b/server-go/storage/rotation.go index a873f501..e26b1d19 100644 --- a/server-go/storage/rotation.go +++ b/server-go/storage/rotation.go @@ -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 @@ -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 @@ -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"