engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(e Engine)

Register adds e to the registry under e.Name(). Typically called from engine package init() functions. Panics on duplicate registration.

func ValidateSourceHost

func ValidateSourceHost(host string) error

ValidateSourceHost rejects loopback addresses that are unreachable from dump helper containers. Both the postgres and mysql engines call this.

Types

type DumpOptions

type DumpOptions struct {
	SchemaOnly bool // when true, dump DDL only — no row data
}

DumpOptions controls optional dump behaviour. The zero value produces a full dump (schema + data), which is the default for all call sites.

type Engine

type Engine interface {
	// Name returns the identifier used in ditto.yaml (e.g. "postgres", "mysql").
	Name() string

	// Dump writes a compressed dump of src to destPath through the configured
	// Docker-compatible runtime. clientImage overrides the helper image used for
	// the dump when non-empty. opts controls whether the dump includes row data.
	Dump(ctx context.Context, docker *client.Client, clientImage string, src SourceConfig, destPath string, opts DumpOptions) error

	// Restore loads a dump file into a running container through the
	// configured Docker-compatible runtime.
	// containerName is the Docker container name (e.g. "ditto-<id>") as set by the
	// copy manager. The manager calls WaitReady before Restore, so the container is
	// guaranteed to be accepting connections when this method is invoked.
	Restore(ctx context.Context, docker *client.Client, dumpPath string, containerName string) error

	// DumpFromContainer creates a compressed dump of the database running inside
	// containerName and writes it to destPath on the host. The container must
	// have its dump directory mounted at /dump (as copy and staging containers do).
	// Used by the dump scheduler to bake obfuscation into the dump file.
	// opts controls whether the dump includes row data.
	DumpFromContainer(ctx context.Context, docker *client.Client, containerName string, destPath string, opts DumpOptions) error

	// ContainerEnv returns the environment variables needed to initialise the
	// database inside a copy or staging container.
	ContainerEnv() []string

	// ContainerImage returns the Docker image (with pinned tag) for copies.
	ContainerImage() string

	// WaitReady blocks until the database in the container on port is ready
	// to accept connections, or until timeout elapses.
	WaitReady(port int, timeout time.Duration) error

	// ConnectionString returns a DSN for connecting to the copy on port.
	ConnectionString(host string, port int) string
}

Engine is the interface that each database engine must implement. All engine-specific behaviour (dump, restore, readiness, connection strings) lives behind this interface; the copy manager never imports engine packages directly.

func Get

func Get(name string) (Engine, error)

Get returns the registered Engine for name, or an error listing available engines if name is not found.

type SourceConfig

type SourceConfig struct {
	Host           string
	Port           int
	Database       string
	User           string
	Password       string // resolved from PasswordSecret at runtime
	PasswordSecret string // secret reference: env:VAR, file:/path, or arn:aws:...
	// NetworkName, when non-empty, attaches the dump helper container to this
	// Docker network so it can reach the source by container hostname. Leave
	// empty when the source is a real network-addressable host.
	NetworkName string
}

SourceConfig holds the connection parameters for the source database.

Directories

Path Synopsis
Package mysql implements the ditto Engine interface for MySQL and MariaDB.
Package mysql implements the ditto Engine interface for MySQL and MariaDB.
Package postgres implements the ditto Engine interface for PostgreSQL.
Package postgres implements the ditto Engine interface for PostgreSQL.

Jump to

Keyboard shortcuts

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