Class: DynamoRecord::TableMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamo-record/table_migration.rb

Class Method Summary collapse

Class Method Details

.add_stream(model) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dynamo-record/table_migration.rb', line 22

def self.add_stream(model)
  migrate_updates(model) do |migration|
    migration.update!(
      stream_specification: {
        stream_enabled: true,
        stream_view_type: 'NEW_IMAGE'
      }
    )
  end
rescue Aws::DynamoDB::Errors::ValidationException => e
  return e.message if e.message == 'Table already has an enabled stream'
  raise e
end

.migrate(model) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/dynamo-record/table_migration.rb', line 3

def self.migrate(model)
  migration = Aws::Record::TableMigration.new(model)
  begin
    migration.client.describe_table(table_name: model.table_name)
    return :exists
  rescue Aws::DynamoDB::Errors::ResourceNotFoundException
    yield migration
    migration.wait_until_available
    return :migrated
  end
end

.migrate_updates(model) {|migration| ... } ⇒ Object

Yields:

  • (migration)


15
16
17
18
19
20
# File 'lib/dynamo-record/table_migration.rb', line 15

def self.migrate_updates(model)
  migration = Aws::Record::TableMigration.new(model)
  yield migration
  migration.wait_until_available
  :updated
end