Documentation
¶
Index ¶
Constants ¶
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 ¶
type ContextualCloser ¶ added in v0.6.0
type CreateConnPoolForDbFn ¶ added in v0.8.0
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 ExcludeMetadataOptions []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, createConnPoolForDb CreateConnPoolForDbFn, opts ...OnInstanceFactoryOpt) (_ Factory, _retErr error)
NewOnInstanceFactory provides an implementation to easily create temporary databases on the Postgres instance connected to via CreateConnPoolForDbFn. 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 CreateConnPoolForDbFn. 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