Module: Migreazy

Defined in:
lib/migreazy.rb

Defined Under Namespace

Classes: Action, Source

Constant Summary collapse

@@db_connected =
false

Class Method Summary collapse

Class Method Details

.ensure_db_connectionObject



6
7
8
9
10
11
12
# File 'lib/migreazy.rb', line 6

def self.ensure_db_connection
  unless @@db_connected
    db_config = YAML::load(IO.read("./config/database.yml"))
    ActiveRecord::Base.establish_connection db_config['development']
    @@db_connected = true
  end
end

.migration_numbers(branch_name) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/migreazy.rb', line 14

def self.migration_numbers(branch_name)
  repo = Rugged::Repository.new '.'
  branch = repo.branches[branch_name]
  db_oid = branch.target.tree['db'][:oid]
  migrate_oid = repo.lookup(db_oid)['migrate'][:oid]
  all_migrations = repo.lookup(migrate_oid).map { |e| e[:name] }
  all_migrations.map { |name| name.gsub(/^0*(\d+)_.*/, '\1') }
end