@eolas-medical/dynamodb-migrator-cli
v1.0.3
Published
DynamoDB Migrator
Downloads
1
Keywords
Readme
dynamodb-migrator-cli
Install
npm i @eolas-medical/dynamodb-migrator-cli --save-dev
Usage
1. Configuration file
Set the config options in .dynamodb-migratorrc.<json|yaml|yml|js|cjs>
or dynamodb-migrator.config.<js|cjs>
:
Config Options
// example dynamodb-migrator.config.js
module.exports = {
migrationsPath: "./migrations", // the directory name where the migration files are listed
region: "eu-west-1",
endpoint: "http://localhost:8000", // optional, local dev only
tableName: "migrations", // the table to use to store which migrations have ran
keyName: "migrationName", // the primary key in the dynamodb table
};
2. Generate a migration file
dynamodb-migrator generate <name-of-migration>
3. Update the generated migration file
// example ./migrations/<generated-file-name>.js
import { UpdateCommand } from "@aws-sdk/lib-dynamodb";
module.exports = {
up: async (db) => {
// db is an instance of @aws dynamodb document client v3.
return db.send(
new UpdateCommand({
TableName: "TableName",
Key: {
id: "abc-123",
},
UpdateExpression: "SET #newAttr = :newAttr",
ExpressionAttributeNames: {
"#newAttr": "newAttr",
},
ExpressionAttributeValues: {
":newAttr": "new attribute",
},
})
);
},
down: () => {},
};