clpgmigrate

package
v0.39.10 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package clpgmigrate implements the postgres migration logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GooseMigrated added in v0.29.1

func GooseMigrated(migrateDir fs.FS, cnff ...func(*Config)) fx.Option

GooseMigrated configures the di for using snapshot migrations.

func SetupTemplateDatabaseFromSnapshot added in v0.39.0

func SetupTemplateDatabaseFromSnapshot(
	ctx context.Context,
	bootstrapConnString,
	templateDatabaseName,
	snapshotPath string,
) error

SetupTemplateDatabaseFromSnapshot can be called early to setup a template database.

func SnapshotMigrated

func SnapshotMigrated(sqlFile string) fx.Option

SnapshotMigrated configures the di for using snapshot migrations.

func TeardownTemplateDatabase added in v0.39.0

func TeardownTemplateDatabase(
	ctx context.Context,
	bootstrapConnString,
	templateDatabaseName string,
) error

TeardownTemplateDatabase can called late in the test suite to drop the template database.

func TemplateMigrated added in v0.39.0

func TemplateMigrated(templDBName TemplateDatabaseName) fx.Option

TemplateMigrated configures the di for using template based migrations.

func VersionMigrated

func VersionMigrated(noChecksumValidate bool) fx.Option

VersionMigrated configures the di for testing with a temporary database and auto-migration of a directory.

Types

type Config

type Config struct {
	// TemporaryDatabase can be set to cause the logic to create a random database name and initialize
	// it when running auto-migration. This is mostly useful for automated tests
	TemporaryDatabase bool `env:"TEMPORARY_DATABASE" envDefault:"false"`
	// AutoMigration can be set to true to cause the logic to automatically run migrations when started. This
	// is mostly useful for automated tests.
	AutoMigration bool `env:"AUTO_MIGRATION" envDefault:"false"`
	// the sql being generated for creating the temporary database
	CreateDatabaseFormat string `env:"CREATE_DATABASE_FORMAT" envDefault:"CREATE DATABASE %s"`
	// the sql being generated for dropping the temporary database
	DropDatabaseFormat string `env:"DROP_DATABASE_FORMAT" envDefault:"DROP DATABASE %s (force)"`
	// configures how long migrations that run in the fx init phase
	InitMigrateTimeout time.Duration `env:"INIT_MIGRATE_TIMEOUT" envDefault:"10s"`
}

Config configures the packaged logic.

type GooseMigrateDir added in v0.29.1

type GooseMigrateDir struct{ fs.FS }

GooseMigrateDir types a filesytem that holds the full path to the goose migrations.

type GooseMigrater added in v0.29.1

type GooseMigrater struct {
	// contains filtered or unexported fields
}

GooseMigrater uses a goose strategy to migrate.

func NewGooseMigrater added in v0.29.1

func NewGooseMigrater(
	cfg Config,
	logs *zap.Logger,
	rwcfg *pgxpool.Config,
	rocfg *pgxpool.Config,
	dir GooseMigrateDir,
) (*GooseMigrater, error)

NewGooseMigrater inits the migrater.

func (GooseMigrater) Migrate added in v0.29.1

func (m GooseMigrater) Migrate(ctx context.Context) error

Migrate initializes the schema.

func (GooseMigrater) Reset added in v0.29.1

func (m GooseMigrater) Reset(ctx context.Context) error

Reset drops the schema.

type SnapshotMigrater

type SnapshotMigrater struct {
	// contains filtered or unexported fields
}

SnapshotMigrater uses a snapshot strategy to migrate.

func NewSnaphotMigrater

func NewSnaphotMigrater(
	cfg Config,
	logs *zap.Logger,
	rwcfg *pgxpool.Config,
	rocfg *pgxpool.Config,
	snapp SnapshotPath,
) (*SnapshotMigrater, error)

NewSnaphotMigrater inits the migrater.

func (SnapshotMigrater) Migrate

func (m SnapshotMigrater) Migrate(ctx context.Context) error

Migrate initializes the schema.

func (SnapshotMigrater) Reset

func (m SnapshotMigrater) Reset(ctx context.Context) error

Reset drops the schema.

type SnapshotPath

type SnapshotPath string

SnapshotPath types a string to hold the full snapshot sql.

type TemplateDatabaseName added in v0.39.0

type TemplateDatabaseName string

TemplateDatabaseName holds the name of a template database.

type TemplateMigrater added in v0.39.0

type TemplateMigrater struct {
	// contains filtered or unexported fields
}

TemplateMigrater uses a template database to migrate.

func NewTemplateMigrater added in v0.39.0

func NewTemplateMigrater(
	cfg Config,
	logs *zap.Logger,
	rwcfg *pgxpool.Config,
	tmpl TemplateDatabaseName,
) (mig *TemplateMigrater, err error)

NewTemplateMigrater inits the migrater.

func (TemplateMigrater) Migrate added in v0.39.0

func (m TemplateMigrater) Migrate(ctx context.Context) error

Migrate initializes the schema. This migrater does the migration in the init phase.

func (TemplateMigrater) Reset added in v0.39.0

func (m TemplateMigrater) Reset(ctx context.Context) error

Reset drops the schema.

type VersionMigrater

type VersionMigrater struct {
	// contains filtered or unexported fields
}

VersionMigrater allows programmatic migration of a database schema using versioned sql steps. Mostly used in testing and local development to provide fully isolated databases.

func NewVersionMigrater

func NewVersionMigrater(
	cfg Config,
	logs *zap.Logger,
	rwcfg *pgxpool.Config,
	rocfg *pgxpool.Config,
	dir migrate.Dir,
) (*VersionMigrater, error)

NewVersionMigrater inits the migrater.

func (VersionMigrater) Migrate

func (m VersionMigrater) Migrate(ctx context.Context) error

Migrate initializes the schema.

func (VersionMigrater) Reset

func (m VersionMigrater) Reset(ctx context.Context) error

Reset drops the migrated state.

Jump to

Keyboard shortcuts

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