Add MariaDB as separate selectable database type in interactive mode

This commit is contained in:
2025-11-07 13:03:15 +00:00
parent 3cedac371c
commit ebb77fb960
4 changed files with 48 additions and 10 deletions

View File

@ -196,9 +196,9 @@ func (c *Config) IsPostgreSQL() bool {
return c.DatabaseType == "postgres"
}
// IsMySQL returns true if database type is MySQL
// IsMySQL returns true if database type is MySQL or MariaDB
func (c *Config) IsMySQL() bool {
return c.DatabaseType == "mysql"
return c.DatabaseType == "mysql" || c.DatabaseType == "mariadb"
}
// GetDefaultPort returns the default port for the database type
@ -215,7 +215,9 @@ func (c *Config) DisplayDatabaseType() string {
case "postgres":
return "PostgreSQL"
case "mysql":
return "MySQL/MariaDB"
return "MySQL"
case "mariadb":
return "MariaDB"
default:
return c.DatabaseType
}
@ -225,7 +227,7 @@ func (c *Config) DisplayDatabaseType() string {
func (c *Config) SetDatabaseType(dbType string) error {
normalized, ok := canonicalDatabaseType(dbType)
if !ok {
return &ConfigError{Field: "database-type", Value: dbType, Message: "must be 'postgres' or 'mysql'"}
return &ConfigError{Field: "database-type", Value: dbType, Message: "must be 'postgres', 'mysql', or 'mariadb'"}
}
previous := c.DatabaseType
@ -329,8 +331,10 @@ func canonicalDatabaseType(input string) (string, bool) {
switch strings.ToLower(strings.TrimSpace(input)) {
case "postgres", "postgresql", "pg":
return "postgres", true
case "mysql", "mariadb", "mariadb-server", "maria":
case "mysql":
return "mysql", true
case "mariadb", "mariadb-server", "maria":
return "mariadb", true
default:
return "", false
}
@ -340,7 +344,7 @@ func defaultPortFor(dbType string) int {
switch dbType {
case "postgres":
return postgresDefaultPort
case "mysql":
case "mysql", "mariadb":
return mysqlDefaultPort
default:
return postgresDefaultPort

View File

@ -69,12 +69,15 @@ func NewMenuModel(cfg *config.Config, log logger.Logger) MenuModel {
dbTypes := []dbTypeOption{
{label: "PostgreSQL", value: "postgres"},
{label: "MySQL / MariaDB", value: "mysql"},
{label: "MySQL", value: "mysql"},
{label: "MariaDB", value: "mariadb"},
}
dbCursor := 0
if cfg.IsMySQL() {
if cfg.DatabaseType == "mysql" {
dbCursor = 1
} else if cfg.DatabaseType == "mariadb" {
dbCursor = 2
}
model := MenuModel{

View File

@ -57,8 +57,8 @@ func NewSettingsModel(cfg *config.Config, log logger.Logger, parent tea.Model) S
Update: func(c *config.Config, v string) error {
return c.SetDatabaseType(v)
},
Type: "string",
Description: "Target database engine (postgres, mysql, mariadb)",
Type: "selector",
Description: "Target database engine (press Enter to cycle: PostgreSQL → MySQL → MariaDB)",
},
{
Key: "backup_dir",
@ -309,6 +309,10 @@ func (m SettingsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case "enter", " ":
// For database_type, cycle through options instead of typing
if m.cursor >= 0 && m.cursor < len(m.settings) && m.settings[m.cursor].Key == "database_type" {
return m.cycleDatabaseType()
}
return m.startEditing()
case "tab":
@ -454,6 +458,33 @@ func (m SettingsModel) saveSettings() (tea.Model, tea.Cmd) {
return m, nil
}
// cycleDatabaseType cycles through database type options
func (m SettingsModel) cycleDatabaseType() (tea.Model, tea.Cmd) {
dbTypes := []string{"postgres", "mysql", "mariadb"}
// Find current index
currentIdx := 0
for i, dbType := range dbTypes {
if m.config.DatabaseType == dbType {
currentIdx = i
break
}
}
// Cycle to next
nextIdx := (currentIdx + 1) % len(dbTypes)
newType := dbTypes[nextIdx]
// Update config
if err := m.config.SetDatabaseType(newType); err != nil {
m.message = errorStyle.Render(fmt.Sprintf("❌ Failed to set database type: %s", err.Error()))
return m, nil
}
m.message = successStyle.Render(fmt.Sprintf("✅ Database type set to %s", m.config.DisplayDatabaseType()))
return m, nil
}
// View renders the settings interface
func (m SettingsModel) View() string {
if m.quitting {