Skip to content

Commit

Permalink
Multiple statements per migration file
Browse files Browse the repository at this point in the history
Makes it possible to run several queries in each file.
  • Loading branch information
balboah committed Nov 17, 2014
1 parent d5f5eb6 commit 5f1ca5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion driver/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cassandra

import (
"net/url"
"strings"
"time"

"github.com/gocql/gocql"
Expand Down Expand Up @@ -120,7 +121,16 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
return
}

err = driver.session.Query(string(f.Content)).Exec()
for _, query := range strings.Split(string(f.Content), ";") {

This comment has been minimized.

Copy link
@mattes

mattes Nov 17, 2014

Using ; probably relates to this issue? Haven't found a better solution yet. What do you think?

This comment has been minimized.

Copy link
@balboah

balboah Nov 17, 2014

Author Owner

Yeah definitely not perfect but I don't see a big issue with it. Possibly it could split only if it's followed by line ending or something. I'd say don't spend too much time on magic split strings until it's a problem :)
Also seen some others doing this

This comment has been minimized.

Copy link
@mattes

mattes Nov 17, 2014

don't spend too much time on magic split strings until it's a problem

I agree. Not sure if others will run into this sooner or later. Maybe at some point there will be a convenient solution.

query = strings.TrimSpace(query)
if len(query) == 0 {
continue
}

if err = driver.session.Query(query).Exec(); err != nil {
return
}
}
}

func (driver *Driver) Version() (uint64, error) {
Expand Down
5 changes: 4 additions & 1 deletion driver/cassandra/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ func TestMigrate(t *testing.T) {
Direction: direction.Up,
Content: []byte(`
CREATE TABLE yolo (
id varint primary key
id varint primary key,
msg text
);
CREATE INDEX ON yolo (msg);
`),
},
{
Expand Down

0 comments on commit 5f1ca5d

Please sign in to comment.