|
3 | 3 | * Post-refactor script for discussions app. |
4 | 4 | * |
5 | 5 | * 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 |
8 | 8 | */ |
9 | 9 |
|
10 | 10 | import fs from 'fs/promises'; |
11 | 11 | import path from 'path'; |
12 | 12 |
|
13 | | -async function addTableNameToActivityTable(appPath: string, envName: string): Promise<void> { |
| 13 | +async function uncommentTableNames(appPath: string, envName: string): Promise<void> { |
14 | 14 | 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'); |
16 | 16 |
|
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 | + ); |
18 | 28 |
|
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', |
22 | 33 | ); |
23 | 34 |
|
24 | | - await fs.writeFile(backendPath, updated, 'utf-8'); |
| 35 | + await fs.writeFile(backendPath, content, 'utf-8'); |
25 | 36 | } |
26 | 37 |
|
27 | 38 | export async function postRefactor(appPath: string, envName = 'main'): Promise<void> { |
28 | | - await addTableNameToActivityTable(appPath, envName); |
| 39 | + await uncommentTableNames(appPath, envName); |
29 | 40 | } |
30 | 41 |
|
31 | 42 | async function main(): Promise<void> { |
|
0 commit comments