database

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckToolsAvailable

func CheckToolsAvailable() error

CheckToolsAvailable verifies that pg_dump and pg_restore are installed

func CreateDump

func CreateDump(config *DatabaseConfig, options *DumpOptions) ([]byte, error)

CreateDump creates a database dump using pg_dump (or Docker)

func ExtractMajorVersion added in v0.17.0

func ExtractMajorVersion(versionStr string) string

ExtractMajorVersion extracts the major version from a PostgreSQL version string Example: "PostgreSQL 17.4 (Debian 17.4-1.pgdg120+1)" -> "17"

func FormatConnectionInfo

func FormatConnectionInfo(config *DatabaseConfig) string

FormatConnectionInfo returns a safe string representation of the connection (without password) for logging purposes

func GetPgDumpPath

func GetPgDumpPath() string

GetPgDumpPath returns the path to the pg_dump binary Checks PG_DUMP_BINARY environment variable, defaults to /usr/local/bin/pg_dump

func GetPgRestorePath

func GetPgRestorePath() string

GetPgRestorePath returns the path to the pg_restore binary Checks PG_RESTORE_BINARY environment variable, defaults to /usr/local/bin/pg_restore

func GetPostgresURLFromEnv

func GetPostgresURLFromEnv() string

GetPostgresURLFromEnv retrieves the POSTGRES_URL environment variable

func GetPostgresVersion

func GetPostgresVersion(config *DatabaseConfig) (string, error)

GetPostgresVersion retrieves the PostgreSQL server version

func GetPsqlPath

func GetPsqlPath() string

GetPsqlPath returns the path to the psql binary Checks PSQL_BINARY environment variable, defaults to /usr/local/bin/psql

func IsDockerAvailable added in v0.17.0

func IsDockerAvailable() bool

IsDockerAvailable checks if Docker is installed and accessible

func IsPostgresURLSet

func IsPostgresURLSet() bool

IsPostgresURLSet checks if the POSTGRES_URL environment variable is set

func NeedsDockerHostNetwork added in v0.17.0

func NeedsDockerHostNetwork(host string) bool

NeedsDockerHostNetwork returns true if Docker should use --network=host This is needed on Linux when connecting to localhost

func PurgeDatabase

func PurgeDatabase(config *DatabaseConfig, dryRun bool) error

PurgeDatabase drops all tables and schemas in the database

func ResolveDockerHost added in v0.17.0

func ResolveDockerHost(host string) string

ResolveDockerHost resolves localhost addresses for Docker containers On Mac/Windows: localhost -> host.docker.internal On Linux: returns original host (will use --network=host flag instead)

func RestoreDump

func RestoreDump(config *DatabaseConfig, dumpData []byte, options *RestoreOptions) error

RestoreDump restores a database dump using pg_restore or psql (or Docker)

func TestConnection

func TestConnection(config *DatabaseConfig) error

TestConnection validates that the database is accessible

func UseDockerPgTools added in v0.17.0

func UseDockerPgTools() bool

UseDockerPgTools checks if Docker should be used for PostgreSQL tools Checks USE_DOCKER_PG_TOOLS environment variable

func ValidateConfig

func ValidateConfig(config *DatabaseConfig) error

ValidateConfig performs basic validation on a DatabaseConfig

Types

type DatabaseBackupMetadata

type DatabaseBackupMetadata struct {
	BackupTimestamp string
	DatabaseName    string
	PostgresVersion string
	DumpFormat      string
	Compressed      bool
}

DatabaseBackupMetadata tracks database backup information

type DatabaseConfig

type DatabaseConfig struct {
	URL      string // Full connection string
	Host     string
	Port     int
	Database string
	User     string
	Password string
}

DatabaseConfig holds PostgreSQL connection details

func ParsePostgresURL

func ParsePostgresURL(connectionURL string) (*DatabaseConfig, error)

ParsePostgresURL parses a PostgreSQL connection string into a DatabaseConfig Expected format: postgres://user:password@host:port/dbname

type DumpOptions

type DumpOptions struct {
	Format       string // "plain" for SQL, "custom" for pg_restore format
	Verbose      bool
	Compress     int // 0-9 compression level (for custom format)
	SchemaOnly   bool
	DataOnly     bool
	NoOwner      bool
	NoPrivileges bool
}

DumpOptions configures pg_dump behavior

type RestoreOptions

type RestoreOptions struct {
	CreateDB     bool // Create database before restore
	NoOwner      bool
	NoPrivileges bool
	Verbose      bool
}

RestoreOptions configures pg_restore behavior

Jump to

Keyboard shortcuts

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