tempdb

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultOnInstanceDbPrefix       = "pgschemadiff_tmp_"
	DefaultOnInstanceMetadataSchema = "pgschemadiff_tmp_metadata"
	DefaultOnInstanceMetadataTable  = "metadata"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextualCloser added in v0.6.0

type ContextualCloser interface {
	Close(context.Context) error
}

type CreateConnForDbFn

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

type Database added in v0.6.0

type Database struct {
	// ConnPool is the connection pool to the temporary database
	ConnPool *sql.DB
	// ExcludeMetadataOptions are the options used to exclude any internal metadata from plan generation
	ExcludeMetadatOptions []schema.GetSchemaOpt
	// ContextualCloser should be called to clean up the temporary database
	ContextualCloser
}

Database represents a temporary database. It should be closed when it is no longer needed.

type Factory

type Factory interface {
	// Create creates a temporary database. Be sure to always call the ContextualCloser to ensure the database and
	// connections are cleaned up
	Create(ctx context.Context) (*Database, 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

func WithRootDatabase added in v0.5.0

func WithRootDatabase(db string) OnInstanceFactoryOpt

WithRootDatabase sets the database to connect to when creating temporary databases

Jump to

Keyboard shortcuts

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