darwinx

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 11 Imported by: 0

README

darwinx

Postgres schema evolution library for Go with pgx
Based on https://github.com/GuiaBolso/darwin

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Darwinx

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

Darwinx is a helper struct to access the Validate and migration functions

func New

func New(pool *pgxpool.Pool, options ...Option) (*Darwinx, error)

New returns a new Darwinx struct

func (*Darwinx) Info

func (d *Darwinx) Info(ctx context.Context) ([]MigrationInfo, error)

Info returns the status of all migrations

func (*Darwinx) Migrate

func (d *Darwinx) Migrate(ctx context.Context) error

Migrate executes the missing migrations in database Apply all Migration or rollback

func (*Darwinx) Validate

func (d *Darwinx) Validate(ctx context.Context) error

Validate if the database migrations are applied and consistent

type DuplicateMigrationVersionError

type DuplicateMigrationVersionError struct {
	Version float64
}

DuplicateMigrationVersionError is used to report when the migration list has duplicated entries

func (DuplicateMigrationVersionError) Error

type IllegalMigrationVersionError

type IllegalMigrationVersionError struct {
	Version float64
}

IllegalMigrationVersionError is used to report when the migration has an illegal Version number

func (IllegalMigrationVersionError) Error

type InvalidChecksumError

type InvalidChecksumError struct {
	Version float64
}

InvalidChecksumError is used to report when a migration was modified

func (InvalidChecksumError) Error

func (i InvalidChecksumError) Error() string

type Migration

type Migration struct {
	Version     float64
	Description string
	Script      string
}

Migration represents a database migrations.

func MigrationsFromString

func MigrationsFromString(content string) (migrations []Migration, err error)

func (Migration) Checksum

func (m Migration) Checksum() string

Checksum calculate the Script sha256

type MigrationInfo

type MigrationInfo struct {
	Status    Status
	Error     error
	Migration Migration
}

MigrationInfo is a struct used in the infoChan to inform clients about the migration being applied.

type MigrationRecord

type MigrationRecord struct {
	Version       float64
	Description   string
	Checksum      string
	AppliedAt     time.Time
	ExecutionTime time.Duration
}

MigrationRecord is the entry in schema table

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithMigration

func WithMigration(migrations []Migration) Option

func WithTableName

func WithTableName(tn string) Option

type RemovedMigrationsError

type RemovedMigrationsError struct {
	Versions []float64
}

RemovedMigrationError is used to report when a migration is removed from the list

func (RemovedMigrationsError) Error

func (r RemovedMigrationsError) Error() string

type Status

type Status uint8

Status is a migration status value

const (
	// Ignored means that the migrations was not applied to the database
	Ignored Status = iota
	// Applied means that the migrations was successfully applied to the database
	Applied
	// Pending means that the migrations is a new migration and it is waiting to be applied to the database
	Pending
	// Error means that the migration could not be applied to the database
	Error
)

func (Status) String

func (s Status) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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