Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple statements in Cassandra cql migration files #76

Merged
merged 3 commits into from
Jul 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't split on \n so we don't need to deal with different line endings


for _, q := range(queries) {
tq := strings.TrimSpace(q)
if (tq == "") { continue }
if err := c.session.Query(tq).Exec(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be better off using Batch since atomicity is guaranteed. But I'm still not sure about parsing the migration data.

// TODO: cast to Cassandra error and get line number
return database.Error{OrigErr: err, Err: "migration failed", Query: migr}
}
}

return nil
Expand Down