Documentation
¶
Overview ¶
Package copier provides functionality for copying data between PostgreSQL databases. It handles table discovery, foreign key management, parallel copying, and progress tracking.
Index ¶
- func ValidateConfig(config *Config) error
- type Config
- type Copier
- type CopyStats
- type Discovery
- type DisplayMode
- type Executor
- type ForeignKey
- type ForeignKeyManager
- func (fkm *ForeignKeyManager) Cleanup() error
- func (fkm *ForeignKeyManager) CleanupBackupFile() error
- func (fkm *ForeignKeyManager) Detect(tables []*TableInfo) error
- func (fkm *ForeignKeyManager) DetectForeignKeys(tables []*TableInfo) error
- func (fkm *ForeignKeyManager) DisableReplicaMode() error
- func (fkm *ForeignKeyManager) DropForeignKeysForTable(table *TableInfo) error
- func (fkm *ForeignKeyManager) GetForeignKeyStats() (total, dropped int)
- func (fkm *ForeignKeyManager) IsUsingReplicaMode() bool
- func (fkm *ForeignKeyManager) Prepare(table *TableInfo) error
- func (fkm *ForeignKeyManager) RecoverFromBackupFile() error
- func (fkm *ForeignKeyManager) Restore(table *TableInfo) error
- func (fkm *ForeignKeyManager) RestoreForeignKeysForTable(table *TableInfo) error
- func (fkm *ForeignKeyManager) SetLogger(logger *utils.SimpleLogger)
- func (fkm *ForeignKeyManager) TryUseReplicaMode() error
- type ForeignKeyStrategy
- type InteractiveDisplay
- func (d *InteractiveDisplay) CompleteTable(_, _ string, _ bool)
- func (d *InteractiveDisplay) SetTotalRows(_ int64)
- func (d *InteractiveDisplay) Start()
- func (d *InteractiveDisplay) StartTable(_, _ string, _ int64)
- func (d *InteractiveDisplay) Stop()
- func (d *InteractiveDisplay) UpdateTableProgress(_, _ string, _ int64)
- type Persistence
- type Planner
- type ProgressSink
- type Reporter
- type TableInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateConfig ¶
ValidateConfig validates the configuration
Types ¶
type Config ¶
type Config = state.OperationConfig
Config is a type alias for state.OperationConfig for backward compatibility
type Copier ¶
type Copier struct {
// contains filtered or unexported fields
}
Copier handles the data copying operation using centralized state management
func NewWithState ¶ added in v0.4.0
NewWithState creates a new Copier instance with an existing state
func NewWithWebPort ¶ added in v0.4.0
NewWithWebPort creates a new Copier instance with web server support
type Discovery ¶ added in v0.4.0
type Discovery interface {
DiscoverTables() ([]*TableInfo, error)
DetectForeignKeys(tables []*TableInfo) error
}
Discovery is responsible for table / FK discovery and basic stats.
type DisplayMode ¶ added in v0.2.0
type DisplayMode string
DisplayMode represents different output modes for progress tracking
const ( // DisplayModeRaw shows minimal output, suitable for headless/CI environments (default) // Note: Internal name remains "raw" for backwards compatibility in code DisplayModeRaw DisplayMode = "raw" // DisplayModeProgress shows a progress bar DisplayModeProgress DisplayMode = "progress" // DisplayModeInteractive shows an interactive live display with table details DisplayModeInteractive DisplayMode = "interactive" // DisplayModeWeb launches a web interface for monitoring the copy process DisplayModeWeb DisplayMode = "web" )
type ForeignKey ¶
type ForeignKey struct {
ConstraintName string
Schema string
Table string
Columns []string
ReferencedSchema string
ReferencedTable string
ReferencedColumns []string
OnDelete string
OnUpdate string
Definition string // Full CREATE CONSTRAINT statement
}
ForeignKey represents a foreign key constraint
type ForeignKeyManager ¶
type ForeignKeyManager struct {
// contains filtered or unexported fields
}
ForeignKeyManager handles foreign key operations
func NewForeignKeyManager ¶
func NewForeignKeyManager(db *sql.DB, logger *utils.SimpleLogger) *ForeignKeyManager
NewForeignKeyManager creates a new foreign key manager
func (*ForeignKeyManager) Cleanup ¶ added in v0.4.0
func (fkm *ForeignKeyManager) Cleanup() error
Cleanup removes residual FK backup artifacts after successful run.
func (*ForeignKeyManager) CleanupBackupFile ¶
func (fkm *ForeignKeyManager) CleanupBackupFile() error
CleanupBackupFile removes the backup file on successful completion
func (*ForeignKeyManager) Detect ¶ added in v0.4.0
func (fkm *ForeignKeyManager) Detect(tables []*TableInfo) error
Detect discovers foreign key constraints for provided tables (ForeignKeyStrategy implementation).
func (*ForeignKeyManager) DetectForeignKeys ¶
func (fkm *ForeignKeyManager) DetectForeignKeys(tables []*TableInfo) error
DetectForeignKeys discovers all foreign keys in the database
func (*ForeignKeyManager) DisableReplicaMode ¶
func (fkm *ForeignKeyManager) DisableReplicaMode() error
DisableReplicaMode disables replica mode
func (*ForeignKeyManager) DropForeignKeysForTable ¶
func (fkm *ForeignKeyManager) DropForeignKeysForTable(table *TableInfo) error
DropForeignKeysForTable drops all foreign keys that reference or are referenced by a table
func (*ForeignKeyManager) GetForeignKeyStats ¶
func (fkm *ForeignKeyManager) GetForeignKeyStats() (total, dropped int)
GetForeignKeyStats returns statistics about foreign keys
func (*ForeignKeyManager) IsUsingReplicaMode ¶
func (fkm *ForeignKeyManager) IsUsingReplicaMode() bool
IsUsingReplicaMode returns whether replica mode is enabled
func (*ForeignKeyManager) Prepare ¶ added in v0.4.0
func (fkm *ForeignKeyManager) Prepare(table *TableInfo) error
Prepare performs pre-copy FK handling for a table (drop or noop in replica mode).
func (*ForeignKeyManager) RecoverFromBackupFile ¶
func (fkm *ForeignKeyManager) RecoverFromBackupFile() error
RecoverFromBackupFile attempts to restore FKs from backup file if they exist but weren't tracked
func (*ForeignKeyManager) Restore ¶ added in v0.4.0
func (fkm *ForeignKeyManager) Restore(table *TableInfo) error
Restore re-creates foreign keys associated with the table.
func (*ForeignKeyManager) RestoreForeignKeysForTable ¶
func (fkm *ForeignKeyManager) RestoreForeignKeysForTable(table *TableInfo) error
RestoreForeignKeysForTable restores foreign keys related to a specific table
func (*ForeignKeyManager) SetLogger ¶ added in v0.2.0
func (fkm *ForeignKeyManager) SetLogger(logger *utils.SimpleLogger)
SetLogger updates the logger for the foreign key manager
func (*ForeignKeyManager) TryUseReplicaMode ¶
func (fkm *ForeignKeyManager) TryUseReplicaMode() error
TryUseReplicaMode attempts to use replica mode for FK handling
type ForeignKeyStrategy ¶ added in v0.4.0
type ForeignKeyStrategy interface {
Detect(tables []*TableInfo) error
Prepare(table *TableInfo) error // before copy of a table
Restore(table *TableInfo) error // after copy of a table
Cleanup() error // after all tables
}
ForeignKeyStrategy abstracts FK handling modes.
type InteractiveDisplay ¶ added in v0.2.0
type InteractiveDisplay struct {
// contains filtered or unexported fields
}
InteractiveDisplay manages the interactive CLI display
func NewInteractiveDisplay ¶ added in v0.2.0
func NewInteractiveDisplay(state *state.CopyState) *InteractiveDisplay
NewInteractiveDisplay creates a new interactive display
func (*InteractiveDisplay) CompleteTable ¶ added in v0.2.0
func (d *InteractiveDisplay) CompleteTable(_, _ string, _ bool)
CompleteTable is now a no-op since the state system handles this
func (*InteractiveDisplay) SetTotalRows ¶ added in v0.2.0
func (d *InteractiveDisplay) SetTotalRows(_ int64)
SetTotalRows is now a no-op since the state system handles this
func (*InteractiveDisplay) Start ¶ added in v0.2.0
func (d *InteractiveDisplay) Start()
Start begins the interactive display loop
func (*InteractiveDisplay) StartTable ¶ added in v0.2.0
func (d *InteractiveDisplay) StartTable(_, _ string, _ int64)
StartTable is now a no-op since the state system handles this
func (*InteractiveDisplay) Stop ¶ added in v0.2.0
func (d *InteractiveDisplay) Stop()
Stop stops the interactive display
func (*InteractiveDisplay) UpdateTableProgress ¶ added in v0.2.0
func (d *InteractiveDisplay) UpdateTableProgress(_, _ string, _ int64)
UpdateTableProgress is now a no-op since the state system handles this
type Persistence ¶ added in v0.4.0
type Persistence interface {
}
Persistence handles durable logging / summaries.
type Planner ¶ added in v0.4.0
Planner orders tables & resolves dependencies (currently passthrough).
type ProgressSink ¶ added in v0.4.0
type ProgressSink interface {
UpdateTable(schema, table string, rowsCopied int64)
Log(level, msg, scope, table string)
Done()
}
ProgressSink receives progress events decoupled from execution.
type Reporter ¶ added in v0.4.0
type Reporter interface {
}
Reporter handles state broadcasting / console rendering (future use).
type TableInfo ¶
type TableInfo = state.TableState
TableInfo is a type alias for state.TableState for backward compatibility