internal

package
Version: v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MySQLDriver driver is represented under DB_DRIVER
	// for MySQL.
	MySQLDriver = "mysql"
	// PostgresDriver driver is represented under
	// DB_DRIVER for postgres.
	PostgresDriver = "postgres"
	// ErrDBConnectionMessage is used as an error message when
	// no database connection could be established.
	ErrDBConnectionMessage = "Error establishing database connection"
	// ErrTableNotFoundMessage is used as an error message
	// when a table is missing from the installation.
	ErrTableNotFoundMessage = "Verbis database tables missing"
)

Variables

View Source
var (
	// ErrCallBackMismatch is returned by AddMigration when
	// there has been a mismatch in the amount of callbacks
	// passed. Each migration should have two callbacks,
	// one up and one Down, or none at all.
	ErrCallBackMismatch = errors.New("both CallBackUp and CallBackDown must be set")
)
View Source
var (
	// ErrTableNotFound is returned by the driver if there are
	// tables missing from the installation.
	ErrTableNotFound = errors.New("database tables missing from verbis installation")
)
View Source
var (
	// Tables define the current database tables within
	// Verbis.
	Tables = []string{
		"categories",
		"form_fields",
		"form_submissions",
		"forms",
		"media",
		"options",
		"password_resets",
		"post_categories",
		"post_fields",
		"post_options",
		"posts",
		"redirects",
		"roles",
		"user_roles",
		"users",
	}
)

Functions

func AddMigration added in v0.0.3

func AddMigration(m *Migration) error

AddMigration adds a migration to the update registry which will be called when Update() is run. The version and Stage must be attached to the migration.

Types

type CallBackFn added in v0.0.3

type CallBackFn func() error

CallBackFn is the function type when migrations are running up or Down.

type Migration added in v0.0.3

type Migration struct {
	// The main version of the migration such as "v0.0.1"
	Version string
	// CallBackUp is a function called when the migration
	// is going up, this can be useful when manipulating
	// files and directories for the current version.
	CallBackUp CallBackFn
	// CallBackUp is a function called when the migration
	// is going Down, this is only called if an update
	// failed. And must be provided if CallBackUp is
	// defined.
	CallBackDown CallBackFn
	// Stage defines the release stage of the migration such as
	// Major, Minor or Patch,
	Stage version.Stage
	// The path of the MySQL file.
	SQLPath string
	// The path of the Postgres SQL file.
	PostgresPath string
	// Parsed SemVer of the Version
	SemVer *sm.Version
}

Migration represents a singular migration for a single version.

type MigrationRegistry added in v0.0.3

type MigrationRegistry []*Migration

MigrationRegistry contains a slice of pointers to each migration.

func (MigrationRegistry) Len added in v0.0.3

func (m MigrationRegistry) Len() int

func (MigrationRegistry) Less added in v0.0.3

func (m MigrationRegistry) Less(i, j int) bool

func (MigrationRegistry) Sort added in v0.0.3

func (m MigrationRegistry) Sort()

Sort MigrationRegistry is a type that implements the sort.Interface interface so that versions can be sorted.

func (MigrationRegistry) Swap added in v0.0.3

func (m MigrationRegistry) Swap(i, j int)

type Migrator added in v0.0.3

type Migrator interface {
	Migrate(version *sm.Version) error
}

Migrator is the core updater for Verbis, it takes in a version and migrates the migrations up to the major version. For example, if the current version is / 1.0.2, the migrator will run up to version 1.9.9 and no more, to allow for schema changes.

func NewMigrator added in v0.0.3

func NewMigrator(driver string, db *sqlx.DB) (Migrator, error)

NewMigrator creates a migrator for updating and installing Verbis. Returns an error on driver mismatch.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL