-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migrations) allow up_f field in Cassandra migrations
The initial assumption behind only allowing strings of SQL and CQL on the "up" side of migrations was that the operations on this phase needed to be safe, fast and reentrant. Unfortunately CQL is much more limited than Pg's SQL. So what's trivial to do in Pg is impossible to do in Cassandra. So we arrive to a point where trivial and safe operations get delayed to the `teardown` phase, simply because they need a more complete language than CQL to be done. This change adds a new `up_f` method to which accepts a Lua function with a connector, effectively allowing the use of Lua inside Cassandra migrations' "up" phase. While adding the same features in Postgres would not be difficult, we think that SQL is powerful enough to do most "safe" things we need (perhaps with some trivial string replacement from Lua). A migration can have both up and up_f. In that case, the up string is run first, and up_f immediately afterwards. Incidentally we have also changed the validations on the migrations schema so that `up` isn't always required. This validation has forced us to set it to "" (empty string) in the past, which is not ideal.
- Loading branch information
Showing
5 changed files
with
140 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,33 @@ | ||
local strat_migration = { | ||
{ up = { type = "string", required = true, len_min = 0 } }, | ||
{ teardown = { type = "function" } }, | ||
} | ||
|
||
|
||
return { | ||
name = "migration", | ||
fields = { | ||
{ name = { type = "string", required = true } }, | ||
{ postgres = { type = "record", required = true, fields = strat_migration } }, | ||
{ cassandra = { type = "record", required = true, fields = strat_migration } }, | ||
{ | ||
postgres = { | ||
type = "record", required = true, | ||
fields = { | ||
{ up = { type = "string", len_min = 0 } }, | ||
{ teardown = { type = "function" } }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
cassandra = { | ||
type = "record", required = true, | ||
fields = { | ||
{ up = { type = "string", len_min = 0 } }, | ||
{ up_f = { type = "function" } }, | ||
{ teardown = { type = "function" } }, | ||
}, | ||
} | ||
}, | ||
}, | ||
entity_checks = { | ||
{ | ||
at_least_one_of = { | ||
"postgres.up", "postgres.teardown", | ||
"cassandra.up", "cassandra.up_f", "cassandra.teardown" | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters