一个帮助您创建和迁移DynamoDB数据库的库
项目描述
dynamodb-migrator
一个帮助您创建和迁移DynamoDB数据库的库。
尽管DynamoDB的性能很好,但这也带来了不灵活的代价。更改列名或添加辅助索引是不可能的。
建议的方法是创建一个新的表,具有所需的属性,并迁移现有数据。
此库将帮助您完成这些操作。
用法
- 编写迁移脚本
- 在构建管道步骤中执行迁移脚本
- 根据需要添加到迁移脚本
示例脚本
from migrator.dynamodb_migrator import Migrator
migrator = Migrator()
@migrator.version(1)
@migrator.create(AttributeDefinitions=[{'AttributeName': 'hash_key', 'AttributeType': 'N'}],
TableName='my_new_table',
KeySchema=[{'AttributeName': 'hash_key', 'KeyType': 'HASH'}],
BillingMode='PAY_PER_REQUEST')
def v1(created_table):
print("Table created using the kwargs provided")
print("Note that the keyword-args are passed onto boto as is")
print(created_table)
@migrator.version(2)
@migrator.add_index(AttributeDefinitions=[{'AttributeName': 'postcode', 'AttributeType': 'S'}],
LocalSecondaryIndexes=[{'IndexName': 'string',
'KeySchema': [{'AttributeName': 'customer_nr', 'KeyType': 'HASH'},
{'AttributeName': 'postcode', 'KeyType': 'RANGE'}],
'Projection': {'ProjectionType': 'ALL'}}])
def v2(created_table):
print("Created a new table with the new index")
print("Created a DynamoDB stream that sends all updates to the old table to a custom Lambda-function")
print("The custom Lambda-function sends all updates to the new table")
print(created_table)
@NotYetImplemented
@migrator.version(3)
@migrator.delete_table("first_table")
def v3(migrate):
print("About to delete table")
print("Ensure that all upstream applications point to the new table, before adding this part to the pipeline!")
migrate()
print("Table deleted")
@NotYetImplemented
@migrator.version(4)
@migrator.convert(lambda item -> {'id': translate(item.id)})
def v4(migrate):
print("About to:")
print(" - Create new table (first_table_v4)")
print(" - Create a AWS Lambda script that will execute the above lambda, and write the result int he new table")
print(" - Create DynamoDB Stream on 'first_table' that triggers the new Lambda")
print(" - Execute a script that automatically updates all existing data")
print(" (This will trigger all data in 'first_table' to be converted and copied into the new table")
migrate()
print("Table with new data is ready to use")
示例
请参阅 examples 文件夹。
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。
源分布
dynamodb-migrator-0.0.8.tar.gz (9.6 kB 查看哈希值)
构建分发
dynamodb_migrator-0.0.8-py3-none-any.whl (16.1 kB 查看哈希)
关闭
dynamodb-migrator-0.0.8.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1c5d1470c7b58089d2356c930c4ce4da3ae9169fbdab9abd5c895f1c6365da8d |
|
MD5 | 0e29b61477ea40c2a09cc583fbd65355 |
|
BLAKE2b-256 | e996be752d01579455eab70bbc375b42d2e955fc52462204313551a6e0eca050 |
关闭
dynamodb_migrator-0.0.8-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | df91e6717fa7494c8362641e0168395911b4a543bb6c3ab839d6032a09f66b4b |
|
MD5 | 69f827ef7f86e8d0538d5af07e9be902 |
|
BLAKE2b-256 | 7999b6c400cd54bed60181039723b17e467cd88cc25177da48f58070293d7d13 |