Skip to content

Commit 9554bb1

Browse files
authored
Merge branch 'main' into feature/CCM-11148-message-plans-link
2 parents 80b4114 + 5723f41 commit 9554bb1

30 files changed

+5879
-2576
lines changed

data-migration/user-transfer/.gitignore

Whitespace-only changes.
Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,80 @@
11
# User Transfer Data Migration
22

3-
The purpose of this tool is to transfer templates stored in DynamoDB from one owner to another. It does not transfer ownership of any files in S3, this would need to be done separately.
3+
The purpose of this tool is to transfer templates stored in DynamoDB from a single user owner to the user's client.
44

5-
The owner field is the partition key for database entries and as such they are deleted and re-created with the new owner. They will retain their unique ID.
5+
This is a 2-stage process:
66

7-
A local backup of the data is persisted before any updates into a `./backup` directory.
7+
1. Plan (your migration)
8+
2. Apply (your migration)
89

9-
## Parameters
10+
## Plan (your migration)
1011

11-
| Parameter | Optional | Description |
12-
| ------------------ | -------- | ----------------------------------------------- |
13-
| --sourceOwner | Required | The current owner of the data, typically a UUID |
14-
| --destinationOwner | Required | The new owner of the data, typically a UUID |
15-
| --environment | Required | The environment name, e.g. main |
16-
| | | |
12+
This creates a `transfer-plan-*.json` file in `./migrations` local directory and a copy in `main-acct-migration-backup/<environment>/transfer-plan-*/**` S3 bucket.
13+
14+
```bash
15+
npm run plan -- \
16+
--environment "main" \
17+
--userPoolId "abc123" \
18+
--iamAccessKeyId "abc1234" \
19+
--iamSecretAccessKey "abc123" \
20+
--iamSessionToken "abc123"
21+
```
22+
23+
### Parameters
24+
25+
| Parameter | Optional | Description |
26+
| --------------------- | -------- | ---------------------------------------------------------------------------------------------- |
27+
| --environment | Required | The environment name, e.g. main |
28+
| --userPoolId | Required | This Cognito `UserPoolId` (if running in `sbx` then this can be your `sbx` Cognito userPoolId) |
29+
| --iamAccessKeyId | Optional | Access key id of the IAM account (dev/prod) |
30+
| --iamSecretAccessKey | Optional | Secret Access key of the IAM account (dev/prod) |
31+
| --iamSessionToken | Optional | Session token of the IAM account (dev/prod) |
32+
33+
#### Why?
34+
35+
The `transfer-plan-*.json` is used to keep a record of the data that will be migrated to Client ownership.
36+
37+
## Apply (your migration)
38+
39+
Run the migration process for data stored in `transfer-plan-*.json`.
40+
41+
When doing a `dryRun=false` the data will be backed up:
42+
43+
1. transfers all user related files in `internal` S3 bucket
44+
2. retrieves and stores all related DynamoDB data before executing
45+
46+
Backed-up data is stored `main-acct-migration-backup/<environment>/transfer-plan-*/**`
47+
48+
```bash
49+
npm run apply -- \
50+
--environment "main" \
51+
--file "./migrations/file.json" \
52+
--dryRun "true"
53+
```
54+
55+
The result of this script will output a file named the same as the input file but with `run/dryrun` appended to the name. This file is a record of what happened to each migration, whether it failed or passed and which stage the migration ended at.
56+
57+
### Parameters
58+
59+
| Parameter | Optional | Description |
60+
| --------------------- | -------- | ---------------------------------------------------------------------------------------------- |
61+
| --environment | Required | The environment name, e.g. main |
62+
| --file | Required | The path of the `transfer-plan-*.json` file |
63+
| --dryRun | Optional | Defaults to `true`. When true will _not_ execute migration |
1764

1865
## Authentication
1966

20-
You should establish a local AWS authentication session to the target AWS account with sufficient permissions to read, write and delete template data from DynamoDB.
67+
You should establish a local AWS authentication session to the Templates (dev/prod) AWS account with sufficient permissions to read, write and delete template data from DynamoDB.
2168

22-
## Example
69+
## Suggestions
2370

24-
```shell
25-
npm run transfer -- --sourceOwner 26d202d4-f001-7043-1781-77c935224d18 --destinationOwner e6f232b4-6051-7096-a238-5527b8615d11 --environment main
71+
When executing the migration it's a good idea to also write out the logs to a file. For example
72+
73+
```bash
74+
npm run plan -- \
75+
--environment "main" \
76+
--file "./migrations/file.json" \
77+
--dryRun "false" >> migration.logs.txt
2678
```
79+
80+
Then upload this log file to S3. This should then keep a decent record of _what_ happened during a migration.

data-migration/user-transfer/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const config: Config = {
3333

3434
collectCoverageFrom: ['src/**/*.ts*'],
3535

36-
coveragePathIgnorePatterns: ['handler.ts', 'constants.ts'],
36+
coveragePathIgnorePatterns: ['migrate-cli.ts', 'plan-cli.ts', 'types.ts'],
3737

3838
// Set the absolute path for imports
3939
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.json

data-migration/user-transfer/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"dependencies": {
3+
"@aws-sdk/client-cognito-identity-provider": "^3.864.0",
34
"@aws-sdk/client-dynamodb": "^3.864.0",
45
"@aws-sdk/client-s3": "^3.864.0",
56
"@aws-sdk/client-sts": "^3.864.0",
7+
"@aws-sdk/credential-providers": "^3.864.0",
68
"yargs": "^17.7.2"
79
},
810
"description": "Transfers template ownership from one user to another",
@@ -20,8 +22,9 @@
2022
"scripts": {
2123
"lint": "eslint ./src",
2224
"lint:fix": "eslint ./src --fix",
25+
"apply": "tsx src/migrate-cli.ts",
26+
"plan": "tsx src/plan-cli.ts",
2327
"test:unit": "jest",
24-
"transfer": "tsx src/handler.ts",
2528
"typecheck": "tsc --noEmit"
2629
}
2730
}

0 commit comments

Comments
 (0)