dynamodb-migrator
A library that helps you create and migrate DynamoDB databases.
As performant DynamoDB is, that does come with the trade-off of being inflexible. Changing column names or adding secondary indexes is impossible.
The recommended approach is to create a new table with the desired properties, and migrate the existing data.
This library will help you do just that.
Usage
- Write a migration script
- Execute the migration script as a step in the build pipeline
- Add to the migration-script as required
Example
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)
@NotYetImplemented
@migrator.version(2)
@migrator.add_index("secondary_index_we_forgot_about")
def v2(migrate):
print("About to:")
print(" - Create new table (first_table_v2) with the appropriate index")
print(" - Create DynamoDB Stream on 'first_table' that copies changes into the new table")
print(" - Execute a script that automatically updates all existing data")
print(" (This will trigger all data in 'first_table' to be copied into the new table")
migrate()
print("Table with new index is ready to use")
@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")
Metadata
Release files for dynamodb-migrator 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dynamodb-migrator-0.0.2.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dynamodb_migrator-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.9 kB
Release files / dynamodb-migrator-0.0.2.tar.gz
| Download URL | dynamodb-migrator-0.0.2.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d7c5f76f915b9b02e94a97303ffdba695a8cbb2e3ed7053f76854a3379ab276
|
|
BLAKE2b-256 checksum How to use checksums |
5b5cf63717a83cc4e2bdc6ad001c4942a8f3016847f959da4fcd5e9906cf6ecc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
|
Release files / dynamodb_migrator-0.0.2-py3-none-any.whl
| Download URL | dynamodb_migrator-0.0.2-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f1cabc3cddfbd0f2d2673be659bfd7211974469922c685f900f1e910d6bd44a
|
|
BLAKE2b-256 checksum How to use checksums |
009be62cdf1d831bddea60dd0d379f5d10b94467ee596ed66353b02b5cc8dd55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
|