Movatterモバイル変換


[0]ホーム

URL:


tempdb

package
v0.9.0Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License:MITImports:13Imported by:2

Details

Repository

github.com/stripe/pg-schema-diff

Links

Documentation

Index

Constants

View Source
const (DefaultOnInstanceDbPrefix       = "pgschemadiff_tmp_"DefaultOnInstanceMetadataSchema = "pgschemadiff_tmp_metadata"DefaultOnInstanceMetadataTable  = "metadata"DefaultStatementTimeout = 3 *time.Second)

Variables

This section is empty.

Functions

This section is empty.

Types

typeContextualCloseradded inv0.6.0

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

typeCreateConnPoolForDbFnadded inv0.8.0

type CreateConnPoolForDbFn func(ctxcontext.Context, dbNamestring) (*sql.DB,error)

typeDatabaseadded inv0.6.0

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

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

typeFactory

type Factory interface {// Create creates a temporary database. Be sure to always call the ContextualCloser to ensure the database and// connections are cleaned upCreate(ctxcontext.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

funcNewOnInstanceFactory

func NewOnInstanceFactory(ctxcontext.Context, createConnPoolForDbCreateConnPoolForDbFn, opts ...OnInstanceFactoryOpt) (_Factory, _retErrerror)

NewOnInstanceFactory provides an implementation to easily create temporary databases on the Postgres instanceconnected to via CreateConnPoolForDbFn. The Postgres instance is connected to via the "postgres" database, and thentemporary databases are created using that connection. These temporary databases are also connected to via theCreateConnPoolForDbFn.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 ifthey're only being used by the pg-schema-diff library, but it's recommended to clean them up when possible. This canbe done by deleting all old databases with the provided temp db prefix. The metadata table can be inspected to findwhen the temporary database was created, e.g., to create a TTL

typeOnInstanceFactoryOpt

type OnInstanceFactoryOpt func(*onInstanceFactoryOptions)

funcWithDbPrefix

func WithDbPrefix(prefixstring)OnInstanceFactoryOpt

WithDbPrefix sets the prefix for the temp database name

funcWithLogger

func WithLogger(loggerlog.Logger)OnInstanceFactoryOpt

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

funcWithMetadataSchema

func WithMetadataSchema(schemastring)OnInstanceFactoryOpt

WithMetadataSchema sets the prefix for the schema name containing the metadata

funcWithMetadataTable

func WithMetadataTable(tablestring)OnInstanceFactoryOpt

WithMetadataTable sets the metadata table name

funcWithRootDatabaseadded inv0.5.0

func WithRootDatabase(dbstring)OnInstanceFactoryOpt

WithRootDatabase sets the database to connect to when creating temporary databases

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp