hsgubert/cassandra_migrations — pull request #35 by svoynow-lz (2014-05-22 18:06:28+00:00)
Title: add a using_keyspace method to migrations that takes a block

https://github.com/hsgubert/cassandra_migrations/issues/34

I've kept it really simple. There's now a using_keyspace method exposed to migrations that takes a block, like so:

```ruby
class WithAlternateKeyspaceMigration < CassandraMigrations::Migration
def up
using_keyspace('alternative') do
create_table :collection_lists, options: {compact_storage: true} do |t|
t.uuid :id, :primary_key => true
t.decimal :a_decimal
end
end
end
end
```

So the overall workflow would be to:
- define all of your keyspaces/environment combinations as separate environments in `cassandra.yml`. You probably want to keep your main or default keyspace as just plain `development` or 'production`, especially if you're using the queries stuff (I'm not), so as to confuse Rails as little as possible.
- make sure to run `rake cassandra:create` for all of them
- but if you use `using_keyspace` in all your migrations for keyspaces defined in enviroments other than the standard Rails ones, you won't have to run them for each 'special' environment.

As a side note, It seems to me that if you're going to be using multiple keyspaces in one application (especially with cql-rb), you probably want to just fully qualify your table names in your queries rather than having to call `USE ' all over the place. Especially since cql-rb encourages you to only have on client object per application.