migrate: Add example

This commit is contained in:
Michał Matczuk
2020-12-03 12:52:48 +01:00
committed by Michal Jan Matczuk
parent 9dd79fc620
commit 1b6e643584
6 changed files with 118 additions and 64 deletions

View File

@@ -1,35 +1,8 @@
# GoCQLX Migrations
# 🚀 GocqlX Migrations
Package `migrate` provides simple and flexible CQL migrations.
Migrations can be read from a flat directory containing cql files.
There is no imposed naming schema, migration name is file name and the migrations are processed in lexicographical order.
Caller provides a `gocqlx.Session`, the session must use a desired keyspace as migrate would try to create migrations table.
`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.
## Features
* Each CQL statement will run once
* Go code migrations using callbacks
## Example
```go
package main
import (
"context"
"github.com/scylladb/gocqlx/v2/migrate"
)
const dir = "./cql"
func main() {
session := CreateSession()
defer session.Close()
ctx := context.Background()
if err := migrate.Migrate(ctx, session, dir); err != nil {
panic(err)
}
}
```
For details see [example](example) migration.