Documentation ¶
Index ¶
Constants ¶
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 ¶
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 ¶
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 ¶
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) PrimaryKey ¶
func (dbm *DeltaRecord) PrimaryKey() database.PrimaryKeyValue
PrimaryKey of this record