Sha256: c47bf8e24a0f8af55114b76b39308626b50ab04df497ecb5ed46742cfbb21ee7

Contents?: true

Size: 1.41 KB

Versions: 22

Compression:

Stored size: 1.41 KB

Contents

ks_namespace = namespace :ks do
  desc 'Create the keyspace in config/cassandra.yml for the current environment'
  task create: :environment do
    begin
      CassandraObject::Schema.create_keyspace CassandraObject::Base.config[:keyspace], CassandraObject::Base.config[:keyspace_options]
    rescue Exception => e
      if e.message =~ /conflicts/
        p "Keyspace #{CassandraObject::Base.config[:keyspace]} already exists"
      else
        raise e
      end
    end
  end

  task drop: :environment do
    begin
      CassandraObject::Schema.drop_keyspace CassandraObject::Base.config[:keyspace]
    rescue Exception => e
      if e.message =~ /non existing keyspace/
        p "Keyspace #{CassandraObject::Base.config[:keyspace]} does not exist"
      else
        raise e
      end
    end
  end

  task reset: [:drop, :setup]

  task setup: [:create, :_load]

  namespace :structure do
    task dump: :environment do
      filename = ENV['SCHEMA'] || "#{Rails.root}/ks/structure.cql"
      File.open(filename, "w:utf-8") do |file|
        CassandraObject::Schema.dump(file)
      end
    end

    task load: :environment do
      filename = ENV['SCHEMA'] || "#{Rails.root}/ks/structure.cql"
      File.open(filename) do |file|
        CassandraObject::Schema.load(file)
      end
    end
  end

  task :_dump do
    ks_namespace["structure:dump"].invoke
  end

  task :_load do
    ks_namespace["structure:load"].invoke
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
extendi-cassandra_object-1.1.1 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.1.0 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.20 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.19 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.18 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.17 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.16 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.15 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.14 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.13 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.12 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.11 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.10 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.9 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.8 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.7 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.6 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.5 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.4 lib/cassandra_object/tasks/ks.rake
extendi-cassandra_object-1.0.1 lib/cassandra_object/tasks/ks.rake