schema

package
v0.0.0-...-23dbee4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeSet

type ChangeSet struct {
	Current, Post int
}

ChangeSet returns the schema changes for the schema when they're applied.

type Hook

type Hook func(int, string) error

Hook is a callback that gets fired when a update gets applied.

type Patch

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

Patch applies a specific schema change to a database, and returns an error if anything goes wrong.

func MakePatch

func MakePatch(statement string, args ...any) Patch

MakePatch returns a patch that applies the given SQL statement with the given arguments.

type Schema

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

Schema captures the schema of a database in terms of a series of ordered updates.

func New

func New(patches ...Patch) *Schema

New creates a new schema Schema with the given patches.

func (*Schema) Add

func (s *Schema) Add(patches ...Patch)

Add a new update to the schema. It will be appended at the end of the existing series.

func (*Schema) Ensure

func (s *Schema) Ensure(ctx context.Context, runner database.TxnRunner) (ChangeSet, error)

Ensure makes sure that the actual schema in the given database matches the one defined by our updates.

All updates are applied transactionally. In case any error occurs the transaction will be rolled back and the database will remain unchanged.

A update will be applied only if it hasn't been current (currently applied updates are tracked in the a 'schema' table, which gets automatically created).

If no error occurs, the integer returned by this method is the initial version that the schema has been upgraded from.

func (*Schema) Hook

func (s *Schema) Hook(hook Hook)

Hook instructs the schema to invoke the given function whenever a update is about to be applied. The function gets passed the update version number and the running transaction, and if it returns an error it will cause the schema transaction to be rolled back. Any previously installed hook will be replaced.

func (*Schema) Len

func (s *Schema) Len() int

Len returns the number of total patches in the schema.

type Tx

type Tx interface {
	ExecContext(context.Context, string, ...any) (sql.Result, error)
}

Tx describes the ability to execute a SQL statement within a transaction.

Jump to

Keyboard shortcuts

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