Skip to content

Commit

Permalink
Revert "feat: get datasource map for migration (#2668)"
Browse files Browse the repository at this point in the history
This reverts commit 02c7da0.
  • Loading branch information
dpilch committed Sep 25, 2024
1 parent 2a64485 commit 2edca25
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 151 deletions.
22 changes: 11 additions & 11 deletions packages/amplify-graphql-api-construct/.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -4433,7 +4433,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 287
"line": 286
},
"name": "addDynamoDbDataSource",
"parameters": [
Expand Down Expand Up @@ -4482,7 +4482,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 299
"line": 298
},
"name": "addElasticsearchDataSource",
"parameters": [
Expand Down Expand Up @@ -4529,7 +4529,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 309
"line": 308
},
"name": "addEventBridgeDataSource",
"parameters": [
Expand Down Expand Up @@ -4576,7 +4576,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 391
"line": 390
},
"name": "addFunction",
"parameters": [
Expand Down Expand Up @@ -4611,7 +4611,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 320
"line": 319
},
"name": "addHttpDataSource",
"parameters": [
Expand Down Expand Up @@ -4659,7 +4659,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 331
"line": 330
},
"name": "addLambdaDataSource",
"parameters": [
Expand Down Expand Up @@ -4707,7 +4707,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 342
"line": 341
},
"name": "addNoneDataSource",
"parameters": [
Expand Down Expand Up @@ -4746,7 +4746,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 353
"line": 352
},
"name": "addOpenSearchDataSource",
"parameters": [
Expand Down Expand Up @@ -4794,7 +4794,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 366
"line": 365
},
"name": "addRdsDataSource",
"parameters": [
Expand Down Expand Up @@ -4861,7 +4861,7 @@
},
"locationInModule": {
"filename": "src/amplify-graphql-api.ts",
"line": 382
"line": 381
},
"name": "addResolver",
"parameters": [
Expand Down Expand Up @@ -8960,5 +8960,5 @@
}
},
"version": "1.13.0",
"fingerprint": "SvUg/laowa+2kCDSW7tShjvINY9o1V4/u3HBb9mcdYA="
"fingerprint": "GVOegrfILHqK5KKiknuL6p+fkV96vEguqRKbwXKS36g="
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export class AmplifyGraphqlApi extends Construct {
const transformParameters = {
...defaultTranslationBehavior,
...(translationBehavior ?? {}),
enableGen2Migration: false,
allowGen1Patterns: false,
};
const executeTransformConfig: ExecuteTransformConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@aws-amplify/graphql-transformer-core';
import { InputObjectTypeDefinitionNode, InputValueDefinitionNode, NamedTypeNode, parse } from 'graphql';
import { getBaseType } from 'graphql-transformer-common';
import { Template, Match } from 'aws-cdk-lib/assertions';
import { Template } from 'aws-cdk-lib/assertions';
import { testTransform } from '@aws-amplify/graphql-transformer-test-utils';
import { PrimaryKeyTransformer } from '@aws-amplify/graphql-index-transformer';
import { VpcConfig, ModelDataSourceStrategySqlDbType, SQLLambdaModelDataSourceStrategy } from '@aws-amplify/graphql-transformer-interfaces';
Expand Down Expand Up @@ -2316,99 +2316,4 @@ describe('ModelTransformer:', () => {
expect(directiveNames).toContain('aws_iam');
});
});

describe('migration', () => {
it('should output data source mapping', async () => {
const validSchema = `
type Post @model {
id: ID!
title: String!
}
`;

const out = testTransform({
schema: validSchema,
transformers: [new ModelTransformer()],
transformParameters: {
enableGen2Migration: true,
},
});
expect(out).toBeDefined();
const template = Template.fromJSON(out.rootStack);
template.hasOutput('DataSourceMappingOutput', {
Value: Match.objectLike({
'Fn::Join': [
'',
[
'{"Post":"',
{
'Fn::GetAtt': ['Post', 'Outputs.transformerrootstackPostPostTable34CAE87BRef'],
},
'"}',
],
],
}),
Description: 'Mapping of model name to data source table name.',
});
});

it('should set table removal policy to retain', () => {
const validSchema = `
type Post @model {
id: ID!
title: String!
}
`;

const out = testTransform({
schema: validSchema,
transformers: [new ModelTransformer()],
transformParameters: {
enableGen2Migration: true,
},
});
expect(out).toBeDefined();
const postStack = out.stacks['Post'];
const template = Template.fromJSON(postStack);
template.hasResource('AWS::DynamoDB::Table', {
DeletionPolicy: 'Retain',
Properties: {
TableName: {
'Fn::Join': [
'',
[
'Post-',
{
Ref: 'referencetotransformerrootstackGraphQLAPI20497F53ApiId',
},
'-',
{
Ref: 'referencetotransformerrootstackenv10C5A902Ref',
},
],
],
},
},
});
});

describe('does not add SQL data sources to mapping', () => {
test.each(sqlDatasources)('%s', (dbType) => {
const validSchema = `
type Post @model {
id: ID! @primaryKey
title: String!
}
`;

const out = testTransform({
schema: validSchema,
transformers: [new ModelTransformer(), new PrimaryKeyTransformer()],
dataSourceStrategies: constructDataSourceStrategies(validSchema, makeStrategy(dbType)),
});
expect(out).toBeDefined();
expect(out.rootStack.Outputs?.DataSourceMappingOutput).toBeUndefined();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
TransformerTransformSchemaStepContextProvider,
TransformerValidationStepContextProvider,
DataSourceStrategiesProvider,
DataSourceProvider,
} from '@aws-amplify/graphql-transformer-interfaces';
import { ModelDirective } from '@aws-amplify/graphql-directives';
import { ITable } from 'aws-cdk-lib/aws-dynamodb';
Expand Down Expand Up @@ -326,31 +325,9 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
};

generateResolvers = (context: TransformerContextProvider): void => {
const dataSourceMapping: Record<string, string> = {};
this.resourceGeneratorMap.forEach((generator) => {
generator.generateResources(context);
const ddbDatasources = Object.entries(generator.getDatasourceMap()).filter(
([, datasource]) => datasource.ds.type === 'AMAZON_DYNAMODB',
);
ddbDatasources.forEach(([modelName, datasource]) => {
if (datasource.ds.dynamoDbConfig && !cdk.isResolvableObject(datasource.ds.dynamoDbConfig)) {
dataSourceMapping[modelName] = datasource.ds.dynamoDbConfig.tableName;
}
// TODO: probably need a link to docs for this
console.warn(
`Could not resolve table name for ${modelName}. DataSourceMappingOutput is incomplete. Please manually add ${modelName} to the mapping for your migration.`,
);
});
});
if (context.transformParameters.enableGen2Migration && context.transformParameters.enableTransformerCfnOutputs) {
const { scope } = context.stackManager;
// TODO: decide final naming before merge to main
new cdk.CfnOutput(cdk.Stack.of(scope), 'DataSourceMappingOutput', {
value: cdk.Stack.of(scope).toJsonString(dataSourceMapping),
description: 'Mapping of model name to data source table name.',
exportName: cdk.Fn.join(':', [cdk.Aws.STACK_NAME, 'DataSourceMappingOutput']),
});
}
};

generateGetResolver = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
expression: cdk.Fn.conditionEquals(pointInTimeRecovery, 'true'),
});

const removalPolicy =
this.options.EnableDeletionProtection || context.transformParameters.enableGen2Migration
? cdk.RemovalPolicy.RETAIN
: cdk.RemovalPolicy.DESTROY;
const removalPolicy = this.options.EnableDeletionProtection ? cdk.RemovalPolicy.RETAIN : cdk.RemovalPolicy.DESTROY;

// Expose a way in context to allow proper resource naming
const table = new Table(scope, tableLogicalName, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,4 @@ export abstract class ModelResourceGenerator {

return fields;
};

getDatasourceMap(): Record<string, DataSourceProvider> {
return this.datasourceMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ export const defaultTransformParameters: TransformParameters = {

// Search Params
enableSearchNodeToNodeEncryption: false,

// Migration
enableGen2Migration: false,
};
1 change: 0 additions & 1 deletion packages/amplify-graphql-transformer-interfaces/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,6 @@ export type TransformParameters = {
enableAutoIndexQueryNames: boolean;
respectPrimaryKeyAttributesOnConnectionField: boolean;
enableSearchNodeToNodeEncryption: boolean;
enableGen2Migration: boolean;
};

// @public (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@ export type TransformParameters = {

// Search Params
enableSearchNodeToNodeEncryption: boolean;

// Migration
enableGen2Migration: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const defaultTransformConfig: TransformConfig = {
allowDestructiveGraphqlSchemaUpdates: false,
replaceTableUponGsiUpdate: false,
allowGen1Patterns: true,
enableGen2Migration: false,
},
};

Expand Down
1 change: 0 additions & 1 deletion packages/graphql-transformer-common/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ export class ResourceConstants {
AuthCognitoUserPoolIdOutput: string;
AuthCognitoUserPoolNativeClientOutput: string;
AuthCognitoUserPoolJSClientOutput: string;
DataSourceMappingOutput: string;
};
// (undocumented)
static PARAMETERS: {
Expand Down
3 changes: 0 additions & 3 deletions packages/graphql-transformer-common/src/ResourceConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ export class ResourceConstants {
AuthCognitoUserPoolIdOutput: 'AuthCognitoUserPoolIdOutput',
AuthCognitoUserPoolNativeClientOutput: 'AuthCognitoUserPoolNativeClientId',
AuthCognitoUserPoolJSClientOutput: 'AuthCognitoUserPoolJSClientId',

// Migration
DataSourceMappingOutput: 'DataSourceMappingOutput',
};

public static METADATA = {};
Expand Down

0 comments on commit 2edca25

Please sign in to comment.