@@ -10,6 +10,8 @@ import {
1010 nspawn as spawn ,
1111 sleep ,
1212 updateApiSchema ,
13+ addFeatureFlag ,
14+ amplifyPushForce ,
1315} from 'amplify-category-api-e2e-core' ;
1416import { 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 */
257214export 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