Skip to content

Commit 97f9ccb

Browse files
author
Dane Pilcher
authored
chore: prep migrations release (#3169)
1 parent d5e9428 commit 97f9ccb

17 files changed

Lines changed: 157 additions & 377 deletions

File tree

migration_release.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/amplify-e2e-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
"@types/ini": "^1.3.31"
5757
},
5858
"peerDependencies": {
59-
"@aws-amplify/amplify-cli-core": "^4.3.9"
59+
"@aws-amplify/amplify-cli-core": "^4.4.0"
6060
}
6161
}

packages/amplify-e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"yargs": "^15.1.0"
5050
},
5151
"peerDependencies": {
52-
"@aws-amplify/amplify-cli-core": "^4.3.9"
52+
"@aws-amplify/amplify-cli-core": "^4.4.0"
5353
},
5454
"devDependencies": {
5555
"@aws-amplify/graphql-transformer-interfaces": "4.2.5",

packages/amplify-graphql-api-construct-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"ws": "^8.18.0"
4646
},
4747
"peerDependencies": {
48-
"@aws-amplify/amplify-cli-core": "^4.3.9"
48+
"@aws-amplify/amplify-cli-core": "^4.4.0"
4949
},
5050
"devDependencies": {
5151
"@aws-amplify/graphql-transformer-core": "3.4.2",

packages/amplify-graphql-api-construct-tests/src/__tests__/migration/base-migration.test.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -161,30 +161,24 @@ describe('Migration with basic schema', () => {
161161
await deleteProject(gen1ProjRoot);
162162

163163
// assert tables have not been deleted after deleting the gen 1 project
164+
const listResult = await graphql(
165+
gen2APIEndpoint,
166+
gen2APIKey,
167+
/* GraphQL */ `
168+
query LIST_TODOS {
169+
listTodos {
170+
items {
171+
id
172+
content
173+
}
174+
}
175+
}
176+
`,
177+
);
164178

165-
// TODO: GEN1_GEN2_MIGRATION
166-
// The enablegen2migration feature flag is not released yet so the tables will be deleted when the gen 1 app is deleted
167-
// Restore this block when the feature flag is released
168-
// start block
169-
// const listResult = await graphql(
170-
// gen2APIEndpoint,
171-
// gen2APIKey,
172-
// /* GraphQL */ `
173-
// query LIST_TODOS {
174-
// listTodos {
175-
// items {
176-
// id
177-
// content
178-
// }
179-
// }
180-
// }
181-
// `,
182-
// );
183-
184-
// expect(listResult.statusCode).toEqual(200);
185-
// expect(listResult.body.data.listTodos.items.length).toEqual(2);
186-
// expect([gen1Todo.id, gen2Todo.id]).toContain(listResult.body.data.listTodos.items[0].id);
187-
// expect([gen1Todo.id, gen2Todo.id]).toContain(listResult.body.data.listTodos.items[1].id);
188-
// end block
179+
expect(listResult.statusCode).toEqual(200);
180+
expect(listResult.body.data.listTodos.items.length).toEqual(2);
181+
expect([gen1Todo.id, gen2Todo.id]).toContain(listResult.body.data.listTodos.items[0].id);
182+
expect([gen1Todo.id, gen2Todo.id]).toContain(listResult.body.data.listTodos.items[1].id);
189183
});
190184
});

packages/amplify-graphql-api-construct-tests/src/__tests__/migration/many-to-many-migration.test.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -272,35 +272,30 @@ describe('Many-to-many Migration', () => {
272272

273273
// assert tables have not been deleted after deleting the gen 1 project
274274

275-
// TODO: GEN1_GEN2_MIGRATION
276-
// The enablegen2migration feature flag is not released yet so the tables will be deleted when the gen 1 app is deleted
277-
// Restore this block when the feature flag is released
278-
// start block
279-
// const listResult = await graphql(
280-
// gen2APIEndpoint,
281-
// gen2APIKey,
282-
// /* GraphQL */ `
283-
// query LIST_POSTS {
284-
// listPosts {
285-
// items {
286-
// id
287-
// tags {
288-
// items {
289-
// id
290-
// }
291-
// }
292-
// }
293-
// }
294-
// }
295-
// `,
296-
// );
275+
const listResult = await graphql(
276+
gen2APIEndpoint,
277+
gen2APIKey,
278+
/* GraphQL */ `
279+
query LIST_POSTS {
280+
listPosts {
281+
items {
282+
id
283+
tags {
284+
items {
285+
id
286+
}
287+
}
288+
}
289+
}
290+
}
291+
`,
292+
);
297293

298-
// expect(listResult.statusCode).toEqual(200);
299-
// expect(listResult.body.data.listPosts.items.length).toEqual(2);
300-
// expect([gen1Post.id, gen2Post.id]).toContain(listResult.body.data.listPosts.items[0].id);
301-
// expect([gen1Post.id, gen2Post.id]).toContain(listResult.body.data.listPosts.items[1].id);
302-
// expect(listResult.body.data.listPosts.items[0].tags.items.length).toEqual(1);
303-
// expect(listResult.body.data.listPosts.items[1].tags.items.length).toEqual(1);
304-
// end block
294+
expect(listResult.statusCode).toEqual(200);
295+
expect(listResult.body.data.listPosts.items.length).toEqual(2);
296+
expect([gen1Post.id, gen2Post.id]).toContain(listResult.body.data.listPosts.items[0].id);
297+
expect([gen1Post.id, gen2Post.id]).toContain(listResult.body.data.listPosts.items[1].id);
298+
expect(listResult.body.data.listPosts.items[0].tags.items.length).toEqual(1);
299+
expect(listResult.body.data.listPosts.items[1].tags.items.length).toEqual(1);
305300
});
306301
});

packages/amplify-graphql-api-construct-tests/src/__tests__/migration/references-migration.test.ts

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -280,47 +280,42 @@ describe('References Migration', () => {
280280

281281
// assert tables have not been deleted after deleting the gen 1 project
282282

283-
// TODO: GEN1_GEN2_MIGRATION
284-
// The enablegen2migration feature flag is not released yet so the tables will be deleted when the gen 1 app is deleted
285-
// Restore this block when the feature flag is released
286-
// start block
287-
// const listResult = await graphql(
288-
// gen2APIEndpoint,
289-
// gen2APIKey,
290-
// /* GraphQL */ `
291-
// query LIST_PRIMARY {
292-
// listPrimaries {
293-
// items {
294-
// id
295-
// relatedMany {
296-
// items {
297-
// id
298-
// primaryId
299-
// }
300-
// nextToken
301-
// }
302-
// relatedOne {
303-
// id
304-
// primaryId
305-
// primary {
306-
// id
307-
// }
308-
// }
309-
// }
310-
// nextToken
311-
// }
312-
// }
313-
// `,
314-
// );
283+
const listResult = await graphql(
284+
gen2APIEndpoint,
285+
gen2APIKey,
286+
/* GraphQL */ `
287+
query LIST_PRIMARY {
288+
listPrimaries {
289+
items {
290+
id
291+
relatedMany {
292+
items {
293+
id
294+
primaryId
295+
}
296+
nextToken
297+
}
298+
relatedOne {
299+
id
300+
primaryId
301+
primary {
302+
id
303+
}
304+
}
305+
}
306+
nextToken
307+
}
308+
}
309+
`,
310+
);
315311

316-
// expect(listResult.statusCode).toEqual(200);
317-
// expect(listResult.body.data.listPrimaries.items.length).toEqual(2);
318-
// expect([gen1Primary.id, gen2Primary.id]).toContain(listResult.body.data.listPrimaries.items[0].id);
319-
// expect([gen1Primary.id, gen2Primary.id]).toContain(listResult.body.data.listPrimaries.items[1].id);
320-
// expect(listResult.body.data.listPrimaries.items[0].relatedMany.items.length).toEqual(1);
321-
// expect(listResult.body.data.listPrimaries.items[1].relatedMany.items.length).toEqual(1);
322-
// expect(listResult.body.data.listPrimaries.items[0].relatedOne).toBeDefined();
323-
// expect(listResult.body.data.listPrimaries.items[1].relatedOne).toBeDefined();
324-
// end block
312+
expect(listResult.statusCode).toEqual(200);
313+
expect(listResult.body.data.listPrimaries.items.length).toEqual(2);
314+
expect([gen1Primary.id, gen2Primary.id]).toContain(listResult.body.data.listPrimaries.items[0].id);
315+
expect([gen1Primary.id, gen2Primary.id]).toContain(listResult.body.data.listPrimaries.items[1].id);
316+
expect(listResult.body.data.listPrimaries.items[0].relatedMany.items.length).toEqual(1);
317+
expect(listResult.body.data.listPrimaries.items[1].relatedMany.items.length).toEqual(1);
318+
expect(listResult.body.data.listPrimaries.items[0].relatedOne).toBeDefined();
319+
expect(listResult.body.data.listPrimaries.items[1].relatedOne).toBeDefined();
325320
});
326321
});

packages/amplify-graphql-api-construct-tests/src/commands.ts

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
nspawn as spawn,
1111
sleep,
1212
updateApiSchema,
13+
addFeatureFlag,
14+
amplifyPushForce,
1315
} from 'amplify-category-api-e2e-core';
1416
import { DynamoDBClient, DeleteTableCommand, ListTablesCommand, UpdateTableCommand } from '@aws-sdk/client-dynamodb';
1517

@@ -189,58 +191,13 @@ export const createGen1ProjectForMigration = async (
189191
await updateApiSchema(projRoot, name, schema);
190192
await amplifyPush(projRoot);
191193

192-
// The test should do a second push after enabling the feature flag to start the migration
193-
// TODO: GEN1_GEN2_MIGRATION
194-
// The Gen 1 CLI has not released this feature flag yet
195-
// In the meantime, manually create the data source mapping
196-
// restore this block when the feature flag is released
197-
// Start block
198-
/*
199194
addFeatureFlag(projRoot, 'graphqltransformer', 'enablegen2migration', true);
200195
await amplifyPushForce(projRoot);
201-
*/
202-
// End block
203196

204197
const meta = getProjectMeta(projRoot);
205198
const { output } = meta.api[name];
206-
const {
207-
GraphQLAPIEndpointOutput,
208-
GraphQLAPIKeyOutput,
209-
GraphQLAPIIdOutput,
210-
// TODO: GEN1_GEN2_MIGRATION
211-
// get DataSourceMappingOutput from output when feature flag is released
212-
// uncomment the line below
213-
// DataSourceMappingOutput,
214-
} = output;
215-
216-
// TODO: GEN1_GEN2_MIGRATION
217-
// Construct the DataSourceMappingOutput with the AWS SDK
218-
// Set table deletion protection to true for all tables
219-
// Remove this block when the feature flag is released
220-
// Start block
221-
const client = new DynamoDBClient({ region: process.env.CLI_REGION || 'us-west-2' });
222-
const tables = [];
223-
let ExclusiveStartTableName;
224-
do {
225-
const command = new ListTablesCommand({ ExclusiveStartTableName });
226-
const response = await client.send(command);
227-
ExclusiveStartTableName = response.LastEvaluatedTableName;
228-
tables.push(...response.TableNames);
229-
} while (ExclusiveStartTableName);
230-
const tablesForApi = tables
231-
// filter all tables by the API ID
232-
.filter((tableName) => tableName.includes(GraphQLAPIIdOutput));
233199

234-
const tableNameMapping = tablesForApi
235-
// extract the model name from the table name and create the mapping
236-
.map((tableName) => [tableName.match(/(^.*?)-/)[1], tableName]);
237-
const DataSourceMappingOutput = JSON.stringify(Object.fromEntries(tableNameMapping));
238-
239-
// set deletion protection to true for all tables
240-
await Promise.allSettled(
241-
tablesForApi.map((tableName) => client.send(new UpdateTableCommand({ TableName: tableName, DeletionProtectionEnabled: true }))),
242-
);
243-
// End block
200+
const { GraphQLAPIEndpointOutput, GraphQLAPIKeyOutput, DataSourceMappingOutput } = output;
244201

245202
return {
246203
GraphQLAPIEndpointOutput,
@@ -256,12 +213,10 @@ export const createGen1ProjectForMigration = async (
256213
*/
257214
export const deleteDDBTables = async (tableNames: string[]): Promise<void> => {
258215
const client = new DynamoDBClient({ region: process.env.CLI_REGION || 'us-west-2' });
259-
// TODO: GEN1_GEN2_MIGRATION
260-
// disable deletion protection before deleting the tables
261-
// start block
216+
// deletion protection is enabled for migrated tables
217+
// disable deletion protection to teardown the tests
262218
await Promise.allSettled(
263219
tableNames.map((tableName) => client.send(new UpdateTableCommand({ TableName: tableName, DeletionProtectionEnabled: false }))),
264220
);
265-
// end block
266221
await Promise.allSettled(tableNames.map((tableName) => client.send(new DeleteTableCommand({ TableName: tableName }))));
267222
};

0 commit comments

Comments
 (0)