Sha256: 4e449065ed02b1573a0fc43ef52781cdae420291421159b15ea0bdb1c7c5ba21

Contents?: true

Size: 964 Bytes

Versions: 2

Compression:

Stored size: 964 Bytes

Contents

class Cassandra::Mapper
  def self.migrate
    cassandra = Cassandra.new('system')
    schema[:keyspaces].each do |name|
      options  = schema.fetch(env, {}).fetch(name, {})
      options  = Utility::Hash.stringify_keys options
      strategy = options.delete('strategy') || 'SimpleStrategy'
      options['replication_factor'] = options.fetch('replication_factor', 1).to_s

      cassandra.add_keyspace Cassandra::Keyspace.new \
        name:             "#{name}_#{env}",
        strategy_class:   strategy,
        strategy_options: options,
        cf_defs:          []
    end
  end

  def migrate
    subkey_types = config.subkey.map do |it|
      Convert.type config.types[it]
    end

    # field subkey
    subkey_types.push Convert::TEXT_TYPE

    keyspace.add_column_family Cassandra::ColumnFamily.new \
      keyspace:        keyspace.keyspace,
      name:            table,
      comparator_type: "CompositeType(#{subkey_types.join ','})"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cassandra-mapper-0.2 lib/cassandra/mapper/extend/migrate.rb
cassandra-mapper-0.1 lib/cassandra/mapper/extend/migrate.rb