Class: CassandraStore::Migration
- Inherits:
-
Object
- Object
- CassandraStore::Migration
- Defined in:
- lib/cassandra_store/migration.rb
Class Method Summary collapse
- .down(path, version) ⇒ Object
- .migrate(path) ⇒ Object
- .migration_class(path, version) ⇒ Object
- .migration_file(path, version) ⇒ Object
- .up(path, version) ⇒ Object
Instance Method Summary collapse
Class Method Details
.down(path, version) ⇒ Object
18 19 20 21 22 |
# File 'lib/cassandra_store/migration.rb', line 18 def self.down(path, version) migration_class(path, version).new.down CassandraStore::SchemaMigration.where(version: version.to_s).delete_all end |
.migrate(path) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/cassandra_store/migration.rb', line 24 def self.migrate(path) migrated = CassandraStore::SchemaMigration.all.to_a.map(&:version).to_set all = Dir[File.join(path, "*.rb")].map { |file| File.basename(file) } todo = all.select { |file| file =~ /\A[0-9]+_/ && !migrated.include?(file.to_i.to_s) }.sort_by(&:to_i) todo.each do |file| up path, file.to_i.to_s end end |
.migration_class(path, version) ⇒ Object
6 7 8 9 10 |
# File 'lib/cassandra_store/migration.rb', line 6 def self.migration_class(path, version) require migration_file(path, version) File.basename(migration_file(path, version), ".rb").gsub(/\A[0-9]+_/, "").camelcase.constantize end |
.migration_file(path, version) ⇒ Object
2 3 4 |
# File 'lib/cassandra_store/migration.rb', line 2 def self.migration_file(path, version) Dir[File.join(path, "#{version}_*.rb")].first end |
.up(path, version) ⇒ Object
12 13 14 15 16 |
# File 'lib/cassandra_store/migration.rb', line 12 def self.up(path, version) migration_class(path, version).new.up CassandraStore::SchemaMigration.create!(version: version.to_s) end |
Instance Method Details
#down ⇒ Object
40 |
# File 'lib/cassandra_store/migration.rb', line 40 def down; end |
#execute(*args) ⇒ Object
34 35 36 |
# File 'lib/cassandra_store/migration.rb', line 34 def execute(*args) CassandraStore::Base.execute(*args) end |
#up ⇒ Object
38 |
# File 'lib/cassandra_store/migration.rb', line 38 def up; end |