Documentation
¶
Index ¶
- func CreateSchema(db *sql.DB, targetDriver, migrationsPath string) error
- func DropAllTables(db *sql.DB, driver string) error
- func GetMigrationsPath() string
- func OpenTargetDB(config TargetConfig) (*sql.DB, error)
- func QuickVerify(ctx context.Context, sourceDB *sql.DB, sourceDriver string, targetDB *sql.DB, ...) (bool, error)
- func TransferData(ctx context.Context, sourceDB *sql.DB, sourceDriver string, targetDB *sql.DB, ...) error
- func VerifySchema(ctx context.Context, db *sql.DB, driver string) error
- type ConfigSaver
- type ConnectionTestDetails
- type ConnectionTestResult
- type Error
- type EstimateInfo
- type EstimateRequest
- type EstimateResponse
- type MigrationRequest
- type MigrationStartResponse
- type Phase
- type PhaseInfo
- type PhaseStatus
- type PostgresConfig
- type Progress
- type ProgressCallback
- type Result
- type SQLiteConfig
- type Service
- func (s *Service) Estimate(ctx context.Context, targetDriver string) (*EstimateResponse, error)
- func (s *Service) GetState() State
- func (s *Service) IsInProgress() bool
- func (s *Service) SetOnChange(fn func(state State))
- func (s *Service) Start(ctx context.Context, config MigrationRequest) (*MigrationStartResponse, error)
- func (s *Service) TestConnection(ctx context.Context, config TargetConfig) ConnectionTestResult
- type SourceInfo
- type State
- type Status
- type TableInfo
- type TableVerificationResult
- type TargetConfig
- type TransferProgress
- type VerificationResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateSchema ¶
CreateSchema runs migrations to create the schema in the target database. It determines the correct migrations path based on the target driver and runs all available migrations.
func DropAllTables ¶
DropAllTables drops all tables in the target database. This is used when migration fails and we need to clean up.
func GetMigrationsPath ¶
func GetMigrationsPath() string
GetMigrationsPath returns the default migrations path for the application.
func OpenTargetDB ¶
func OpenTargetDB(config TargetConfig) (*sql.DB, error)
OpenTargetDB opens a connection to the target database.
func QuickVerify ¶
func QuickVerify( ctx context.Context, sourceDB *sql.DB, sourceDriver string, targetDB *sql.DB, targetDriver string, ) (bool, error)
QuickVerify performs a quick verification by comparing total row counts. This is faster than full verification but less thorough.
Types ¶
type ConfigSaver ¶
type ConfigSaver func(driver string, pgHost string, pgPort int, pgUser, pgDatabase, pgSSLMode string) error
ConfigSaver is a function that saves database configuration after migration. This is used to break the import cycle with the config package.
type ConnectionTestDetails ¶
type ConnectionTestDetails struct {
Version string `json:"version"`
ServerTime time.Time `json:"serverTime"`
IsEmpty bool `json:"isEmpty"`
ExistingTables int `json:"existingTables"`
}
ConnectionTestDetails contains detailed connection information.
func GetConnectionDetails ¶
func GetConnectionDetails(ctx context.Context, db *sql.DB, driver string) (*ConnectionTestDetails, error)
GetConnectionDetails gets details about a database connection.
type ConnectionTestResult ¶
type ConnectionTestResult struct {
Success bool `json:"success"`
Message string `json:"message"`
Error string `json:"error,omitempty"`
Details *ConnectionTestDetails `json:"details,omitempty"`
}
ConnectionTestResult contains the result of a connection test.
func TestConnection ¶
func TestConnection(ctx context.Context, config TargetConfig) ConnectionTestResult
TestConnection tests a connection to the target database.
type Error ¶
type Error struct {
Phase Phase `json:"phase"`
Table string `json:"table,omitempty"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
}
Error contains migration error information.
type EstimateInfo ¶
type EstimateInfo struct {
DurationSeconds int `json:"durationSeconds"`
DurationHuman string `json:"durationHuman"`
DataSizeBytes int64 `json:"dataSizeBytes"`
Tables []TableInfo `json:"tables"`
}
EstimateInfo contains estimated migration metrics.
type EstimateRequest ¶
type EstimateRequest struct {
TargetDriver string `json:"targetDriver"`
}
EstimateRequest contains the request for migration estimation.
type EstimateResponse ¶
type EstimateResponse struct {
Source SourceInfo `json:"source"`
Estimate EstimateInfo `json:"estimate"`
Warnings []string `json:"warnings"`
}
EstimateResponse contains the migration estimation result.
func EstimateMigration ¶
func EstimateMigration(ctx context.Context, db *sql.DB, sourceDriver, targetDriver string) (*EstimateResponse, error)
EstimateMigration estimates the migration time and data size.
type MigrationRequest ¶
type MigrationRequest struct {
TargetDriver string `json:"targetDriver"`
Postgres *PostgresConfig `json:"postgres,omitempty"`
SQLite *SQLiteConfig `json:"sqlite,omitempty"`
}
MigrationRequest contains the request to start a migration.
type MigrationStartResponse ¶
type MigrationStartResponse struct {
Started bool `json:"started"`
MigrationID string `json:"migrationId,omitempty"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
}
MigrationStartResponse contains the response when starting a migration.
type PhaseInfo ¶
type PhaseInfo struct {
Name Phase `json:"name"`
Status PhaseStatus `json:"status"`
}
PhaseInfo contains information about a migration phase.
type PhaseStatus ¶
type PhaseStatus string
PhaseStatus represents the status of a migration phase.
const ( PhaseStatusPending PhaseStatus = "pending" PhaseStatusInProgress PhaseStatus = "in_progress" PhaseStatusCompleted PhaseStatus = "completed" PhaseStatusFailed PhaseStatus = "failed" PhaseStatusSkipped PhaseStatus = "skipped" )
type PostgresConfig ¶
type PostgresConfig struct {
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Password string `json:"password"`
Database string `json:"database"`
SSLMode string `json:"sslMode"`
}
PostgresConfig contains PostgreSQL connection settings.
type Progress ¶
type Progress struct {
CurrentTable string `json:"currentTable,omitempty"`
TablesCompleted int `json:"tablesCompleted"`
TablesTotal int `json:"tablesTotal"`
RowsCopied int64 `json:"rowsCopied"`
RowsTotal int64 `json:"rowsTotal"`
BytesCopied int64 `json:"bytesCopied"`
BytesTotal int64 `json:"bytesTotal"`
PercentComplete int `json:"percentComplete"`
ElapsedSeconds int `json:"elapsedSeconds"`
EstimatedRemainingSeconds int `json:"estimatedRemainingSeconds"`
}
Progress contains migration progress information.
type ProgressCallback ¶
type ProgressCallback func(progress TransferProgress)
ProgressCallback is called during transfer to report progress.
type Result ¶
type Result struct {
TablesMigrated int `json:"tablesMigrated"`
RowsMigrated int64 `json:"rowsMigrated"`
VerificationPassed bool `json:"verificationPassed"`
OldDatabasePath string `json:"oldDatabasePath,omitempty"`
RequiresRestart bool `json:"requiresRestart"`
DurationSeconds int `json:"durationSeconds"`
}
Result contains migration result information.
type SQLiteConfig ¶
type SQLiteConfig struct {
Path string `json:"path"`
}
SQLiteConfig contains SQLite connection settings.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service orchestrates database migrations.
func NewService ¶
func NewService(sourceDB *sql.DB, sourceDriver string, maintenanceMgr *system.MaintenanceManager, configSaver ConfigSaver) *Service
NewService creates a new migration service.
func (*Service) IsInProgress ¶
IsInProgress returns whether a migration is currently in progress.
func (*Service) SetOnChange ¶
SetOnChange sets a callback for state changes.
func (*Service) Start ¶
func (s *Service) Start(ctx context.Context, config MigrationRequest) (*MigrationStartResponse, error)
Start begins a database migration.
func (*Service) TestConnection ¶
func (s *Service) TestConnection(ctx context.Context, config TargetConfig) ConnectionTestResult
TestConnection tests a connection to the target database.
type SourceInfo ¶
type SourceInfo struct {
Driver string `json:"driver"`
SizeBytes int64 `json:"sizeBytes"`
TableCount int `json:"tableCount"`
TotalRows int64 `json:"totalRows"`
}
SourceInfo contains information about the source database.
type State ¶
type State struct {
Status Status `json:"status"`
MigrationID string `json:"migrationId,omitempty"`
Phase Phase `json:"phase,omitempty"`
StartedAt *time.Time `json:"startedAt,omitempty"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
FailedAt *time.Time `json:"failedAt,omitempty"`
Progress *Progress `json:"progress,omitempty"`
Phases []PhaseInfo `json:"phases,omitempty"`
Result *Result `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
State represents the current migration state.
type TableInfo ¶
type TableInfo struct {
Name string `json:"name"`
Rows int64 `json:"rows"`
SizeBytes int64 `json:"sizeBytes"`
}
TableInfo contains information about a table.
type TableVerificationResult ¶
type TableVerificationResult struct {
TableName string `json:"tableName"`
SourceRows int64 `json:"sourceRows"`
TargetRows int64 `json:"targetRows"`
Match bool `json:"match"`
Error string `json:"error,omitempty"`
}
TableVerificationResult contains verification result for a single table.
type TargetConfig ¶
type TargetConfig struct {
Driver string `json:"driver"`
Postgres *PostgresConfig `json:"postgres,omitempty"`
SQLite *SQLiteConfig `json:"sqlite,omitempty"`
}
TargetConfig contains configuration for the target database.
type TransferProgress ¶
type TransferProgress struct {
CurrentTable string
TablesCompleted int
TablesTotal int
RowsCopied int64
RowsTotal int64
}
TransferProgress tracks progress during data transfer.
type VerificationResult ¶
type VerificationResult struct {
Success bool `json:"success"`
TableResults []TableVerificationResult `json:"tableResults"`
Errors []string `json:"errors,omitempty"`
}
VerificationResult contains the result of migration verification.
func VerifyMigration ¶
func VerifyMigration( ctx context.Context, sourceDB *sql.DB, sourceDriver string, targetDB *sql.DB, targetDriver string, ) (*VerificationResult, error)
VerifyMigration verifies that data was correctly migrated by comparing row counts. It only verifies tables that exist in BOTH source AND target (some source tables like plugin tables may not exist in target).