vibe coded the shit out of a db migration system

This commit is contained in:
2026-01-24 16:21:28 +11:00
parent bd3816de82
commit 818f107143
15 changed files with 1649 additions and 40 deletions

View File

@@ -12,16 +12,22 @@ type Config struct {
Port uint16 // ENV DB_PORT: Database port (default: 5432)
DB string // ENV DB_NAME: Database name to connect to (required)
SSL string // ENV DB_SSL: SSL mode for connection (default: disable)
// Backup configuration
BackupDir string // ENV DB_BACKUP_DIR: Directory for database backups (default: backups)
BackupRetention int // ENV DB_BACKUP_RETENTION: Number of backups to keep (default: 10)
}
func ConfigFromEnv() (any, error) {
cfg := &Config{
User: env.String("DB_USER", ""),
Password: env.String("DB_PASSWORD", ""),
Host: env.String("DB_HOST", ""),
Port: env.UInt16("DB_PORT", 5432),
DB: env.String("DB_NAME", ""),
SSL: env.String("DB_SSL", "disable"),
User: env.String("DB_USER", ""),
Password: env.String("DB_PASSWORD", ""),
Host: env.String("DB_HOST", ""),
Port: env.UInt16("DB_PORT", 5432),
DB: env.String("DB_NAME", ""),
SSL: env.String("DB_SSL", "disable"),
BackupDir: env.String("DB_BACKUP_DIR", "backups"),
BackupRetention: env.Int("DB_BACKUP_RETENTION", 10),
}
// Validate SSL mode
@@ -50,6 +56,9 @@ func ConfigFromEnv() (any, error) {
if cfg.DB == "" {
return nil, errors.New("Envar not set: DB_NAME")
}
if cfg.BackupRetention < 1 {
return nil, errors.New("DB_BACKUP_RETENTION must be at least 1")
}
return cfg, nil
}