database

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package database defines the public API for Diverge database providers.

This package contains the interfaces and types that third-party and Pro/Enterprise providers implement to integrate with the Diverge controller. OSS implementations live in internal/database; Pro implementations live in the diverge-enterprise repository.

Implementing a custom provider

To implement a custom DatabaseProvider, implement the DatabaseProvider interface and register it using [RegisterProvider].

type MyProvider struct { /* config */ }

func (p *MyProvider) Provision(ctx context.Context, env *v1alpha1.Environment) (*database.DatabaseResult, error) {
    // Create database context for the preview
}

func (p *MyProvider) Teardown(ctx context.Context, env *v1alpha1.Environment) error {
    // Remove database context
}

func (p *MyProvider) Status(ctx context.Context, env *v1alpha1.Environment) (*database.DatabaseStatus, error) {
    // Report current state
}

Index

Constants

This section is empty.

Variables

View Source
var Providers = registry.New[DatabaseProvider]("database")

Providers is the registry of available DatabaseProvider implementations.

Functions

This section is empty.

Types

type DatabaseProvider

type DatabaseProvider interface {
	// Provision creates a database context for the preview environment.
	// It returns a DatabaseResult with connection details and any env vars
	// to inject into preview pods.
	Provision(ctx context.Context, env *v1alpha1.Environment) (*DatabaseResult, error)

	// Teardown removes the database context. Must be idempotent — calling
	// Teardown on an already-torn-down environment must not return an error.
	Teardown(ctx context.Context, env *v1alpha1.Environment) error

	// Status returns the current state of the database context.
	Status(ctx context.Context, env *v1alpha1.Environment) (*DatabaseStatus, error)
}

DatabaseProvider provisions and tears down database contexts for preview environments. Implementations range from simple (noop, schema isolation) to complex (Neon branching, CloudNativePG instances).

All methods must be safe for concurrent use.

type DatabaseResult

type DatabaseResult struct {
	// DSN is the connection string for the preview database.
	DSN string

	// EnvVars are environment variables to inject into preview pods.
	// Typically includes DATABASE_URL and schema-specific vars.
	EnvVars map[string]string

	// SetupSQL is SQL to run to initialize the database context.
	// The controller executes this against the admin DSN after Provision
	// returns. May be empty if the provider handles setup internally.
	SetupSQL string

	// SetupSQLExecuted reports whether SetupSQL was already executed in-process
	// by the provider. If true, external runners (such as K8s Jobs) can be skipped.
	SetupSQLExecuted bool

	// AdminDSN is the connection string for the admin role, used to execute SetupSQL.
	AdminDSN string

	// Ready reports that the provider finished its own work. It does not
	// guarantee that SetupSQL has been executed; callers must run SetupSQL
	// separately if non-empty and SetupSQLExecuted is false.
	Ready bool

	// Message is a human-readable status message for logging and MR comments.
	Message string
}

DatabaseResult is the outcome of a Provision call.

type DatabaseStatus

type DatabaseStatus struct {
	// Provisioned indicates whether the database context exists.
	Provisioned bool

	// SchemaName is the name of the database schema (for schema-based isolation).
	SchemaName string

	// Message is a human-readable status message.
	Message string
}

DatabaseStatus is the observed state of a preview database context.

Jump to

Keyboard shortcuts

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