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
- #reindex_all ⇒ Object
- #reindex_one(model) ⇒ 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, #reload_solr_core, #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
75 76 77 |
# File 'lib/datastax_rails/schema/migrator.rb', line 75 def connection DatastaxRails::Base.connection end |
#migrate_all(force = false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/datastax_rails/schema/migrator.rb', line 44 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/datastax_rails/schema/migrator.rb', line 58 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 |
#reindex_all ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/datastax_rails/schema/migrator.rb', line 19 def reindex_all say_with_time('Reindexing all models') do FileList[rails_models].each do |model| require model end count = 0 DatastaxRails::Base.models.each do |m| count += reindex_one(m) unless m.abstract_class? end count end end |
#reindex_one(model) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/datastax_rails/schema/migrator.rb', line 33 def reindex_one(model) count = 0 unless model <= DatastaxRails::CassandraOnlyModel say_with_time("Reindexing #{model.name}") do reindex_solr(model, false) count += 1 end end count end |