class LolDba::SqlGenerator

Public Class Methods

new(which) click to toggle source
# File lib/lol_dba/sql_migrations/sql_generator.rb, line 3
def initialize(which)
  @which = which
end

Public Instance Methods

run() click to toggle source
# File lib/lol_dba/sql_migrations/sql_generator.rb, line 7
def run
  LolDba::Writer.reset_output_dir
  migrations(@which).each do |file|
    LolDba::Migration.new(file).up
  end
end

Private Instance Methods

migrations(which) click to toggle source
# File lib/lol_dba/sql_migrations/sql_generator.rb, line 16
def migrations(which)
  if which == 'all'
    migrator.migrations.collect(&:filename)
  elsif which == 'pending'
    pending_migrations
  else
    specific_migration(which)
  end
end
migrator() click to toggle source
# File lib/lol_dba/sql_migrations/sql_generator.rb, line 45
def migrator
  LolDba::RailsCompatibility.migrator
end
pending_migrations() click to toggle source
# File lib/lol_dba/sql_migrations/sql_generator.rb, line 26
def pending_migrations
  pending = migrator.pending_migrations
  if pending.empty?
    puts 'No pending migrations.'
    exit
  end
  pending.collect(&:filename)
end
specific_migration(which) click to toggle source
# File lib/lol_dba/sql_migrations/sql_generator.rb, line 35
def specific_migration(which)
  migration = migrator.migrations.find { |m| m.version == which.to_i }
  if migration.present?
    [migration.filename]
  else
    puts "There are no migrations for version #{which}."
    exit
  end
end