Skip to content
Evan Prothro edited this page Nov 19, 2015 · 12 revisions

Additional Table Options

The create_table method allow do pass a hash of options for:

  • Clustering Order (clustering_order): A string such as 'a_decimal DESC'
  • Compact Storage (compact_storage): Boolean, true or false
  • Wait before GC (gc_grace_seconds): Default: 864000 [10 days]
  • Others: See CQL Table Properties

Cassandra Migration will attempt to pass through the properties to the CREATE TABLE command.

Examples:

class WithClusteringOrderMigration < CassandraMigrations::Migration
  def up
    create_table :collection_lists, options: {
                                      clustering_order: 'a_decimal DESC',
                                      compact_storage: true,
                                      gc_grace_seconds: 43200
                                    } do |t|
      t.uuid :id, :primary_key => true
      t.decimal :a_decimal
    end
  end
end

Using Alternate/Additional Keyspaces

The using_keyspace method in a migration allows to execute that migration in the context of a specific keyspace:

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

If using multiple keyspaces, read about Using Multiple Keyspaces.

Collections

Support for Cassandra collections are provided via the list, set and map column types.

class CollectionsListMigration < CassandraMigrations::Migration
  def up
    create_table :collection_lists do |t|
      t.uuid :id, :primary_key => true
      t.list :my_list, :type => :string
      t.set :my_set, :type => :float
      t.map :my_map, :key_type => :uuid, :value_type => :float
    end
  end
end
Clone this wiki locally