Add MariaDB as separate selectable database type in interactive mode
This commit is contained in:
@ -196,9 +196,9 @@ func (c *Config) IsPostgreSQL() bool {
|
|||||||
return c.DatabaseType == "postgres"
|
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 {
|
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
|
// GetDefaultPort returns the default port for the database type
|
||||||
@ -215,7 +215,9 @@ func (c *Config) DisplayDatabaseType() string {
|
|||||||
case "postgres":
|
case "postgres":
|
||||||
return "PostgreSQL"
|
return "PostgreSQL"
|
||||||
case "mysql":
|
case "mysql":
|
||||||
return "MySQL/MariaDB"
|
return "MySQL"
|
||||||
|
case "mariadb":
|
||||||
|
return "MariaDB"
|
||||||
default:
|
default:
|
||||||
return c.DatabaseType
|
return c.DatabaseType
|
||||||
}
|
}
|
||||||
@ -225,7 +227,7 @@ func (c *Config) DisplayDatabaseType() string {
|
|||||||
func (c *Config) SetDatabaseType(dbType string) error {
|
func (c *Config) SetDatabaseType(dbType string) error {
|
||||||
normalized, ok := canonicalDatabaseType(dbType)
|
normalized, ok := canonicalDatabaseType(dbType)
|
||||||
if !ok {
|
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
|
previous := c.DatabaseType
|
||||||
@ -329,8 +331,10 @@ func canonicalDatabaseType(input string) (string, bool) {
|
|||||||
switch strings.ToLower(strings.TrimSpace(input)) {
|
switch strings.ToLower(strings.TrimSpace(input)) {
|
||||||
case "postgres", "postgresql", "pg":
|
case "postgres", "postgresql", "pg":
|
||||||
return "postgres", true
|
return "postgres", true
|
||||||
case "mysql", "mariadb", "mariadb-server", "maria":
|
case "mysql":
|
||||||
return "mysql", true
|
return "mysql", true
|
||||||
|
case "mariadb", "mariadb-server", "maria":
|
||||||
|
return "mariadb", true
|
||||||
default:
|
default:
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
@ -340,7 +344,7 @@ func defaultPortFor(dbType string) int {
|
|||||||
switch dbType {
|
switch dbType {
|
||||||
case "postgres":
|
case "postgres":
|
||||||
return postgresDefaultPort
|
return postgresDefaultPort
|
||||||
case "mysql":
|
case "mysql", "mariadb":
|
||||||
return mysqlDefaultPort
|
return mysqlDefaultPort
|
||||||
default:
|
default:
|
||||||
return postgresDefaultPort
|
return postgresDefaultPort
|
||||||
|
|||||||
@ -69,12 +69,15 @@ func NewMenuModel(cfg *config.Config, log logger.Logger) MenuModel {
|
|||||||
|
|
||||||
dbTypes := []dbTypeOption{
|
dbTypes := []dbTypeOption{
|
||||||
{label: "PostgreSQL", value: "postgres"},
|
{label: "PostgreSQL", value: "postgres"},
|
||||||
{label: "MySQL / MariaDB", value: "mysql"},
|
{label: "MySQL", value: "mysql"},
|
||||||
|
{label: "MariaDB", value: "mariadb"},
|
||||||
}
|
}
|
||||||
|
|
||||||
dbCursor := 0
|
dbCursor := 0
|
||||||
if cfg.IsMySQL() {
|
if cfg.DatabaseType == "mysql" {
|
||||||
dbCursor = 1
|
dbCursor = 1
|
||||||
|
} else if cfg.DatabaseType == "mariadb" {
|
||||||
|
dbCursor = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
model := MenuModel{
|
model := MenuModel{
|
||||||
|
|||||||
@ -57,8 +57,8 @@ func NewSettingsModel(cfg *config.Config, log logger.Logger, parent tea.Model) S
|
|||||||
Update: func(c *config.Config, v string) error {
|
Update: func(c *config.Config, v string) error {
|
||||||
return c.SetDatabaseType(v)
|
return c.SetDatabaseType(v)
|
||||||
},
|
},
|
||||||
Type: "string",
|
Type: "selector",
|
||||||
Description: "Target database engine (postgres, mysql, mariadb)",
|
Description: "Target database engine (press Enter to cycle: PostgreSQL → MySQL → MariaDB)",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "backup_dir",
|
Key: "backup_dir",
|
||||||
@ -309,6 +309,10 @@ func (m SettingsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "enter", " ":
|
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()
|
return m.startEditing()
|
||||||
|
|
||||||
case "tab":
|
case "tab":
|
||||||
@ -454,6 +458,33 @@ func (m SettingsModel) saveSettings() (tea.Model, tea.Cmd) {
|
|||||||
return m, nil
|
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
|
// View renders the settings interface
|
||||||
func (m SettingsModel) View() string {
|
func (m SettingsModel) View() string {
|
||||||
if m.quitting {
|
if m.quitting {
|
||||||
|
|||||||
Reference in New Issue
Block a user