def _alter(self, tree): """ Run an ALTER statement """ if tree.throughput: [read, write] = tree.throughput index = None if tree.index: index = tree.index self._update_throughput(tree.table, read, write, index) elif tree.drop_index: updates = [IndexUpdate.delete(tree.drop_index[0])] try: self.connection.update_table(tree.table, index_updates=updates) except DynamoDBError as e: if tree.exists and e.kwargs["Code"] == "ResourceNotFoundException": pass else: raise elif tree.create_index: # GlobalIndex attrs = {} index = self._parse_global_index(tree.create_index, attrs) updates = [IndexUpdate.create(index)] try: self.connection.update_table(tree.table, index_updates=updates) except DynamoDBError as e: if ( tree.not_exists and e.kwargs["Code"] == "ValidationException" and "already exists" in e.kwargs["Message"] ): pass else: raise else: raise SyntaxError("No alter command found")
def _alter(self, tree): """ Run an ALTER statement """ if tree.throughput: [read, write] = tree.throughput index = None if tree.index: index = tree.index self._update_throughput(tree.table, read, write, index) elif tree.drop_index: updates = [IndexUpdate.delete(tree.drop_index[0])] try: self.connection.update_table(tree.table, index_updates=updates) except DynamoDBError as e: if tree.exists and e.kwargs[ "Code"] == "ResourceNotFoundException": pass else: raise elif tree.create_index: # GlobalIndex attrs = {} index = self._parse_global_index(tree.create_index, attrs) updates = [IndexUpdate.create(index)] try: self.connection.update_table(tree.table, index_updates=updates) except DynamoDBError as e: if (tree.not_exists and e.kwargs["Code"] == "ValidationException" and "already exists" in e.kwargs["Message"]): pass else: raise else: raise SyntaxError("No alter command found")
def test_delete_index(self): """ Delete a global index """ hash_key = DynamoKey('id', data_type=STRING) index_field = DynamoKey('name') index = GlobalIndex.all('name-index', index_field) self.dynamo.create_table('foobar', hash_key=hash_key, global_indexes=[index]) self.dynamo.update_table('foobar', index_updates=[ IndexUpdate.delete('name-index')]) table = self.dynamo.describe_table('foobar') self.assertTrue(len(table.global_indexes) == 0 or table.global_indexes[0].index_status == 'DELETING')
def test_index_update_equality(self): """ IndexUpdates should have sane == behavior """ self.assertEqual(IndexUpdate.delete('foo'), IndexUpdate.delete('foo')) collection = set([IndexUpdate.delete('foo')]) self.assertIn(IndexUpdate.delete('foo'), collection) self.assertNotEqual(IndexUpdate.delete('foo'), IndexUpdate.delete('bar'))
def test_delete_index(self): """ Delete a global index """ hash_key = DynamoKey('id', data_type=STRING) index_field = DynamoKey('name') index = GlobalIndex.all('name-index', index_field) self.dynamo.create_table('foobar', hash_key=hash_key, global_indexes=[index]) self.dynamo.update_table( 'foobar', index_updates=[IndexUpdate.delete('name-index')]) table = self.dynamo.describe_table('foobar') self.assertTrue( len(table.global_indexes) == 0 or table.global_indexes[0].index_status == 'DELETING')
def test_delete_index(self): """Delete a global index""" hash_key = DynamoKey("id", data_type=STRING) index_field = DynamoKey("name") index = GlobalIndex.all("name-index", index_field) self.dynamo.create_table("foobar", hash_key=hash_key, global_indexes=[index]) self.dynamo.update_table( "foobar", index_updates=[IndexUpdate.delete("name-index")] ) table = self.dynamo.describe_table("foobar") assert table is not None self.assertTrue( len(table.global_indexes) == 0 or table.global_indexes[0].status == "DELETING" )