Class: Dynamo::Record::TableMigration
- Inherits:
-
Object
- Object
- Dynamo::Record::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
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dynamo/record/table_migration.rb', line 31 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
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dynamo/record/table_migration.rb', line 12 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
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dynamo/record/table_migration.rb', line 45 def self.migrate_table?(update_provisioned_throughput = false) unless update_provisioned_throughput table_name = table_config.instance_values['model_class'].table_name described_table = table_config.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
24 25 26 27 28 29 |
# File 'lib/dynamo/record/table_migration.rb', line 24 def self.migrate_updates(model) migration = Aws::Record::TableMigration.new(model) yield migration migration.wait_until_available :updated end |
.table_config_check ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/dynamo/record/table_migration.rb', line 4 def self.table_config_check if migrate_table? table_config.migrate! return :migrated end :exists end |