-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 AWS Keyspaces #579
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,10 @@ func (c *Cassandra) Open(url string) (database.Driver, error) { | |
} | ||
} | ||
|
||
if s := u.Query().Get("disable-host-lookup"); len(s) > 0 { | ||
cluster.DisableInitialHostLookup = true | ||
} | ||
|
||
session, err := cluster.CreateSession() | ||
if err != nil { | ||
return nil, err | ||
|
@@ -226,16 +230,24 @@ func (c *Cassandra) Run(migration io.Reader) error { | |
} | ||
|
||
func (c *Cassandra) SetVersion(version int, dirty bool) error { | ||
query := `TRUNCATE "` + c.config.MigrationsTable + `"` | ||
if err := c.session.Query(query).Exec(); err != nil { | ||
return &database.Error{OrigErr: err, Query: []byte(query)} | ||
if previous, _, err := c.Version(); err == nil { | ||
if previous != database.NilVersion { | ||
// DELETE instead of TRUNCATE because AWS Keyspaces does not support it | ||
// see: https://docs.aws.amazon.com/keyspaces/latest/devguide/cassandra-apis.html | ||
query := `DELETE FROM "` + c.config.MigrationsTable + `" WHERE version = ?` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only removes the previous version and not all versions. Having multiple versions will cause issues since selecting the current versions only selects one version without any ordering. We can either:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this causing the tests to fail. You can test locally by running |
||
if err := c.session.Query(query, previous).Exec(); err != nil { | ||
return &database.Error{OrigErr: err, Query: []byte(query)} | ||
} | ||
} | ||
} else { | ||
return err | ||
} | ||
|
||
// Also re-write the schema version for nil dirty versions to prevent | ||
// empty schema version for failed down migration on the first migration | ||
// See: https://github.com/golang-migrate/migrate/issues/330 | ||
if version >= 0 || (version == database.NilVersion && dirty) { | ||
query = `INSERT INTO "` + c.config.MigrationsTable + `" (version, dirty) VALUES (?, ?)` | ||
query := `INSERT INTO "` + c.config.MigrationsTable + `" (version, dirty) VALUES (?, ?)` | ||
if err := c.session.Query(query, version, dirty).Exec(); err != nil { | ||
return &database.Error{OrigErr: err, Query: []byte(query)} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ParseBool and handle the error properly