deltas

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DeltaTableName for use in queries
	DeltaTableName = "delta"
	// LockName for preventing multiple executions of the sql delta's at the same time
	LockName = "delta_exec"

	// CreateDeltaTableSQL creates the delta's table in the database for use by
	// this package.
	CreateDeltaTableSQL = `CREATE TABLE ` + "`" + DeltaTableName + "`" + ` (
		` + "`id`" + ` int NOT NULL,
		` + "`name`" + ` varchar(120) NOT NULL,
		` + "`created`" + ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
		` + "`modified`" + ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		PRIMARY KEY (` + "`id`" + `)
		) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`
)

Variables

View Source
var DeltaMeta = (&deltaMeta{}).Alias("delta")

DeltaMeta is a meta representation of the database delta table for building ad hoc queries

Functions

func Execute

func Execute(config database.InstanceConfig, schema string, deltas []*Delta) errors.TracerError

Execute the passed deltas sequentially if they have not already been applied to the database. WARN: This function will create the table 'delta' which is needs to track changes if it does not

already exist.

NOTE: This function assumes that the database has fully transactional DDL

(not MySQL). Using this function with a non-transactional DDL database
will cause errors to leave the database in an indeterminate state.

func ExecuteDelta

func ExecuteDelta(tx lockingDatabaseTx, db lockingDatabase, delta *Delta) errors.TracerError

ExecuteDelta checks if the passed delta has already been executed according to the Deltas table, and then executes if it has not been using the passed transaction for both queries.

Types

type Delta

type Delta struct {
	ID     int
	Name   string
	Script string
}

Delta represents a set of changes that are to be applied to the database as an atomic unit

type DeltaRecord

type DeltaRecord struct {
	database.DefaultRecord
	ID       int       `db:"id"`
	Name     string    `db:"name"`
	Created  time.Time `db:"created,read_only"`
	Modified time.Time `db:"modified,read_only"`
}

DeltaRecord is the database representation of delta script and indicates that it has been executed on the database.

func (*DeltaRecord) Initialize

func (dbm *DeltaRecord) Initialize()

Initialize the delta record with an id

func (*DeltaRecord) Key

func (dbm *DeltaRecord) Key() string

Key field name

func (*DeltaRecord) Meta

func (dbm *DeltaRecord) Meta() qb.Table

Meta object for this record

func (*DeltaRecord) PrimaryKey

func (dbm *DeltaRecord) PrimaryKey() database.PrimaryKeyValue

PrimaryKey of this record

Jump to

Keyboard shortcuts

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