Class: ActiveColumn::Migration
Constant Summary collapse
- @@verbose =
true
Class Method Summary collapse
- .announce(message) ⇒ Object
-
.connection ⇒ Object
Returns the raw connection to Cassandra.
-
.create_column_family(name, &block) ⇒ Object
Creates a new column family with the given name.
-
.drop_column_family(name) ⇒ Object
Drops the given column family.
- .migrate(direction) ⇒ Object
-
.rename_column_family(old_name, new_name) ⇒ Object
Renames the column family from the old name to the new name.
- .say(message, subitem = false) ⇒ Object
- .say_with_time(message) ⇒ Object
- .suppress_messages ⇒ Object
- .verbose ⇒ Object
- .verbose=(verbose) ⇒ Object
- .write(text = "") ⇒ Object
Class Method Details
.announce(message) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/active_column/migration.rb', line 70 def self.announce() version = defined?(@version) ? @version : nil text = "#{version} #{name}: #{}" length = [0, 75 - text.length].max write "== %s %s" % [text, "=" * length] end |
.connection ⇒ Object
Returns the raw connection to Cassandra
16 17 18 |
# File 'lib/active_column/migration.rb', line 16 def self.connection ActiveColumn.connection end |
.create_column_family(name, &block) ⇒ Object
Creates a new column family with the given name. Column family configurations can be set within a block like this:
create_column_family(:users) do |cf|
cf.comment = 'Users column family'
cf.comparator_type = 'TimeUUIDType'
end
A complete list of available configuration settings is here:
github.com/fauna/cassandra/blob/master/vendor/0.7/gen-rb/cassandra_types.rb
Scroll down to the CfDef definition.
52 53 54 |
# File 'lib/active_column/migration.rb', line 52 def self.create_column_family(name, &block) ActiveColumn.column_family_tasks.create(name, &block) end |
.drop_column_family(name) ⇒ Object
Drops the given column family
57 58 59 |
# File 'lib/active_column/migration.rb', line 57 def self.drop_column_family(name) ActiveColumn.column_family_tasks.drop(name) end |
.migrate(direction) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_column/migration.rb', line 20 def self.migrate(direction) return unless respond_to?(direction) case direction when :up then announce "migrating" when :down then announce "reverting" end result = nil time = Benchmark.measure { result = send("#{direction}") } case direction when :up then announce "migrated (%.4fs)" % time.real; write when :down then announce "reverted (%.4fs)" % time.real; write end result end |
.rename_column_family(old_name, new_name) ⇒ Object
Renames the column family from the old name to the new name
62 63 64 |
# File 'lib/active_column/migration.rb', line 62 def self.rename_column_family(old_name, new_name) ActiveColumn.column_family_tasks.rename(old_name, new_name) end |
.say(message, subitem = false) ⇒ Object
78 79 80 |
# File 'lib/active_column/migration.rb', line 78 def self.say(, subitem=false) write "#{subitem ? " ->" : "--"} #{}" end |
.say_with_time(message) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/active_column/migration.rb', line 82 def self.say_with_time() say() result = nil time = Benchmark.measure { result = yield } say "%.4fs" % time.real, :subitem say("#{result} rows", :subitem) if result.is_a?(Integer) result end |
.suppress_messages ⇒ Object
91 92 93 94 95 96 |
# File 'lib/active_column/migration.rb', line 91 def self. save, self.verbose = verbose, false yield ensure self.verbose = save end |
.verbose ⇒ Object
11 12 13 |
# File 'lib/active_column/migration.rb', line 11 def self.verbose @@verbose end |
.verbose=(verbose) ⇒ Object
7 8 9 |
# File 'lib/active_column/migration.rb', line 7 def self.verbose=(verbose) @@verbose = verbose end |
.write(text = "") ⇒ Object
66 67 68 |
# File 'lib/active_column/migration.rb', line 66 def self.write(text="") puts(text) if verbose end |