2018-05-25 08:02:16 +02:00
|
|
|
# GoCQLX Migrations
|
|
|
|
|
|
|
|
|
|
Package `migrate` provides simple and flexible CQL migrations.
|
|
|
|
|
Migrations can be read from a flat directory containing cql files.
|
2020-12-02 13:18:49 +01:00
|
|
|
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.
|
2018-05-25 08:02:16 +02:00
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
|
|
|
|
* Each CQL statement will run once
|
2020-12-02 13:18:49 +01:00
|
|
|
* Go code migrations using callbacks
|
2018-05-25 08:02:16 +02:00
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2020-12-02 13:18:49 +01:00
|
|
|
"github.com/scylladb/gocqlx/v2/migrate"
|
2018-05-25 08:02:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const dir = "./cql"
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
session := CreateSession()
|
|
|
|
|
defer session.Close()
|
|
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
if err := migrate.Migrate(ctx, session, dir); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|