Fix MySQL support and TUI auto-confirm mode
- Fix format detection to read database_type from .meta.json metadata file - Add ensureMySQLDatabaseExists() for MySQL/MariaDB database creation - Route database creation to correct implementation based on db type - Add TUI auto-forward in auto-confirm mode (no input required for debugging) - All TUI components now exit automatically when --auto-confirm is set - Fix status view to skip loading in auto-confirm mode
This commit is contained in:
@@ -2,6 +2,7 @@ package restore
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -21,6 +22,25 @@ const (
|
||||
FormatUnknown ArchiveFormat = "Unknown"
|
||||
)
|
||||
|
||||
// backupMetadata represents the structure of .meta.json files
|
||||
type backupMetadata struct {
|
||||
DatabaseType string `json:"database_type"`
|
||||
}
|
||||
|
||||
// readMetadataDBType reads the database_type from the .meta.json file if it exists
|
||||
func readMetadataDBType(archivePath string) string {
|
||||
metaPath := archivePath + ".meta.json"
|
||||
data, err := os.ReadFile(metaPath)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
var meta backupMetadata
|
||||
if err := json.Unmarshal(data, &meta); err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.ToLower(meta.DatabaseType)
|
||||
}
|
||||
|
||||
// DetectArchiveFormat detects the format of a backup archive from its filename and content
|
||||
func DetectArchiveFormat(filename string) ArchiveFormat {
|
||||
lower := strings.ToLower(filename)
|
||||
@@ -54,7 +74,14 @@ func DetectArchiveFormat(filename string) ArchiveFormat {
|
||||
|
||||
// Check for compressed SQL formats
|
||||
if strings.HasSuffix(lower, ".sql.gz") {
|
||||
// Determine if MySQL or PostgreSQL based on naming convention
|
||||
// First, try to determine from metadata file
|
||||
if dbType := readMetadataDBType(filename); dbType != "" {
|
||||
if dbType == "mysql" || dbType == "mariadb" {
|
||||
return FormatMySQLSQLGz
|
||||
}
|
||||
return FormatPostgreSQLSQLGz
|
||||
}
|
||||
// Fallback: determine if MySQL or PostgreSQL based on naming convention
|
||||
if strings.Contains(lower, "mysql") || strings.Contains(lower, "mariadb") {
|
||||
return FormatMySQLSQLGz
|
||||
}
|
||||
@@ -63,7 +90,14 @@ func DetectArchiveFormat(filename string) ArchiveFormat {
|
||||
|
||||
// Check for uncompressed SQL formats
|
||||
if strings.HasSuffix(lower, ".sql") {
|
||||
// Determine if MySQL or PostgreSQL based on naming convention
|
||||
// First, try to determine from metadata file
|
||||
if dbType := readMetadataDBType(filename); dbType != "" {
|
||||
if dbType == "mysql" || dbType == "mariadb" {
|
||||
return FormatMySQLSQLGz
|
||||
}
|
||||
return FormatPostgreSQLSQL
|
||||
}
|
||||
// Fallback: determine if MySQL or PostgreSQL based on naming convention
|
||||
if strings.Contains(lower, "mysql") || strings.Contains(lower, "mariadb") {
|
||||
return FormatMySQLSQL
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user