Class: DatastaxRails::Schema::Migrator
- Defined in:
- lib/datastax_rails/schema/migrator.rb
Overview
DatastaxRails reads the attributes from the individual models. This class migrates both Cassandra and Solr to the point where they reflect what is specified in the models.
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(keyspace) ⇒ Migrator
constructor
A new instance of Migrator.
- #migrate_all(force = false) ⇒ Object
- #migrate_one(model, force = false) ⇒ Object
Methods included from Cassandra
#cassandra_index_cql_name, #check_missing_schema, #column_exists?, #column_family_exists?, #create_cql3_column_family, #create_keyspace, #drop_keyspace, #index_exists?, #keyspace_exists?, #solr_index_cql_name
Methods included from Solr
#create_solr_core, #generate_solr_schema, #reindex_solr, #upload_solr_configuration
Constructor Details
#initialize(keyspace) ⇒ Migrator
Returns a new instance of Migrator.
13 14 15 16 17 |
# File 'lib/datastax_rails/schema/migrator.rb', line 13 def initialize(keyspace) @keyspace = keyspace check_schema_migrations unless keyspace == 'system' @errors = [] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
11 12 13 |
# File 'lib/datastax_rails/schema/migrator.rb', line 11 def errors @errors end |
Instance Method Details
#connection ⇒ Object
51 52 53 |
# File 'lib/datastax_rails/schema/migrator.rb', line 51 def connection DatastaxRails::Base.connection end |
#migrate_all(force = false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/datastax_rails/schema/migrator.rb', line 19 def migrate_all(force = false) say_with_time('Migrating all models') do FileList[rails_models].each do |model| require model end count = 0 DatastaxRails::Base.models.each do |m| count += migrate_one(m, force) unless m.abstract_class? end count end end |
#migrate_one(model, force = false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/datastax_rails/schema/migrator.rb', line 34 def migrate_one(model, force = false) count = 0 say_with_time("Migrating #{model.name} to latest version") do unless column_family_exists?(model.column_family.to_s) create_cql3_column_family(model) count += 1 end count += check_missing_schema(model) unless model <= DatastaxRails::CassandraOnlyModel count += upload_solr_configuration(model, force) end end count end |