engine

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 1, 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 ConnectionConfig added in v0.2.0

type ConnectionConfig struct {
	Host       string
	Port       int
	Database   string
	User       string
	Password   string
	TLSEnabled bool
}

ConnectionConfig describes how callers connect to a running copy.

type ContainerSpec added in v0.2.0

type ContainerSpec struct {
	Env []string
	Cmd []string
}

ContainerSpec captures the engine-specific environment variables and command line needed to bootstrap a container.

type CopyBootstrap added in v0.2.0

type CopyBootstrap struct {
	Database     string
	User         string
	Password     string
	RootPassword string
	TLSEnabled   bool
}

CopyBootstrap describes the database users and TLS settings used to initialize a copy or staging container.

func DefaultLocalBootstrap added in v0.3.1

func DefaultLocalBootstrap() CopyBootstrap

DefaultLocalBootstrap returns the standard credentials used for ephemeral copy and staging containers. All callers use these same fixed values.

type DumpFromContainerRequest added in v0.3.2

type DumpFromContainerRequest struct {
	Docker        *client.Client
	ContainerName string
	DestPath      string
	Copy          CopyBootstrap
	Options       DumpOptions
}

DumpFromContainerRequest contains all inputs needed to dump a database that is already running inside a managed container.

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 DumpRequest added in v0.3.2

type DumpRequest struct {
	Docker      *client.Client
	ClientImage string
	Source      SourceConfig
	DestPath    string
	Options     DumpOptions
}

DumpRequest contains all inputs needed to create a dump from a source database through a Docker-compatible runtime.

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, req DumpRequest) 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, req DumpFromContainerRequest) error

	// ContainerSpec returns the environment variables and optional command line
	// used to initialize the database inside a copy or staging container.
	ContainerSpec(copy CopyBootstrap) ContainerSpec

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

	// ContainerPort returns the TCP port the database listens on inside the container.
	ContainerPort() int

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

	// ConnectionString returns a DSN for connecting to the copy on port.
	ConnectionString(conn ConnectionConfig) string

	// 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.
	Restore(ctx context.Context, req RestoreRequest) error
}

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 RestoreRequest added in v0.3.2

type RestoreRequest struct {
	Docker        *client.Client
	DumpPath      string
	ContainerName string
	Copy          CopyBootstrap
}

RestoreRequest contains all inputs needed to restore a dump into a running managed container.

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
internal
engineutil
Package engineutil contains shared helpers for database engine implementations.
Package engineutil contains shared helpers for database engine implementations.
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