Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions manager/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package database

import (
"encoding/json"
"errors"
"fmt"

Expand Down Expand Up @@ -200,5 +201,33 @@ func seed(db *gorm.DB) error {
}
}

// Create default GC config.
var config models.Config
if err := db.Model(models.Config{}).First(&config, models.Config{Name: models.ConfigGC}).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}

gcConfig := &models.GCConfig{
Audit: &models.GCAuditConfig{
TTL: models.DefaultGCAuditTTL,
},
Job: &models.GCJobConfig{
TTL: models.DefaultGCJobTTL,
},
}
gcConfigVal, err := json.Marshal(gcConfig)
if err != nil {
return err
}

if err := db.Model(models.Config{}).Create(&models.Config{
Name: models.ConfigGC,
Value: string(gcConfigVal),
}).Error; err != nil {
return err
}
}

return nil
}
28 changes: 28 additions & 0 deletions manager/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@

package models

import "time"

const (
// ConfigGC is the name of the GC config.
ConfigGC = "gc"
)

const (
// DefaultGCJobTTL is the default GC job TTL, by default it is 6 hours.
DefaultGCJobTTL = time.Hour * 6

// DefaultGCAuditTTL is the default audit TTL, by default it is 7 days.
DefaultGCAuditTTL = time.Hour * 24 * 7
)

type Config struct {
BaseModel
Name string `gorm:"column:name;type:varchar(256);index:uk_config_name,unique;not null;comment:config name" json:"name"`
Expand All @@ -24,3 +39,16 @@ type Config struct {
UserID uint `gorm:"comment:user id" json:"user_id"`
User User `json:"user"`
}

type GCConfig struct {
Audit *GCAuditConfig `json:"audit,omitempty"`
Job *GCJobConfig `json:"job,omitempty"`
}

type GCAuditConfig struct {
TTL time.Duration `json:"ttl"`
}

type GCJobConfig struct {
TTL time.Duration `json:"ttl"`
}