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.
19 20 21 22 23 24 |
# File 'lib/aws-record/record/table_migration.rb', line 19 def initialize(model, opts = {}) _assert_model_valid(model) @model = model @client = opts[:client] || model.dynamodb_client || Aws::DynamoDB::Client.new @client.config.user_agent_frameworks << 'aws-record' end |
Instance Attribute Details
#client ⇒ Aws::DynamoDB::Client
Returns the Aws::DynamoDB::Client class used by this table migration instance.
10 11 12 |
# File 'lib/aws-record/record/table_migration.rb', line 10 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/aws-record/record/table_migration.rb', line 63 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, '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.
117 118 119 120 121 |
# File 'lib/aws-record/record/table_migration.rb', line 117 def delete! @client.delete_table(table_name: @model.table_name) rescue DynamoDB::Errors::ResourceNotFoundException raise Errors::TableDoesNotExist end |
#update!(opts) ⇒ Object
This method calls Aws::DynamoDB::Client#update_table using the parameters that you provide.
102 103 104 105 106 107 108 109 |
# File 'lib/aws-record/record/table_migration.rb', line 102 def update!(opts) update_opts = opts.merge( table_name: @model.table_name ) @client.update_table(update_opts) rescue DynamoDB::Errors::ResourceNotFoundException raise Errors::TableDoesNotExist 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.
127 128 129 |
# File 'lib/aws-record/record/table_migration.rb', line 127 def wait_until_available @client.wait_until(:table_exists, table_name: @model.table_name) end |