@@ -59,11 +59,23 @@ func (p *Cassandra) Open(url string) (database.Driver, error) {
59
59
MigrationsTable : migrationsTable ,
60
60
}
61
61
62
+ username := u .User .Username ()
63
+ if len (username ) == 0 {
64
+ username = "cassandra"
65
+ }
66
+ password , _ := u .User .Password ()
67
+ if len (password ) == 0 {
68
+ password = "cassandra"
69
+ }
70
+
62
71
cluster := gocql .NewCluster (u .Host )
63
72
cluster .Keyspace = u .Path [1 :len (u .Path )]
64
73
cluster .Consistency = gocql .All
65
74
cluster .Timeout = 1 * time .Minute
66
-
75
+ cluster .Authenticator = gocql.PasswordAuthenticator {
76
+ Username : username ,
77
+ Password : password ,
78
+ }
67
79
68
80
// Retrieve query string configuration
69
81
if len (u .Query ().Get ("consistency" )) > 0 {
@@ -130,9 +142,17 @@ func (p *Cassandra) Run(migration io.Reader) error {
130
142
}
131
143
// run migration
132
144
query := string (migr [:])
133
- if err := p .session .Query (query ).Exec (); err != nil {
134
- // TODO: cast to Cassandra error and get line number
135
- return database.Error {OrigErr : err , Err : "migration failed" , Query : migr }
145
+ matches := regexp .MustCompile (`(?m:;$)` ).Split (query , - 1 )
146
+ for _ , match := range matches {
147
+ trimmedMatch := strings .Trim (match , " \t \r \n " )
148
+ if len (trimmedMatch ) == 0 {
149
+ continue
150
+ }
151
+
152
+ if err := p .session .Query (trimmedMatch ).Exec (); err != nil {
153
+ // TODO: cast to Cassandra error and get line number
154
+ return database.Error {OrigErr : err , Err : "migration failed" , Query : migr }
155
+ }
136
156
}
137
157
138
158
return nil
0 commit comments