Module: Lhm
- Defined in:
- lib/lhm.rb,
lib/lhm/table.rb,
lib/lhm/chunker.rb,
lib/lhm/command.rb,
lib/lhm/invoker.rb,
lib/lhm/version.rb,
lib/lhm/migrator.rb,
lib/lhm/entangler.rb,
lib/lhm/migration.rb,
lib/lhm/connection.rb,
lib/lhm/sql_helper.rb,
lib/lhm/intersection.rb,
lib/lhm/atomic_switcher.rb,
lib/lhm/locked_switcher.rb
Overview
Copyright © 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias Schmidt
Defined Under Namespace
Modules: Command, SqlHelper Classes: AtomicSwitcher, Chunker, Connection, Entangler, Error, Intersection, Invoker, LockedSwitcher, Migration, Migrator, Table
Constant Summary collapse
- VERSION =
"2.0.0"
Class Method Summary collapse
- .adapter ⇒ Object
-
.change_table(table_name, options = {}) {|Migrator| ... } ⇒ Boolean
Alters a table with the changes described in the block.
- .cleanup(run = false) ⇒ Object
- .setup(adapter) ⇒ Object
Class Method Details
.adapter ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/lhm.rb', line 69 def self.adapter @@adapter ||= begin raise 'Please call Lhm.setup' unless defined?(ActiveRecord) ActiveRecord::Base.connection end end |
.change_table(table_name, options = {}) {|Migrator| ... } ⇒ Boolean
Alters a table with the changes described in the block
40 41 42 43 44 45 46 |
# File 'lib/lhm.rb', line 40 def self.change_table(table_name, = {}, &block) origin = Table.parse(table_name, connection) invoker = Invoker.new(origin, connection) block.call(invoker.migrator) invoker.run() true end |
.cleanup(run = false) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lhm.rb', line 48 def self.cleanup(run = false) lhm_tables = connection.select_values("show tables").select do |name| name =~ /^lhm(a|n)_/ end return true if lhm_tables.empty? if run lhm_tables.each do |table| connection.execute("drop table #{table}") end true else puts "Existing LHM backup tables: #{lhm_tables.join(", ")}." puts "Run Lhm.cleanup(true) to drop them all." false end end |
.setup(adapter) ⇒ Object
65 66 67 |
# File 'lib/lhm.rb', line 65 def self.setup(adapter) @@adapter = adapter end |