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

Discussion: Allow passing in a schema configuration for string based schemas #1706

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .changeset/twenty-pants-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-data': minor
---

allow passing in a schema configuration for string based SQL schemas
17 changes: 16 additions & 1 deletion packages/backend-data/src/convert_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DataSourceConfiguration,
DerivedCombinedSchema,
DerivedModelSchema as DerivedDataSchema,
SchemaConfiguration,
} from '@aws-amplify/data-schema-types';
import {
AmplifyDataDefinition,
Expand Down Expand Up @@ -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)) {
/**
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions packages/backend-data/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DerivedCombinedSchema,
DerivedModelSchema,
SchemaConfiguration,
} from '@aws-amplify/data-schema-types';
import { AmplifyFunction, ConstructFactory } from '@aws-amplify/plugin-types';

Expand Down Expand Up @@ -125,6 +126,11 @@ export type DataProps = {
*/
schema: DataSchemaInput;

/**
* Schema configuration for non-DynamoDB data sources.
*/
schemaConfiguration?: SchemaConfiguration;

/**
* Optional name for the generated Api.
*/
Expand Down