Class: Jets::Commands::Dynamodb::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/commands/dynamodb/migrator.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ Migrator

Returns a new instance of Migrator.



8
9
10
11
# File 'lib/jets/commands/dynamodb/migrator.rb', line 8

def initialize(path, options)
  @path = path
  @options = options
end

Instance Method Details

#get_migration_classObject



31
32
33
34
35
# File 'lib/jets/commands/dynamodb/migrator.rb', line 31

def get_migration_class
  filename = File.basename(@path, '.rb')
  filename = filename.sub(/\d+[-_]/, '') # strip leading timestsamp
  filename.classify.constantize
end

#migrateObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jets/commands/dynamodb/migrator.rb', line 19

def migrate
  path = "#{Jets.root}#{@path}"
  unless File.exist?(path)
    puts "Unable to find the migration file: #{path}"
    exit 1
  end

  require path
  migration_class = get_migration_class
  migration_class.new.up
end

#runObject



13
14
15
16
17
# File 'lib/jets/commands/dynamodb/migrator.rb', line 13

def run
  puts "Running database migrations"
  return if @options[:noop]
  migrate
end