Skip to content

Commit

Permalink
Support for multiple statements in Cassandra cql migration files base…
Browse files Browse the repository at this point in the history
…d on semi-colon and newline.
  • Loading branch information
aggrhm committed Jul 17, 2018
1 parent 6bb3e49 commit c4b81d1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions database/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,17 @@ func (c *Cassandra) Run(migration io.Reader) error {
}
// run migration
query := string(migr[:])
if err := c.session.Query(query).Exec(); err != nil {
// TODO: cast to Cassandra error and get line number
return database.Error{OrigErr: err, Err: "migration failed", Query: migr}

// split query by semi-colon
queries := strings.Split(query, ";\n")

for _, q := range(queries) {
tq := strings.TrimSpace(q)
if (tq == "") { continue }
if err := c.session.Query(tq).Exec(); err != nil {
// TODO: cast to Cassandra error and get line number
return database.Error{OrigErr: err, Err: "migration failed", Query: migr}
}
}

return nil
Expand Down

0 comments on commit c4b81d1

Please sign in to comment.