generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 103
feat: api for adopted table during gen1 -> gen2 migration #3040
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
Draft
iankhou
wants to merge
1
commit into
main
Choose a base branch
from
iankhou-adopted-table-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−49
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@aws-amplify/backend-data': minor | ||
| --- | ||
|
|
||
| Enabled a new "adoption" strategy for moving DynamoDB tables from Gen1 to Gen2, which will require an import operation. The migrated table will be fully managed by the Gen2 stack. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,12 @@ const IMPORTED_DYNAMO_DATA_SOURCE_STRATEGY = { | |
| provisionStrategy: 'IMPORTED_AMPLIFY_TABLE', | ||
| } as const; | ||
|
|
||
| // Adopted strategy where Amplify will synthesize a managed CFN table resource | ||
| const ADOPTED_DYNAMO_DATA_SOURCE_STRATEGY = { | ||
| dbType: 'DYNAMODB', | ||
| provisionStrategy: 'ADOPTED_AMPLIFY_TABLE', | ||
| } as const; | ||
|
|
||
| // Translate the external engine types to the config values | ||
| // Reference: https://github.com/aws-amplify/amplify-category-api/blob/fd7f6fbc17c199331c4b04debaff69ea0424cd74/packages/amplify-graphql-api-construct/src/model-datasource-strategy-types.ts#L25 | ||
| const SQL_DB_TYPES = { | ||
|
|
@@ -81,18 +87,28 @@ const SQL_DB_TYPES = { | |
|
|
||
| /** | ||
| * Given an input schema type, produce the relevant CDK Graphql Def interface | ||
| * @param schema TS schema builder definition or string GraphQL schema | ||
| * @param backendSecretResolver secret resolver | ||
| * @param stableBackendIdentifiers backend identifiers | ||
| * @param importedTableName table name to use for imported models. If not defined the model is not imported. | ||
| * @param params configuration parameters | ||
| * @param params.schema TS schema builder definition or string GraphQL schema | ||
| * @param params.backendSecretResolver secret resolver | ||
| * @param params.stableBackendIdentifiers backend identifiers | ||
| * @param params.importedTableName table name to use for imported models. If not defined the model is not imported. | ||
| * @param params.shouldAdoptExistingTable whether to adopt the existing table | ||
| * @returns the cdk graphql definition interface | ||
| */ | ||
| export const convertSchemaToCDK = ( | ||
| schema: DataSchema, | ||
| backendSecretResolver: BackendSecretResolver, | ||
| stableBackendIdentifiers: StableBackendIdentifiers, | ||
| importedTableName?: string, | ||
| ): IAmplifyDataDefinition => { | ||
| export const convertSchemaToCDK = (params: { | ||
| schema: DataSchema; | ||
| backendSecretResolver: BackendSecretResolver; | ||
| stableBackendIdentifiers: StableBackendIdentifiers; | ||
| importedTableName?: string; | ||
| shouldAdoptExistingTable?: boolean; | ||
| }): IAmplifyDataDefinition => { | ||
| const { | ||
| schema, | ||
| backendSecretResolver, | ||
| stableBackendIdentifiers, | ||
| importedTableName, | ||
| shouldAdoptExistingTable, | ||
| } = params; | ||
| if (isDataSchema(schema)) { | ||
| /** | ||
| * This is not super obvious, but the IAmplifyDataDefinition interface requires a record of each model type to a | ||
|
|
@@ -146,6 +162,12 @@ export const convertSchemaToCDK = ( | |
| } | ||
|
|
||
| if (importedTableName) { | ||
| if (shouldAdoptExistingTable) { | ||
| return AmplifyDataDefinition.fromString(schema, { | ||
| ...ADOPTED_DYNAMO_DATA_SOURCE_STRATEGY, | ||
| tableName: importedTableName, | ||
| } as unknown as ModelDataSourceStrategy); | ||
| } | ||
|
Comment on lines
+165
to
+170
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the important part. |
||
| return AmplifyDataDefinition.fromString(schema, { | ||
| ...IMPORTED_DYNAMO_DATA_SOURCE_STRATEGY, | ||
| tableName: importedTableName, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the important part.