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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/aws-record/record/table_migration.rb', line 73 def create!(opts) gsit = opts.delete(:global_secondary_index_throughput) _validate_billing(opts) 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 || opts[:billing_mode] == 'PAY_PER_REQUEST' raise ArgumentError.new( 'If you define global secondary indexes, you must also define'\ ' :global_secondary_index_throughput on table creation,'\ " unless :billing_mode is set to 'PAY_PER_REQUEST'." ) end gsis_opts = if opts[:billing_mode] == 'PAY_PER_REQUEST' gsis else _add_throughput_to_gsis(gsis, gsit) end create_opts[:global_secondary_indexes] = gsis_opts _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.
131 132 133 134 135 136 137 |
# File 'lib/aws-record/record/table_migration.rb', line 131 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.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/aws-record/record/table_migration.rb', line 114 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.
143 144 145 |
# File 'lib/aws-record/record/table_migration.rb', line 143 def wait_until_available @client.wait_until(:table_exists, table_name: @model.table_name) end |