copier

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package copier provides functionality for copying data between PostgreSQL databases

Index

Constants

View Source
const (
	ColorReset   = "\033[0m"
	ColorRed     = "\033[31m"
	ColorGreen   = "\033[32m"
	ColorYellow  = "\033[33m"
	ColorBlue    = "\033[34m"
	ColorMagenta = "\033[35m"
	ColorCyan    = "\033[36m"
	ColorWhite   = "\033[37m"
	ColorBold    = "\033[1m"
	ColorDim     = "\033[2m"
)

ANSI color codes

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(config *Config) error

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
	ProgressBar   bool
}

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

func New

func New(config *Config) (*Copier, error)

New creates a new Copier instance

func (*Copier) Close

func (c *Copier) Close()

Close closes database connections

func (*Copier) Copy

func (c *Copier) Copy() error

Copy performs 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 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 Logger) *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) TryUseReplicaMode

func (fkm *ForeignKeyManager) TryUseReplicaMode() error

TryUseReplicaMode attempts to use replica mode for FK handling

type Logger

type Logger interface {
	// contains filtered or unexported methods
}

Logger interface for colorized logging

type TableInfo

type TableInfo struct {
	Schema    string
	Name      string
	RowCount  int64
	Columns   []string
	PKColumns []string
}

TableInfo holds information about a table to be copied

Jump to

Keyboard shortcuts

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