Skip to content

Commit

Permalink
feat(data-migration): remove destination table from stream migration
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvieirasilva committed Nov 3, 2023
1 parent 9264847 commit c72f945
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 176 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
"@commitlint/config-conventional": "^17.4.4",
"@commitlint/config-nx-scopes": "^17.6.4",
"@commitlint/cz-commitlint": "^17.5.0",
"@nx/devkit": "16.3.2",
"@nx/eslint-plugin": "16.3.2",
"@nx/jest": "16.3.2",
"@nx/js": "16.3.2",
"@nx/linter": "16.3.2",
"@nx/plugin": "16.3.2",
"@nx/workspace": "16.3.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.7",
"@swc-node/register": "^1.6.5",
"@swc/cli": "0.1.62",
"@swc/core": "^1.3.57",
"@types/aws-lambda": "^8.10.125",
"@types/cross-spawn": "^6.0.2",
"@types/fs-extra": "^11.0.1",
"@types/jest": "29.4.0",
Expand All @@ -39,21 +47,14 @@
"lint-staged": "^13.1.2",
"mock-fs": "^5.2.0",
"nx": "16.3.2",
"nx-cloud": "16.0.5",
"prettier": "^2.8.4",
"semantic-release-npm": "^0.0.5",
"semantic-release-plus": "^20.0.0",
"string-dedent": "^3.0.1",
"ts-jest": "29.1.0",
"ts-node": "10.9.1",
"typescript": "5.0.4",
"nx-cloud": "16.0.5",
"@nx/devkit": "16.3.2",
"@nx/workspace": "16.3.2",
"@nx/js": "16.3.2",
"@nx/linter": "16.3.2",
"@nx/eslint-plugin": "16.3.2",
"@nx/jest": "16.3.2",
"@nx/plugin": "16.3.2"
"typescript": "5.0.4"
},
"dependencies": {
"@aws-sdk/client-cloudwatch-logs": "^3.348.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);

const TARGET_TABLE_NAME = 'example-users-v2';

export const handler: DynamoDBStreamHandler = async (event) => {
console.debug('Event', JSON.stringify(event));

Expand All @@ -22,7 +24,7 @@ export const handler: DynamoDBStreamHandler = async (event) => {

await docClient.send(
new PutCommand({
TableName: process.env['TARGET_TABLE_NAME'],
TableName: TARGET_TABLE_NAME,
Item: {
userId: item['id'],
name: item['name'],
Expand All @@ -37,7 +39,7 @@ export const handler: DynamoDBStreamHandler = async (event) => {

await docClient.send(
new DeleteCommand({
TableName: process.env['TARGET_TABLE_NAME'],
TableName: TARGET_TABLE_NAME,
Key: {
userId: keys['id'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class extends DynamoDBMigrationBase {
}

async up(): Promise<void> {
await this.enableStream('example-users', 'example-users-v2');
await this.enableStream('example-users');

this.logger.info('Migrating users from v1 to v2');
let count = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/data-migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ import {
})
export default class extends DynamoDBMigrationBase {
async up(): Promise<void> {
await this.enableStream('my-table-v1', 'my-table-v2');
await this.enableStream('my-table-v1');

const items = await MyTableModel.scan().exec();
for (const chunk of chunks(items, 25)) {
Expand Down
Loading

0 comments on commit c72f945

Please sign in to comment.