migratetest

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopyScanner

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

CopyScanner will scan COPY statements, returning TableSnapshots.

func NewCopyScanner

func NewCopyScanner(r io.Reader) *CopyScanner

NewCopyScanner will return a new CopyScanner.

func (*CopyScanner) Err

func (d *CopyScanner) Err() error

func (*CopyScanner) Scan

func (d *CopyScanner) Scan() bool

Scan will scan the next COPY statement.

func (*CopyScanner) Table

func (d *CopyScanner) Table() TableSnapshot

type IgnoreRule

type IgnoreRule struct {
	// MigrationName is the name of the migration this rule applies to.
	MigrationName string
	TableName     string
	ColumnName    string

	// ExtraRows will ignore extra/leftover rows in the table when migrating down.
	ExtraRows bool

	// MissingRows will ignore missing rows in the table when migrating down (e.g., table was dropped).
	MissingRows bool
}

IgnoreRule is a rule to ignore differences in a snapshot.

type RuleSet

type RuleSet []IgnoreRule

RuleSet is a set of IgnoreRules.

func (RuleSet) RequireEqualDown

func (rs RuleSet) RequireEqualDown(t *testing.T, expected, actual *Snapshot)

RequireEqualDown will compare two snapshots and ignore any differences based on the rules in the RuleSet after a Down migration.

func (RuleSet) RequireEqualUp

func (rs RuleSet) RequireEqualUp(t *testing.T, expected, actual *Snapshot)

AssertEqualUp will compare two snapshots and ignore any differences based on the rules in the RuleSet after the second Up migration.

type Snapshot

type Snapshot struct {
	Schema    *pgdump.Schema
	TableData []TableSnapshot
}

Snapshot is a snapshot of a database's schema and data.

func NewSnapshot

func NewSnapshot(ctx context.Context, db *pgxpool.Pool) (*Snapshot, error)

NewSnapshot will create a new Snapshot from a database connection.

func NewSnapshotURL

func NewSnapshotURL(ctx context.Context, dbURL string) (*Snapshot, error)

NewSnapshotURL will create a new Snapshot from a database URL.

type TableSnapshot

type TableSnapshot struct {
	// Name is the name of the table.
	Name    string
	Columns []string
	Rows    [][]string
}

TableSnapshot is a snapshot of a table's data.

func (TableSnapshot) EntityName

func (t TableSnapshot) EntityName() string

func (*TableSnapshot) Sort

func (data *TableSnapshot) Sort()

Sort sorts the columns and rows of the snapshot.

Jump to

Keyboard shortcuts

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