database

package
v1.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSupportedTypesDisplay added in v1.1.6

func GetSupportedTypesDisplay() string

GetSupportedTypesDisplay returns a display string of supported database types

func ValidateAndSetDefaults added in v1.1.6

func ValidateAndSetDefaults(config *ProviderConfig) error

ValidateAndSetDefaults validates the configuration and sets appropriate defaults

func ValidateConfig added in v1.1.6

func ValidateConfig(config *ProviderConfig) error

ValidateConfig validates the provider configuration

Types

type BackupFormat added in v1.1.6

type BackupFormat string

BackupFormat represents the format of backup files

const (
	SQL    BackupFormat = "sql"    // Plain SQL format
	Custom BackupFormat = "custom" // Database-specific custom format
	Binary BackupFormat = "binary" // Binary/physical backup
)

type BackupOptions added in v1.1.6

type BackupOptions struct {
	Databases     []string
	Directory     string
	Timestamp     string
	UseParallel   bool // Use parallel tools (mydumper/pg_dump parallel)
	Format        BackupFormat
	Compression   bool
	IncludeData   bool
	IncludeSchema bool
	Timeout       time.Duration
	ExtraArgs     []string // Database-specific arguments
}

BackupOptions contains options for backup operations

type BackupResult added in v1.1.6

type BackupResult struct {
	Database    string
	BackupPath  string
	Size        int64
	Duration    time.Duration
	Success     bool
	Error       error
	Format      BackupFormat
	Compression bool
}

BackupResult contains the result of a backup operation

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *config.DatabaseConfig) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) CreateBackup

func (c *Client) CreateBackup(ctx context.Context, dbName, backupDir string) (string, error)

func (*Client) CreateDirectory

func (c *Client) CreateDirectory(path string) error

func (*Client) ListDatabases added in v1.1.4

func (c *Client) ListDatabases(ctx context.Context) ([]string, error)

ListDatabases returns a list of database names

func (*Client) RestoreBackup

func (c *Client) RestoreBackup(ctx context.Context, backupPath, dbName string) error

type DatabaseInfo added in v1.1.6

type DatabaseInfo struct {
	Name       string
	Size       int64 // Size in bytes
	TableCount int
	IsSystem   bool   // Whether it's a system database
	Charset    string // Character set/encoding
}

DatabaseInfo contains metadata about a database

type DatabaseType added in v1.1.6

type DatabaseType string

DatabaseType represents the type of database

const (
	MySQL      DatabaseType = "mysql"
	PostgreSQL DatabaseType = "postgresql"
)

type DefaultProviderFactory added in v1.1.6

type DefaultProviderFactory struct{}

DefaultProviderFactory implements ProviderFactory

func (*DefaultProviderFactory) CreateProvider added in v1.1.6

func (f *DefaultProviderFactory) CreateProvider(config *ProviderConfig) (Provider, error)

CreateProvider creates a database provider based on the configuration

func (*DefaultProviderFactory) GetSupportedTypes added in v1.1.6

func (f *DefaultProviderFactory) GetSupportedTypes() []DatabaseType

GetSupportedTypes returns the list of supported database types

type LegacyDatabaseConfig added in v1.1.6

type LegacyDatabaseConfig struct {
	Host          string `yaml:"host"`
	Port          int    `yaml:"port"`
	Username      string `yaml:"username"`
	Password      string `yaml:"password"`
	Timeout       int    `yaml:"timeout"`
	MysqldumpPath string `yaml:"mysqldump_path"`
	MysqlPath     string `yaml:"mysql_path"`
}

LegacyDatabaseConfig represents the old MySQL-only configuration for backward compatibility

type MySQLConfig added in v1.1.6

type MySQLConfig struct {
	// Existing MySQL configuration will be moved here
	UseMyDumper       bool   `yaml:"use_mydumper"`
	MyDumperPath      string `yaml:"mydumper_path,omitempty"`
	MyLoaderPath      string `yaml:"myloader_path,omitempty"`
	SingleTransaction bool   `yaml:"single_transaction"`
	LockTables        bool   `yaml:"lock_tables"`
	RoutinesAndEvents bool   `yaml:"routines_and_events"`
}

MySQLConfig contains MySQL-specific configuration

type MySQLProvider added in v1.1.6

type MySQLProvider struct {
	// contains filtered or unexported fields
}

MySQLProvider implements the Provider interface for MySQL databases

func (*MySQLProvider) Close added in v1.1.6

func (p *MySQLProvider) Close() error

Close closes the database connection

func (*MySQLProvider) CreateBackup added in v1.1.6

func (p *MySQLProvider) CreateBackup(ctx context.Context, opts *BackupOptions) ([]*BackupResult, error)

CreateBackup creates backups for the specified databases

func (*MySQLProvider) DatabaseExists added in v1.1.6

func (p *MySQLProvider) DatabaseExists(ctx context.Context, dbName string) (bool, error)

DatabaseExists checks if a database exists

func (*MySQLProvider) GetAvailableTools added in v1.1.6

func (p *MySQLProvider) GetAvailableTools() []string

GetAvailableTools returns available MySQL tools

func (*MySQLProvider) GetDefaultPort added in v1.1.6

func (p *MySQLProvider) GetDefaultPort() int

GetDefaultPort returns the default MySQL port

func (*MySQLProvider) GetProviderType added in v1.1.6

func (p *MySQLProvider) GetProviderType() DatabaseType

GetProviderType returns the provider type

func (*MySQLProvider) GetSystemDatabases added in v1.1.6

func (p *MySQLProvider) GetSystemDatabases() []string

GetSystemDatabases returns MySQL system databases

func (*MySQLProvider) ListDatabases added in v1.1.6

func (p *MySQLProvider) ListDatabases(ctx context.Context) ([]*DatabaseInfo, error)

ListDatabases returns a list of all databases

func (*MySQLProvider) RestoreBackup added in v1.1.6

func (p *MySQLProvider) RestoreBackup(ctx context.Context, opts *RestoreOptions) error

RestoreBackup restores a database from backup

func (*MySQLProvider) TestConnection added in v1.1.6

func (p *MySQLProvider) TestConnection(ctx context.Context) error

TestConnection tests the database connection

func (*MySQLProvider) ValidateTools added in v1.1.6

func (p *MySQLProvider) ValidateTools() error

ValidateTools validates that required tools are available

type PostgreSQLConfig added in v1.1.6

type PostgreSQLConfig struct {
	// Will be implemented in v1.2.0
	UsePgDumpParallel bool   `yaml:"use_pg_dump_parallel"`
	PgDumpPath        string `yaml:"pg_dump_path,omitempty"`
	PsqlPath          string `yaml:"psql_path,omitempty"`
	Format            string `yaml:"format"` // plain, custom, directory, tar
}

PostgreSQLConfig contains PostgreSQL-specific configuration

type Provider added in v1.1.6

type Provider interface {
	// Connection management
	TestConnection(ctx context.Context) error
	Close() error

	// Database operations
	ListDatabases(ctx context.Context) ([]*DatabaseInfo, error)
	DatabaseExists(ctx context.Context, dbName string) (bool, error)

	// Backup operations
	CreateBackup(ctx context.Context, opts *BackupOptions) ([]*BackupResult, error)

	// Restore operations
	RestoreBackup(ctx context.Context, opts *RestoreOptions) error

	// Tool availability
	GetAvailableTools() []string
	ValidateTools() error

	// Provider metadata
	GetProviderType() DatabaseType
	GetDefaultPort() int
	GetSystemDatabases() []string
}

Provider defines the interface that all database providers must implement

func NewMySQLProvider added in v1.1.6

func NewMySQLProvider(config *ProviderConfig) (Provider, error)

NewMySQLProvider creates a new MySQL provider

type ProviderConfig added in v1.1.6

type ProviderConfig struct {
	Type     DatabaseType `yaml:"type"`
	Host     string       `yaml:"host"`
	Port     int          `yaml:"port"`
	Username string       `yaml:"username"`
	Password string       `yaml:"password"`
	SSLMode  string       `yaml:"ssl_mode,omitempty"`
	Timeout  string       `yaml:"timeout,omitempty"`

	// Tool paths (auto-discovered if empty)
	DumpToolPath     string `yaml:"dump_tool_path,omitempty"`
	ClientToolPath   string `yaml:"client_tool_path,omitempty"`
	ParallelToolPath string `yaml:"parallel_tool_path,omitempty"`

	// Provider-specific options
	MySQL      *MySQLConfig      `yaml:"mysql,omitempty"`
	PostgreSQL *PostgreSQLConfig `yaml:"postgresql,omitempty"`
}

ProviderConfig contains common configuration for all providers

func MigrateFromLegacyConfig added in v1.1.6

func MigrateFromLegacyConfig(legacy *LegacyDatabaseConfig) *ProviderConfig

MigrateFromLegacyConfig converts legacy config to new provider config

type ProviderFactory added in v1.1.6

type ProviderFactory interface {
	CreateProvider(config *ProviderConfig) (Provider, error)
	GetSupportedTypes() []DatabaseType
}

ProviderFactory creates database providers based on configuration

func NewProviderFactory added in v1.1.6

func NewProviderFactory() ProviderFactory

NewProviderFactory creates a new provider factory

type RestoreOptions added in v1.1.6

type RestoreOptions struct {
	BackupPath   string
	TargetDB     string
	DropIfExists bool
	Timeout      time.Duration
	ExtraArgs    []string
}

RestoreOptions contains options for restore operations

type SetupWizard added in v1.1.6

type SetupWizard struct {
	// contains filtered or unexported fields
}

SetupWizard provides an interactive setup for database configuration

func NewSetupWizard added in v1.1.6

func NewSetupWizard() *SetupWizard

NewSetupWizard creates a new setup wizard

func (*SetupWizard) SetupDatabaseConfig added in v1.1.6

func (w *SetupWizard) SetupDatabaseConfig() (*ProviderConfig, error)

SetupDatabaseConfig interactively configures database settings with multi-database support

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL