Documentation ¶
Overview ¶
Package migrate reads migrations from a flat directory containing CQL files. There is no imposed naming schema. Migration name is file name. The order of migrations is the lexicographical order of file names in the directory. You can inject execution of Go code before processing of a migration file, after processing of a migration file, or between statements in a migration file.
Index ¶
Constants ¶
const ( AwaitSchemaAgreementDisabled awaitSchemaAgreement = iota AwaitSchemaAgreementBeforeEachFile AwaitSchemaAgreementBeforeEachStatement )
Options for checking schema agreement.
Variables ¶
var DefaultAwaitSchemaAgreement = AwaitSchemaAgreementDisabled
DefaultAwaitSchemaAgreement controls whether checking for cluster schema agreement is disabled or if it is checked before each file or statement is applied. The default is not checking before each file or statement but only once after every migration has been run.
Functions ¶
func FromFS ¶ added in v2.4.0
FromFS executes new CQL files from a file system abstraction (io/fs.FS). The provided FS has to be a flat directory containing *.cql files.
It supports code based migrations, see Callback and CallbackFunc. Any comment in form `-- CALL <name>;` will trigger an CallComment callback.
Types ¶
type CallbackEvent ¶
type CallbackEvent uint8
CallbackEvent specifies type of the event when calling CallbackFunc.
const ( BeforeMigration CallbackEvent = iota AfterMigration CallComment )
enumeration of CallbackEvents
type CallbackFunc ¶
type CallbackFunc func(ctx context.Context, session gocqlx.Session, ev CallbackEvent, name string) error
CallbackFunc enables execution of arbitrary Go code during migration. If error is returned the migration is aborted. BeforeMigration and AfterMigration are triggered before and after processing of each migration file respectively. CallComment is triggered for each comment in a form `-- CALL <name>;` (note the semicolon).
var Callback CallbackFunc
Callback is means of executing Go code during migrations. Use this variable to register a global callback dispatching function. See CallbackFunc for details.
type CallbackRegister ¶ added in v2.3.0
type CallbackRegister map[nameEvent]CallbackFunc
CallbackRegister allows to register a handlers for an event type and a name. It dispatches calls to the registered handlers. If there is no handler registered for CallComment an error is returned.
func (CallbackRegister) Add ¶ added in v2.3.0
func (r CallbackRegister) Add(ev CallbackEvent, name string, f CallbackFunc)
Add registers a callback handler.
func (CallbackRegister) Callback ¶ added in v2.3.0
func (r CallbackRegister) Callback(ctx context.Context, session gocqlx.Session, ev CallbackEvent, name string) error
Callback is CallbackFunc.
func (CallbackRegister) Find ¶ added in v2.7.0
func (r CallbackRegister) Find(ev CallbackEvent, name string) CallbackFunc
Find returns the registered handler.