pgmgr

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 14 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DOWN = iota
	UP
)

Migration directions

View Source
const (
	MIGRATION = "migration"
	ROLLBACK  = "rollback"
)

Migration directions used for error message building

Variables

This section is empty.

Functions

func Create

func Create(c *Config) error

Create creates the database specified by the configuration.

func CreateMigration

func CreateMigration(c *Config, name string, noTransaction bool) error

CreateMigration generates new, empty migration files.

func Drop

func Drop(c *Config) error

Drop drops the database specified by the configuration.

func Dump

func Dump(c *Config) error

Dump dumps the schema and contents of the database to the dump file.

func Initialize

func Initialize(c *Config) error

Initialize creates the schema_migrations table if necessary.

func Load

func Load(c *Config) error

Load loads the database from the dump file using psql.

func LoadConfig

func LoadConfig(config *Config, ctx argumentContext) error

LoadConfig reads the config file, applies CLI arguments as overrides, and returns an error if the configuration is invalid.

func Migrate

func Migrate(c *Config) error

Migrate applies un-applied migrations in the specified MigrationFolder.

func Rollback

func Rollback(c *Config) error

Rollback un-applies the latest migration, if possible.

func SQLConnectionString added in v1.0.1

func SQLConnectionString(c *Config) string

SQLConnectionString formats the values pulled from the config into a connection string

func Version

func Version(c *Config) (int64, error)

Version returns the highest version number stored in the database. This is not necessarily enough info to uniquely identify the version, since there may be backdated migrations which have not yet applied.

Types

type Config

type Config struct {
	// connection
	Username string
	Password string
	Database string
	Host     string
	Port     int
	URL      string
	SslMode  string

	// dump
	DumpConfig DumpConfig `json:"dump-options"`

	// filepaths
	MigrationFolder string `json:"migration-folder"`

	// options
	MigrationTable  string `json:"migration-table"`
	MigrationDriver string `json:"migration-driver"`
	ColumnType      string `json:"column-type"`
	Format          string

	// deprecated -- see dump_config.go
	DumpFile   string   `json:"dump-file"`
	SeedTables []string `json:"seed-tables"`
}

Config stores the options used by pgmgr.

func (*Config) DumpToEnv

func (config *Config) DumpToEnv() error

DumpToEnv applies all applicable keys as PG environment variables, so that shell commands will work on the correct target.

type DumpConfig added in v1.1.0

type DumpConfig struct {
	// exclusions
	ExcludeSchemas []string `json:"exclude-schemas"`

	// inclusions
	IncludeTables     []string `json:"seed-tables"`
	IncludePrivileges bool     `json:"include-privileges"`
	IncludeTriggers   bool     `json:"include-triggers"`

	// options
	NoCompress bool   `json:"no-compress"`
	DumpFile   string `json:"dump-file"`
}

DumpConfig stores the options used by pgmgr's dump tool and defers connection-type options to the main config file

func (DumpConfig) GetDumpFile added in v1.1.0

func (config DumpConfig) GetDumpFile() string

GetDumpFile returns the true dump file name with or without the specified compression suffix

func (DumpConfig) GetDumpFileRaw added in v1.1.0

func (config DumpConfig) GetDumpFileRaw() string

GetDumpFileRaw returns the literal dump file name as configured

func (DumpConfig) IsCompressed added in v1.1.1

func (config DumpConfig) IsCompressed() bool

IsCompressed returns whether compression is set

type Migration

type Migration struct {
	Filename string
	Version  int64
}

Migration stores a single migration's version and filename.

func (Migration) WrapInTransaction

func (m Migration) WrapInTransaction() bool

WrapInTransaction returns whether the migration should be run within a transaction.

Jump to

Keyboard shortcuts

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