Sha256: d15be3d4b1c1b0af0082f657481bc564ea0b7e6b00b2f5680c3302035ba71a85

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

class Dynomite::Migration
  class Executor
    include Dynomite::DbConfig

    # Examples:
    #  Executor.new(:create_table, params) or
    #  Executor.new(:update_table, params)
    #
    # The params are generated frmo the dsl.params
    attr_accessor :table_name
    def initialize(table_name, method_name, params)
      @table_name = table_name
      @method_name = method_name # create_table or update_table
      @params = params
    end

    def run
      begin
        # Examples:
        #   result = db.create_table(@params)
        #   result = db.update_table(@params)

        # Leaving this verbose output in here until this DSL is more hardened to help debug
        unless ENV['DYNOMITE_ENV'] == 'test'
          puts "Calling #{@method_name} with params:"
          pp @params
        end

        return if ENV['DYNOMITE_DRY'] # dry run flag
        result = db.send(@method_name, @params)

        puts "DynamoDB Table: #{@table_name} Status: #{result.table_description.table_status}"
      rescue Aws::DynamoDB::Errors::ServiceError => error
        puts "Unable to #{@method_name.to_s.gsub('_',' ')}: #{error.message}".color(:red)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dynomite-1.2.7 lib/dynomite/migration/executor.rb
dynomite-1.2.6 lib/dynomite/migration/executor.rb
dynomite-1.2.5 lib/dynomite/migration/executor.rb