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

@ -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 {