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 DisplayMode
- type ForeignKey
- type ForeignKeyManager
- func (fkm *ForeignKeyManager) CleanupBackupFile() 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) RecoverFromBackupFile() error
- func (fkm *ForeignKeyManager) RestoreForeignKeysForTable(table *TableInfo) error
- func (fkm *ForeignKeyManager) SetLogger(logger *utils.SimpleLogger)
- func (fkm *ForeignKeyManager) TryUseReplicaMode() error
- type InteractiveDisplay
- func (d *InteractiveDisplay) CompleteTable(schema, name string, success bool)
- func (d *InteractiveDisplay) SetTotalRows(totalRows int64)
- func (d *InteractiveDisplay) Start()
- func (d *InteractiveDisplay) StartTable(schema, name string, rowCount int64)
- func (d *InteractiveDisplay) Stop()
- func (d *InteractiveDisplay) UpdateTableProgress(schema, name string, copiedRows int64)
- type TableInfo
- type TableProgress
- type TableStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateConfig ¶
ValidateConfig validates the configuration
Types ¶
type Config ¶
type Config struct {
SourceConn string
DestConn string
SourceFile string
DestFile string
Parallel int
BatchSize int
ExcludeTables []string
IncludeTables []string
Resume bool
DryRun bool
Mode DisplayMode
}
Config holds the configuration for the data copy operation
type Copier ¶
type Copier struct {
// contains filtered or unexported fields
}
Copier handles the data copying operation
type CopyStats ¶
type CopyStats struct {
TablesProcessed int64
RowsCopied int64
TotalTables int64
TotalRows int64
ForeignKeysDetected int64
ForeignKeysDropped int64
StartTime time.Time
Errors []error
}
CopyStats tracks copying statistics
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" )
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) CleanupBackupFile ¶
func (fkm *ForeignKeyManager) CleanupBackupFile() error
CleanupBackupFile removes the backup file on successful completion
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) RecoverFromBackupFile ¶
func (fkm *ForeignKeyManager) RecoverFromBackupFile() error
RecoverFromBackupFile attempts to restore FKs from backup file if they exist but weren't tracked
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 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(totalTables int) *InteractiveDisplay
NewInteractiveDisplay creates a new interactive display
func (*InteractiveDisplay) CompleteTable ¶ added in v0.2.0
func (d *InteractiveDisplay) CompleteTable(schema, name string, success bool)
CompleteTable marks a table as completed
func (*InteractiveDisplay) SetTotalRows ¶ added in v0.2.0
func (d *InteractiveDisplay) SetTotalRows(totalRows int64)
SetTotalRows sets the total number of rows across all tables
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(schema, name string, rowCount int64)
StartTable marks a table as started
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(schema, name string, copiedRows int64)
UpdateTableProgress updates the progress of a table
type TableInfo ¶
type TableInfo struct {
Schema string
Name string
RowCount int64
Columns []string
PKColumns []string
}
TableInfo holds information about a table to be copied
type TableProgress ¶ added in v0.2.0
type TableProgress struct {
Schema string
Name string
RowCount int64
CopiedRows int64
StartTime time.Time
EndTime *time.Time
Status TableStatus
Order int // Order in which table was started or completed
}
TableProgress represents the progress of a single table
type TableStatus ¶ added in v0.2.0
type TableStatus int
TableStatus represents the current status of a table
const ( TableStatusPending TableStatus = iota // Table is waiting to be processed TableStatusInProgress // Table is currently being copied TableStatusCompleted // Table has been successfully copied TableStatusFailed // Table copying failed )
Table status constants