Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions migration_release.md

This file was deleted.

2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
"@types/ini": "^1.3.31"
},
"peerDependencies": {
"@aws-amplify/amplify-cli-core": "^4.3.9"
"@aws-amplify/amplify-cli-core": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/amplify-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"yargs": "^15.1.0"
},
"peerDependencies": {
"@aws-amplify/amplify-cli-core": "^4.3.9"
"@aws-amplify/amplify-cli-core": "^4.4.0"
},
"devDependencies": {
"@aws-amplify/graphql-transformer-interfaces": "4.2.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ws": "^8.18.0"
},
"peerDependencies": {
"@aws-amplify/amplify-cli-core": "^4.3.9"
"@aws-amplify/amplify-cli-core": "^4.4.0"
},
"devDependencies": {
"@aws-amplify/graphql-transformer-core": "3.4.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,30 +161,24 @@ describe('Migration with basic schema', () => {
await deleteProject(gen1ProjRoot);

// assert tables have not been deleted after deleting the gen 1 project
const listResult = await graphql(
gen2APIEndpoint,
gen2APIKey,
/* GraphQL */ `
query LIST_TODOS {
listTodos {
items {
id
content
}
}
}
`,
);

// TODO: GEN1_GEN2_MIGRATION
// The enablegen2migration feature flag is not released yet so the tables will be deleted when the gen 1 app is deleted
// Restore this block when the feature flag is released
// start block
// const listResult = await graphql(
// gen2APIEndpoint,
// gen2APIKey,
// /* GraphQL */ `
// query LIST_TODOS {
// listTodos {
// items {
// id
// content
// }
// }
// }
// `,
// );

// expect(listResult.statusCode).toEqual(200);
// expect(listResult.body.data.listTodos.items.length).toEqual(2);
// expect([gen1Todo.id, gen2Todo.id]).toContain(listResult.body.data.listTodos.items[0].id);
// expect([gen1Todo.id, gen2Todo.id]).toContain(listResult.body.data.listTodos.items[1].id);
// end block
expect(listResult.statusCode).toEqual(200);
expect(listResult.body.data.listTodos.items.length).toEqual(2);
expect([gen1Todo.id, gen2Todo.id]).toContain(listResult.body.data.listTodos.items[0].id);
expect([gen1Todo.id, gen2Todo.id]).toContain(listResult.body.data.listTodos.items[1].id);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -272,35 +272,30 @@ describe('Many-to-many Migration', () => {

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

// TODO: GEN1_GEN2_MIGRATION
// The enablegen2migration feature flag is not released yet so the tables will be deleted when the gen 1 app is deleted
// Restore this block when the feature flag is released
// start block
// const listResult = await graphql(
// gen2APIEndpoint,
// gen2APIKey,
// /* GraphQL */ `
// query LIST_POSTS {
// listPosts {
// items {
// id
// tags {
// items {
// id
// }
// }
// }
// }
// }
// `,
// );
const listResult = await graphql(
gen2APIEndpoint,
gen2APIKey,
/* GraphQL */ `
query LIST_POSTS {
listPosts {
items {
id
tags {
items {
id
}
}
}
}
}
`,
);

// expect(listResult.statusCode).toEqual(200);
// expect(listResult.body.data.listPosts.items.length).toEqual(2);
// expect([gen1Post.id, gen2Post.id]).toContain(listResult.body.data.listPosts.items[0].id);
// expect([gen1Post.id, gen2Post.id]).toContain(listResult.body.data.listPosts.items[1].id);
// expect(listResult.body.data.listPosts.items[0].tags.items.length).toEqual(1);
// expect(listResult.body.data.listPosts.items[1].tags.items.length).toEqual(1);
// end block
expect(listResult.statusCode).toEqual(200);
expect(listResult.body.data.listPosts.items.length).toEqual(2);
expect([gen1Post.id, gen2Post.id]).toContain(listResult.body.data.listPosts.items[0].id);
expect([gen1Post.id, gen2Post.id]).toContain(listResult.body.data.listPosts.items[1].id);
expect(listResult.body.data.listPosts.items[0].tags.items.length).toEqual(1);
expect(listResult.body.data.listPosts.items[1].tags.items.length).toEqual(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -280,47 +280,42 @@ describe('References Migration', () => {

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

// TODO: GEN1_GEN2_MIGRATION
// The enablegen2migration feature flag is not released yet so the tables will be deleted when the gen 1 app is deleted
// Restore this block when the feature flag is released
// start block
// const listResult = await graphql(
// gen2APIEndpoint,
// gen2APIKey,
// /* GraphQL */ `
// query LIST_PRIMARY {
// listPrimaries {
// items {
// id
// relatedMany {
// items {
// id
// primaryId
// }
// nextToken
// }
// relatedOne {
// id
// primaryId
// primary {
// id
// }
// }
// }
// nextToken
// }
// }
// `,
// );
const listResult = await graphql(
gen2APIEndpoint,
gen2APIKey,
/* GraphQL */ `
query LIST_PRIMARY {
listPrimaries {
items {
id
relatedMany {
items {
id
primaryId
}
nextToken
}
relatedOne {
id
primaryId
primary {
id
}
}
}
nextToken
}
}
`,
);

// expect(listResult.statusCode).toEqual(200);
// expect(listResult.body.data.listPrimaries.items.length).toEqual(2);
// expect([gen1Primary.id, gen2Primary.id]).toContain(listResult.body.data.listPrimaries.items[0].id);
// expect([gen1Primary.id, gen2Primary.id]).toContain(listResult.body.data.listPrimaries.items[1].id);
// expect(listResult.body.data.listPrimaries.items[0].relatedMany.items.length).toEqual(1);
// expect(listResult.body.data.listPrimaries.items[1].relatedMany.items.length).toEqual(1);
// expect(listResult.body.data.listPrimaries.items[0].relatedOne).toBeDefined();
// expect(listResult.body.data.listPrimaries.items[1].relatedOne).toBeDefined();
// end block
expect(listResult.statusCode).toEqual(200);
expect(listResult.body.data.listPrimaries.items.length).toEqual(2);
expect([gen1Primary.id, gen2Primary.id]).toContain(listResult.body.data.listPrimaries.items[0].id);
expect([gen1Primary.id, gen2Primary.id]).toContain(listResult.body.data.listPrimaries.items[1].id);
expect(listResult.body.data.listPrimaries.items[0].relatedMany.items.length).toEqual(1);
expect(listResult.body.data.listPrimaries.items[1].relatedMany.items.length).toEqual(1);
expect(listResult.body.data.listPrimaries.items[0].relatedOne).toBeDefined();
expect(listResult.body.data.listPrimaries.items[1].relatedOne).toBeDefined();
});
});
55 changes: 5 additions & 50 deletions packages/amplify-graphql-api-construct-tests/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
nspawn as spawn,
sleep,
updateApiSchema,
addFeatureFlag,
amplifyPushForce,
} from 'amplify-category-api-e2e-core';
import { DynamoDBClient, DeleteTableCommand, ListTablesCommand, UpdateTableCommand } from '@aws-sdk/client-dynamodb';

Expand Down Expand Up @@ -189,58 +191,13 @@ export const createGen1ProjectForMigration = async (
await updateApiSchema(projRoot, name, schema);
await amplifyPush(projRoot);

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

const meta = getProjectMeta(projRoot);
const { output } = meta.api[name];
const {
GraphQLAPIEndpointOutput,
GraphQLAPIKeyOutput,
GraphQLAPIIdOutput,
// TODO: GEN1_GEN2_MIGRATION
// get DataSourceMappingOutput from output when feature flag is released
// uncomment the line below
// DataSourceMappingOutput,
} = output;

// TODO: GEN1_GEN2_MIGRATION
// Construct the DataSourceMappingOutput with the AWS SDK
// Set table deletion protection to true for all tables
// Remove this block when the feature flag is released
// Start block
const client = new DynamoDBClient({ region: process.env.CLI_REGION || 'us-west-2' });
const tables = [];
let ExclusiveStartTableName;
do {
const command = new ListTablesCommand({ ExclusiveStartTableName });
const response = await client.send(command);
ExclusiveStartTableName = response.LastEvaluatedTableName;
tables.push(...response.TableNames);
} while (ExclusiveStartTableName);
const tablesForApi = tables
// filter all tables by the API ID
.filter((tableName) => tableName.includes(GraphQLAPIIdOutput));

const tableNameMapping = tablesForApi
// extract the model name from the table name and create the mapping
.map((tableName) => [tableName.match(/(^.*?)-/)[1], tableName]);
const DataSourceMappingOutput = JSON.stringify(Object.fromEntries(tableNameMapping));

// set deletion protection to true for all tables
await Promise.allSettled(
tablesForApi.map((tableName) => client.send(new UpdateTableCommand({ TableName: tableName, DeletionProtectionEnabled: true }))),
);
// End block
const { GraphQLAPIEndpointOutput, GraphQLAPIKeyOutput, DataSourceMappingOutput } = output;

return {
GraphQLAPIEndpointOutput,
Expand All @@ -256,12 +213,10 @@ export const createGen1ProjectForMigration = async (
*/
export const deleteDDBTables = async (tableNames: string[]): Promise<void> => {
const client = new DynamoDBClient({ region: process.env.CLI_REGION || 'us-west-2' });
// TODO: GEN1_GEN2_MIGRATION
// disable deletion protection before deleting the tables
// start block
// deletion protection is enabled for migrated tables
// disable deletion protection to teardown the tests
await Promise.allSettled(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually need this block because the tables will still have deletion protection when tearing down the test.

tableNames.map((tableName) => client.send(new UpdateTableCommand({ TableName: tableName, DeletionProtectionEnabled: false }))),
);
// end block
await Promise.allSettled(tableNames.map((tableName) => client.send(new DeleteTableCommand({ TableName: tableName }))));
};
Loading
Loading