Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allowlist comparison properties on imported table #2908

Merged
merged 15 commits into from
Oct 11, 2024
Merged
6 changes: 3 additions & 3 deletions packages/amplify-e2e-tests/schemas/references.graphql
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
type Primary @model @auth(rules: [{ allow: public }]) {
id: ID! @primaryKey
Copy link
Member Author

Choose a reason for hiding this comment

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

Just removing this to simplify the test case.

id: ID!
relatedMany: [RelatedMany] @hasMany(references: "primaryId")
relatedOne: RelatedOne @hasOne(references: "primaryId")
}

type RelatedMany @model @auth(rules: [{ allow: public }]) {
id: ID! @primaryKey
id: ID!
primaryId: String
primary: Primary @belongsTo(references: ["primaryId"])
}

type RelatedOne @model @auth(rules: [{ allow: public }]) {
id: ID! @primaryKey
id: ID!
primaryId: String
primary: Primary @belongsTo(references: ["primaryId"])
}
3 changes: 2 additions & 1 deletion packages/amplify-graphql-api-construct-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"private": true,
"scripts": {
"e2e": "jest --verbose --forceExit",
"e2e": "npm run setup-profile && jest --verbose --forceExit",
"setup-profile": "ts-node ../amplify-e2e-tests/src/configure_tests.ts",
"build-tests": "tsc --build tsconfig.tests.json"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Many-to-many Migration', () => {
/* No-op */
}
try {
// await cdkDestroy(gen2ProjRoot, '--all');
await cdkDestroy(gen2ProjRoot, '--all');
} catch (_) {
/* No-op */
}
Expand All @@ -42,7 +42,7 @@ describe('Many-to-many Migration', () => {
}

deleteProjectDir(gen1ProjRoot);
// deleteProjectDir(gen2ProjRoot);
deleteProjectDir(gen2ProjRoot);
});

test('many-to-many migration', async () => {
Expand Down Expand Up @@ -107,8 +107,12 @@ describe('Many-to-many Migration', () => {
import { AmplifyGraphqlApi } from '@aws-amplify/graphql-api-construct';

export const applyOverrides = (api: AmplifyGraphqlApi): void => {
const todoTable = api.resources.cfnResources.additionalCfnResources['Todo'];
todoTable.addOverride('Properties.sseSpecification', { sseEnabled: false });
const postTable = api.resources.cfnResources.additionalCfnResources['Post'];
const tagTable = api.resources.cfnResources.additionalCfnResources['Tag'];
const postTagsTable = api.resources.cfnResources.additionalCfnResources['PostTags'];
postTable.addOverride('Properties.sseSpecification', { sseEnabled: false });
tagTable.addOverride('Properties.sseSpecification', { sseEnabled: false });
postTagsTable.addOverride('Properties.sseSpecification', { sseEnabled: false });
};
`;
writeOverrides(overrides, gen2ProjRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ describe('Migration table import validation', () => {
'extraGSIOnGen2',
'',
[
'AttributeDefintions does not match the expected value.\nActual: [{"AttributeName":"id","AttributeType":"S"}]\nExpected: [{"AttributeType":"S","AttributeName":"id"},{"AttributeType":"S","AttributeName":"content"}]',
'GlobalSecondaryIndexes does not match the expected value.\nActual: undefined\nExpected: [{"IndexName":"todosByContent","KeySchema":[{"AttributeName":"content","KeyType":"HASH"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"WriteCapacityUnits":5,"ReadCapacityUnits":5}}]',
'AttributeDefinitions does not match the expected value.\nActual: [{"AttributeName":"id","AttributeType":"S"}]\nExpected: [{"AttributeType":"S","AttributeName":"id"},{"AttributeType":"S","AttributeName":"content"}]',
'GlobalSecondaryIndexes does not match the expected value.\nActual: undefined\nExpected: [{"IndexName":"todosByContent","KeySchema":[{"AttributeName":"content","KeyType":"HASH"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"ReadCapacityUnits":0,"WriteCapacityUnits":0}}]',
],
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('References Migration', () => {
Primary: {
schema: /* GraphQL */ `
type Primary @model @auth(rules: [{ allow: public }]) {
id: ID! @primaryKey
id: ID!
relatedMany: [RelatedMany] @hasMany(references: "primaryId")
relatedOne: RelatedOne @hasOne(references: "primaryId")
}
Expand All @@ -72,7 +72,7 @@ describe('References Migration', () => {
RelatedMany: {
schema: /* GraphQL */ `
type RelatedMany @model @auth(rules: [{ allow: public }]) {
id: ID! @primaryKey
id: ID!
primaryId: String
primary: Primary @belongsTo(references: ["primaryId"])
}
Expand All @@ -86,7 +86,7 @@ describe('References Migration', () => {
RelatedOne: {
schema: /* GraphQL */ `
type RelatedOne @model @auth(rules: [{ allow: public }]) {
id: ID! @primaryKey
id: ID!
primaryId: String
primary: Primary @belongsTo(references: ["primaryId"])
}
Expand All @@ -105,8 +105,12 @@ describe('References Migration', () => {
import { AmplifyGraphqlApi } from '@aws-amplify/graphql-api-construct';

export const applyOverrides = (api: AmplifyGraphqlApi): void => {
const todoTable = api.resources.cfnResources.additionalCfnResources['Todo'];
todoTable.addOverride('Properties.sseSpecification', { sseEnabled: false });
const primaryTable = api.resources.cfnResources.additionalCfnResources['Primary'];
const relatedManyTable = api.resources.cfnResources.additionalCfnResources['RelatedMany'];
const relatedOneTable = api.resources.cfnResources.additionalCfnResources['RelatedOne'];
primaryTable.addOverride('Properties.sseSpecification', { sseEnabled: false });
relatedManyTable.addOverride('Properties.sseSpecification', { sseEnabled: false });
relatedOneTable.addOverride('Properties.sseSpecification', { sseEnabled: false });
};
`;
writeOverrides(overrides, gen2ProjRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { copySync, moveSync, readFileSync, writeFileSync } from 'fs-extra';
import {
addApiWithoutSchema,
amplifyPush,
amplifyPushForce,
getProjectMeta,
getScriptRunnerPath,
initJSProjectWithProfile,
nspawn as spawn,
sleep,
updateApiSchema,
addFeatureFlag,
} from 'amplify-category-api-e2e-core';
import { DynamoDBClient, DeleteTableCommand } from '@aws-sdk/client-dynamodb';

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

// TODO: can't use feature flag until released in CLI
// The test should do a second push after enabling the feature flag to start the migration
// Add the feature flag and push before merging to main.
// addFeatureFlag(projRoot, 'graphqltransformer', 'enableGen2Migration', true);
// await amplifyPush(projRoot);
addFeatureFlag(projRoot, 'graphqltransformer', 'enablegen2migration', true);
await amplifyPushForce(projRoot);

const meta = getProjectMeta(projRoot);
const { output } = meta.api[name];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,66 +583,3 @@ Object {
},
}
`;

exports[`Custom Resource Lambda Tests getExpectedTableProperties 1`] = `
Object {
"AttributeDefinitions": Array [
Object {
"AttributeName": "todoId",
"AttributeType": "S",
},
Object {
"AttributeName": "name",
"AttributeType": "S",
},
Object {
"AttributeName": "name2",
"AttributeType": "S",
},
],
"BillingModeSummary": Object {
"BillingMode": "PROVISIONED",
},
"DeletionProtectionEnabled": false,
"GlobalSecondaryIndexes": Array [
Object {
"IndexName": "byName2",
"KeySchema": Array [
Object {
"AttributeName": "name2",
"KeyType": "HASH",
},
],
"Projection": Object {
"ProjectionType": "ALL",
},
"ProvisionedThroughput": Object {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5,
},
},
],
"KeySchema": Array [
Object {
"AttributeName": "todoId",
"KeyType": "HASH",
},
Object {
"AttributeName": "name",
"KeyType": "RANGE",
},
],
"ProvisionedThroughput": Object {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5,
},
"SSEDescription": Object {
"SSEType": "KMS",
"Status": "ENABLED",
},
"StreamSpecification": Object {
"StreamEnabled": true,
"StreamViewType": "NEW_AND_OLD_IMAGES",
},
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`import-table getExpectedTableProperties 1`] = `
Object {
"AttributeDefinitions": Array [
Object {
"AttributeName": "todoId",
"AttributeType": "S",
},
Object {
"AttributeName": "name",
"AttributeType": "S",
},
Object {
"AttributeName": "name2",
"AttributeType": "S",
},
],
"BillingModeSummary": Object {
"BillingMode": "PROVISIONED",
},
"DeletionProtectionEnabled": false,
"GlobalSecondaryIndexes": Array [
Object {
"IndexName": "byName2",
"KeySchema": Array [
Object {
"AttributeName": "name2",
"KeyType": "HASH",
},
],
"Projection": Object {
"ProjectionType": "ALL",
},
"ProvisionedThroughput": Object {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5,
},
},
],
"KeySchema": Array [
Object {
"AttributeName": "todoId",
"KeyType": "HASH",
},
Object {
"AttributeName": "name",
"KeyType": "RANGE",
},
],
"ProvisionedThroughput": Object {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5,
},
"SSEDescription": Object {
"SSEType": "KMS",
"Status": "ENABLED",
},
"StreamSpecification": Object {
"StreamEnabled": true,
"StreamViewType": "NEW_AND_OLD_IMAGES",
},
}
`;
Loading
Loading