Class: DynamoRecord::TableMigration
- Inherits:
-
Object
- Object
- DynamoRecord::TableMigration
- Defined in:
- lib/dynamo-record/table_migration.rb
Class Method Summary collapse
- .add_stream(model) ⇒ Object
- .migrate(model) ⇒ Object
- .migrate_table?(update_provisioned_throughput = false) ⇒ Boolean
- .migrate_updates(model) {|migration| ... } ⇒ Object
- .table_config_check ⇒ Object
Class Method Details
.add_stream(model) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dynamo-record/table_migration.rb', line 30 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. if e. == 'Table already has an enabled stream' raise e end |
.migrate(model) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dynamo-record/table_migration.rb', line 11 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_table?(update_provisioned_throughput = false) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dynamo-record/table_migration.rb', line 44 def self.migrate_table?(update_provisioned_throughput = false) unless update_provisioned_throughput client = table_config.client table_name = table_config.instance_values['model_class'].table_name described_table = client.describe_table table_name: table_name provisioned_throughput = described_table.table.provisioned_throughput table_config.read_capacity_units provisioned_throughput.read_capacity_units table_config.write_capacity_units provisioned_throughput.write_capacity_units end !table_config.exact_match? rescue Aws::DynamoDB::Errors::ResourceNotFoundException true end |
.migrate_updates(model) {|migration| ... } ⇒ Object
23 24 25 26 27 28 |
# File 'lib/dynamo-record/table_migration.rb', line 23 def self.migrate_updates(model) migration = Aws::Record::TableMigration.new(model) yield migration migration.wait_until_available :updated end |
.table_config_check ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/dynamo-record/table_migration.rb', line 3 def self.table_config_check if migrate_table? table_config.migrate! return :migrated end :exists end |