Class: DashOverlord::Models::V1::DynamoDb::Migration

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/dash_overlord/models/v1/dynamo_db/migration.rb

Instance Method Summary collapse

Constructor Details

#initialize(migration_class) ⇒ Migration

Returns a new instance of Migration.



8
9
10
11
12
# File 'lib/dash_overlord/models/v1/dynamo_db/migration.rb', line 8

def initialize(migration_class)
  @client ||= Aws::DynamoDB::Client.new

  @migration_class = migration_class
end

Instance Method Details

#create!(params = nil) ⇒ Object



14
15
16
# File 'lib/dash_overlord/models/v1/dynamo_db/migration.rb', line 14

def create!(params = nil)
  @client.create_table(params || create_params)
end

#create_paramsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dash_overlord/models/v1/dynamo_db/migration.rb', line 18

def create_params
  # THIS NEEDS TO BE DYNAMIC!
  {
    table_name: @migration_class.table_name,
    key_schema: [
      {
        attribute_name: "dashboard_id",
        key_type: "HASH" #PRIMARY KEY
      },
      {
        attribute_name: "id",
        key_type: "RANGE" # SORT KEY
      },
    ],
    attribute_definitions: [
      {
        attribute_name: "dashboard_id",
        attribute_type: "N"
      },
      {
        attribute_name: "id",
        attribute_type: "N"
      }
    ],
    provisioned_throughput: {
      read_capacity_units: 10,
      write_capacity_units: 10
    }
  }
end

#delete!Object



49
50
51
# File 'lib/dash_overlord/models/v1/dynamo_db/migration.rb', line 49

def delete!
  @client.delete_table(delete_params)
end

#delete_paramsObject



53
54
55
56
57
# File 'lib/dash_overlord/models/v1/dynamo_db/migration.rb', line 53

def delete_params
  {
    table_name: @migration_class.table_name
  }
end