tempdb

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultOnInstanceDbPrefix       = "pgschemadifftmp_"
	DefaultOnInstanceMetadataSchema = "pgschemadifftmp_metadata"
	DefaultOnInstanceMetadataTable  = "metadata"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateConnForDbFn

type CreateConnForDbFn func(ctx context.Context, dbName string) (*sql.DB, error)

type Dropper

type Dropper func(ctx context.Context) error

Factory is used to create temp databases These databases do not have to be in-memory. They might be, for example, be created on the target Postgres server

type Factory

type Factory interface {
	// Create creates a temporary database. Be sure to always call the Dropper to ensure the database and
	// connections are cleaned up
	Create(ctx context.Context) (db *sql.DB, dropper Dropper, err error)

	io.Closer
}

Factory is used to create temp databases These databases do not have to be in-memory. They might be, for example, be created on the target Postgres server

func NewOnInstanceFactory

func NewOnInstanceFactory(ctx context.Context, createConnForDb CreateConnForDbFn, opts ...OnInstanceFactoryOpt) (Factory, error)

NewOnInstanceFactory provides an implementation to easily create temporary databases on the Postgres instance connected to via CreateConnForDbFn. The Postgres instance is connected to via the "postgres" database, and then temporary databases are created using that connection. These temporary databases are also connected to via the CreateConnForDbFn. Make sure to always call Close() on the returned Factory to ensure the root connection is closed

WARNING: It is possible this will lead to orphaned temporary databases. These orphaned databases should be pretty small if they're only being used by the pg-schema-diff library, but it's recommended to clean them up when possible. This can be done by deleting all old databases with the provided temp db prefix. The metadata table can be inspected to find when the temporary database was created, e.g., to create a TTL

type OnInstanceFactoryOpt

type OnInstanceFactoryOpt func(*onInstanceFactoryOptions)

func WithDbPrefix

func WithDbPrefix(prefix string) OnInstanceFactoryOpt

WithDbPrefix sets the prefix for the temp database name

func WithLogger

func WithLogger(logger log.Logger) OnInstanceFactoryOpt

WithLogger sets the logger for the factory. If not set, a SimpleLogger will be used

func WithMetadataSchema

func WithMetadataSchema(schema string) OnInstanceFactoryOpt

WithMetadataSchema sets the prefix for the schema name containing the metadata

func WithMetadataTable

func WithMetadataTable(table string) OnInstanceFactoryOpt

WithMetadataTable sets the metadata table name

Jump to

Keyboard shortcuts

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