class HecksAdapters::DynamoDB::Migrate

Creates tables according to your domain spec

Attributes

client[R]

Public Class Methods

new(client:, domain:) click to toggle source
# File lib/migrate.rb, line 5
def initialize(client:, domain:)
  @client           = client
  @unchanged_tables = []
  @new_tables       = []
  @domain           = domain
  load(@domain.spec_path)
end

Public Instance Methods

call() click to toggle source
# File lib/migrate.rb, line 13
def call
  create_tables
  self
end
result() click to toggle source
# File lib/migrate.rb, line 18
def result
  { unchanged_tables: @unchanged_tables, new_tables: @new_tables }
end

Private Instance Methods

create_table(name) click to toggle source
# File lib/migrate.rb, line 32
def create_table(name)
  begin
    client.create_table(
      attribute_definitions: [{
        attribute_name: 'id',
        attribute_type: 'S'
      }],
      table_name: name,
      key_schema: [{ attribute_name: 'id', key_type: 'HASH' }],
      provisioned_throughput: {
        read_capacity_units: 5,
        write_capacity_units: 5
      }
    )
    @new_tables << name
  rescue Aws::DynamoDB::Errors::ResourceInUseException => e
    @unchanged_tables << name
  end
end
create_tables() click to toggle source
# File lib/migrate.rb, line 26
def create_tables
  DOMAIN.domain_modules.values.each do |domain_module|
    create_table(domain_module.head.name)
  end
end