diff --git a/.changeset/twenty-pants-own.md b/.changeset/twenty-pants-own.md new file mode 100644 index 0000000000..0518166426 --- /dev/null +++ b/.changeset/twenty-pants-own.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/backend-data': minor +--- + +allow passing in a schema configuration for string based SQL schemas diff --git a/packages/backend-data/src/convert_schema.ts b/packages/backend-data/src/convert_schema.ts index 4b25072182..c1bc922f18 100644 --- a/packages/backend-data/src/convert_schema.ts +++ b/packages/backend-data/src/convert_schema.ts @@ -3,6 +3,7 @@ import type { DataSourceConfiguration, DerivedCombinedSchema, DerivedModelSchema as DerivedDataSchema, + SchemaConfiguration, } from '@aws-amplify/data-schema-types'; import { AmplifyDataDefinition, @@ -74,7 +75,8 @@ const SQL_DB_TYPES = { export const convertSchemaToCDK = ( schema: DataSchema, backendSecretResolver: BackendSecretResolver, - stableBackendIdentifiers: StableBackendIdentifiers + stableBackendIdentifiers: StableBackendIdentifiers, + schemaConfiguration?: SchemaConfiguration ): IAmplifyDataDefinition => { if (isDataSchema(schema)) { /** @@ -125,6 +127,19 @@ export const convertSchemaToCDK = ( }) ) || [], }; + } else if ( + schemaConfiguration && + schemaConfiguration?.database.engine != 'dynamodb' + ) { + const provisionStrategyName = + stableBackendIdentifiers.getStableBackendHash(); + const dbStrategy = convertDatabaseConfigurationToDataSourceStrategy( + schemaConfiguration.database, + [], + backendSecretResolver, + provisionStrategyName + ); + return AmplifyDataDefinition.fromString(schema, dbStrategy); } return AmplifyDataDefinition.fromString(schema, DYNAMO_DATA_SOURCE_STRATEGY); diff --git a/packages/backend-data/src/types.ts b/packages/backend-data/src/types.ts index 031636986e..6318c3df86 100644 --- a/packages/backend-data/src/types.ts +++ b/packages/backend-data/src/types.ts @@ -1,6 +1,7 @@ import { DerivedCombinedSchema, DerivedModelSchema, + SchemaConfiguration, } from '@aws-amplify/data-schema-types'; import { AmplifyFunction, ConstructFactory } from '@aws-amplify/plugin-types'; @@ -125,6 +126,11 @@ export type DataProps = { */ schema: DataSchemaInput; + /** + * Schema configuration for non-DynamoDB data sources. + */ + schemaConfiguration?: SchemaConfiguration; + /** * Optional name for the generated Api. */