跳转到主要内容

一个帮助您创建和迁移DynamoDB数据库的库

项目描述

dynamodb-migrator

Build Status Coverage Status PyPI version

一个帮助您创建和迁移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 查看哈希)

上传于 Python 3

由以下提供支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面