Skip to content

Commit 4976cfe

Browse files
committed
fix(discussions): fix post-refactor script regex and add missing fixups
Fix regex to match per-table stack names (storageActivityStack, storageBookmarksStack) instead of the old shared storageStack. Add bookmarks table name and S3 bucket name uncommenting. --- Prompt: Fix post-refactor.ts to match the actual codegen output and handle all post-refactor edits.
1 parent 4c29ec1 commit 4976cfe

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

amplify-migration-apps/discussions/migration/post-refactor.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,40 @@
33
* Post-refactor script for discussions app.
44
*
55
* Applies manual edits required after `amplify gen2-migration refactor`:
6-
* 1. Add tableName to the DynamoDB table definition in backend.ts
7-
* This ensures the refactored table keeps its original name.
6+
* 1. Add tableName to DynamoDB table definitions in backend.ts
7+
* 2. Uncomment the S3 bucket name in backend.ts
88
*/
99

1010
import fs from 'fs/promises';
1111
import path from 'path';
1212

13-
async function addTableNameToActivityTable(appPath: string, envName: string): Promise<void> {
13+
async function uncommentTableNames(appPath: string, envName: string): Promise<void> {
1414
const backendPath = path.join(appPath, 'amplify', 'backend.ts');
15-
const content = await fs.readFile(backendPath, 'utf-8');
15+
let content = await fs.readFile(backendPath, 'utf-8');
1616

17-
const tableName = `activity-${envName}`;
17+
// Add tableName to activity table
18+
content = content.replace(
19+
/new Table\(storage\w+Stack,\s*['"]activity['"],\s*\{\s*partitionKey:/g,
20+
`new Table(storageActivityStack, 'activity', { tableName: 'activity-${envName}', partitionKey:`,
21+
);
22+
23+
// Add tableName to bookmarks table
24+
content = content.replace(
25+
/new Table\(storage\w+Stack,\s*['"]bookmarks['"],\s*\{\s*partitionKey:/g,
26+
`new Table(storageBookmarksStack, 'bookmarks', { tableName: 'bookmarks-${envName}', partitionKey:`,
27+
);
1828

19-
const updated = content.replace(
20-
/new Table\(storageStack,\s*["']activity["'],\s*\{\s*partitionKey:/g,
21-
`new Table(storageStack, "activity", { tableName: "${tableName}", partitionKey:`,
29+
// Uncomment S3 bucket name
30+
content = content.replace(
31+
/\/\/ (s3Bucket\.bucketName = '[^']+';)/,
32+
'$1',
2233
);
2334

24-
await fs.writeFile(backendPath, updated, 'utf-8');
35+
await fs.writeFile(backendPath, content, 'utf-8');
2536
}
2637

2738
export async function postRefactor(appPath: string, envName = 'main'): Promise<void> {
28-
await addTableNameToActivityTable(appPath, envName);
39+
await uncommentTableNames(appPath, envName);
2940
}
3041

3142
async function main(): Promise<void> {

0 commit comments

Comments
 (0)