feat(backend): add age condition for state versions retention
Closes #59
This commit is contained in:
parent
5d7b540718
commit
0a63e1f593
3 changed files with 32 additions and 20 deletions
|
@ -28,12 +28,13 @@ func initDB(ctx context.Context, url string) (*sql.DB, error) {
|
|||
}
|
||||
|
||||
type DB struct {
|
||||
ctx context.Context
|
||||
dataEncryptionKey scrypto.AES256Key
|
||||
readDB *sql.DB
|
||||
sessionsSalt scrypto.AES256Key
|
||||
versionsHistoryLimit int
|
||||
writeDB *sql.DB
|
||||
ctx context.Context
|
||||
dataEncryptionKey scrypto.AES256Key
|
||||
readDB *sql.DB
|
||||
sessionsSalt scrypto.AES256Key
|
||||
versionsHistoryLimit int
|
||||
versionsHistoryMinimumDays int
|
||||
writeDB *sql.DB
|
||||
}
|
||||
|
||||
func NewDB(ctx context.Context, url string, getenv func(string) string) (*DB, error) {
|
||||
|
@ -60,10 +61,11 @@ func NewDB(ctx context.Context, url string, getenv func(string) string) (*DB, er
|
|||
writeDB.SetMaxOpenConns(1)
|
||||
|
||||
db := DB{
|
||||
ctx: ctx,
|
||||
readDB: readDB,
|
||||
versionsHistoryLimit: 64,
|
||||
writeDB: writeDB,
|
||||
ctx: ctx,
|
||||
readDB: readDB,
|
||||
versionsHistoryLimit: 128,
|
||||
versionsHistoryMinimumDays: 28,
|
||||
writeDB: writeDB,
|
||||
}
|
||||
pragmas := []struct {
|
||||
key string
|
||||
|
@ -103,6 +105,12 @@ func NewDB(ctx context.Context, url string, getenv func(string) string) (*DB, er
|
|||
return nil, fmt.Errorf("failed to parse the TFSTATED_VERSIONS_HISTORY_LIMIT environment variable, expected an integer: %w", err)
|
||||
}
|
||||
}
|
||||
versionsHistoryMinimumDays := getenv("TFSTATED_VERSIONS_HISTORY_MINIMUM_DAYS")
|
||||
if versionsHistoryMinimumDays != "" {
|
||||
if db.versionsHistoryMinimumDays, err = strconv.Atoi(versionsHistoryMinimumDays); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse the TFSTATED_VERSIONS_HISTORY_MINIMUM_DAYS environment variable, expected an integer: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return &db, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue