Class: Aws::Record::TableMigration
- Inherits:
-
Object
- Object
- Aws::Record::TableMigration
- Defined in:
- lib/aws-record/record/table_migration.rb
Instance Attribute Summary collapse
-
#client ⇒ Aws::DynamoDB::Client
The Aws::DynamoDB::Client class used by this table migration instance.
Instance Method Summary collapse
-
#create!(opts) ⇒ Object
This method calls Aws::DynamoDB::Client#create_table, populating the attribute definitions and key schema based on your model class, as well as passing through other parameters as provided by you.
-
#delete! ⇒ Object
This method calls Aws::DynamoDB::Client#delete_table using the table name of your model.
-
#initialize(model, opts = {}) ⇒ TableMigration
constructor
A new instance of TableMigration.
-
#update!(opts) ⇒ Object
This method calls Aws::DynamoDB::Client#update_table using the parameters that you provide.
-
#wait_until_available ⇒ Object
This method waits on the table specified in the model to exist and be marked as ACTIVE in Amazon DynamoDB.
Constructor Details
#initialize(model, opts = {}) ⇒ TableMigration
Returns a new instance of TableMigration.
31 32 33 34 35 |
# File 'lib/aws-record/record/table_migration.rb', line 31 def initialize(model, opts = {}) _assert_model_valid(model) @model = model @client = opts[:client] || model.dynamodb_client || Aws::DynamoDB::Client.new end |
Instance Attribute Details
#client ⇒ Aws::DynamoDB::Client
Returns the Aws::DynamoDB::Client class used by this table migration instance.
22 23 24 |
# File 'lib/aws-record/record/table_migration.rb', line 22 def client @client end |
Instance Method Details
#create!(opts) ⇒ Object
This method calls Aws::DynamoDB::Client#create_table, populating the attribute definitions and key schema based on your model class, as well as passing through other parameters as provided by you.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/aws-record/record/table_migration.rb', line 66 def create!(opts) gsit = opts.delete(:global_secondary_index_throughput) create_opts = opts.merge({ table_name: @model.table_name, attribute_definitions: _attribute_definitions, key_schema: _key_schema }) if lsis = @model.local_secondary_indexes_for_migration create_opts[:local_secondary_indexes] = lsis _append_to_attribute_definitions(lsis, create_opts) end if gsis = @model.global_secondary_indexes_for_migration unless gsit raise ArgumentError.new( "If you define global secondary indexes, you must also define"\ " :global_secondary_index_throughput on table creation." ) end gsis_with_throughput = _add_throughout_to_gsis(gsis, gsit) create_opts[:global_secondary_indexes] = gsis_with_throughput _append_to_attribute_definitions(gsis, create_opts) end @client.create_table(create_opts) end |
#delete! ⇒ Object
This method calls Aws::DynamoDB::Client#delete_table using the table name of your model.
117 118 119 120 121 122 123 |
# File 'lib/aws-record/record/table_migration.rb', line 117 def delete! begin @client.delete_table(table_name: @model.table_name) rescue DynamoDB::Errors::ResourceNotFoundException => e raise Errors::TableDoesNotExist.new(e) end end |
#update!(opts) ⇒ Object
This method calls Aws::DynamoDB::Client#update_table using the parameters that you provide.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/aws-record/record/table_migration.rb', line 100 def update!(opts) begin update_opts = opts.merge({ table_name: @model.table_name }) @client.update_table(update_opts) rescue DynamoDB::Errors::ResourceNotFoundException => e raise Errors::TableDoesNotExist.new(e) end end |
#wait_until_available ⇒ Object
This method waits on the table specified in the model to exist and be marked as ACTIVE in Amazon DynamoDB. Note that this method can run for several minutes if the table does not exist, and is not created within the wait period.
129 130 131 |
# File 'lib/aws-record/record/table_migration.rb', line 129 def wait_until_available @client.wait_until(:table_exists, table_name: @model.table_name) end |