This page explains the technical details of Prisma schema conversion within Amplication. For a practical guide on uploading your schema, see How to Upload Schema.

When you upload your DB Schema into Amplication, you are initiating a process that transforms your schema into Amplication’s internal entity model. This page dives deep into how Amplication converts your Prisma database schema into Amplication’s internal structure.

The 3-Step Conversion Process

During the schema upload, you’ll see logs detailing a three-phase conversion process:

1

Validate: Ensuring Schema Integrity

The first step validates the syntax and structure of your schema.prisma file against Prisma’s conventions. This ensures your schema is well-formed and ready for conversion. Crucially, it also checks for the presence of models – the building blocks of your services. Without models, the conversion process cannot proceed, ensuring a valid starting point.

This validation step is your first line of defense against schema errors, preventing issues down the line and ensuring a smooth import process.

2

Prepare: Aligning with Amplication's Standards

The preparation phase standardizes your schema, applying five key transformations to ensure consistency and maintainability across all services generated by Amplication. This step is critical for platform teams aiming to enforce organizational standards and reduce technical drift.

These transformations include:

  • Model Names: Standardizing to PascalCase, singular, and no underscores.
  • Field Names: Standardizing to camelCase and no underscores.
  • Field Types: Ensuring consistent type references between models.
  • Model IDs: Simplifying primary key definitions for clarity and consistency.
  • Model ID Field: Guaranteeing a standardized id field for each entity.
3

Convert: Optimizing Data Types for Amplication

In the final conversion step, Prisma’s data types are mapped to Amplication’s internal data types. This ensures optimal performance and functionality within Amplication’s service generation framework. This mapping includes handling specific DateTime attributes for CreatedAt and UpdatedAt fields, and translating Prisma’s type system to Amplication’s more abstract types like Lookup for relations and OptionSet for Enums.

This step ensures that your database schema is not just imported, but intelligently adapted to Amplication’s architecture, maximizing efficiency and developer experience.

Step 1: Validate - First Pass Schema Check

This step acts as an initial quality gate, confirming that your schema.prisma is syntactically correct and contains the essential elements – models – necessary for Amplication to build upon. This quick check prevents wasted time and ensures the conversion process begins with a valid schema.

Step 2: Prepare - Standardizing for Consistency and Maintainability

This phase is where Amplication’s conversion happens. By applying these five operations, Amplication ensures that all generated services adhere to consistent naming conventions and structural patterns.

Step 3: Convert - Mapping Prisma Types to Amplication Data Types

The final conversion step maps Prisma’s data types to Amplication’s internal data types, optimizing them for service generation and functionality within the Amplication ecosystem. This step ensures that your data is represented in a way that best leverages Amplication’s features and capabilities.

Here’s a table summarizing the Prisma to Amplication data type conversions:

PrismaAmplicationDescription
String (ID)IdConverts ID fields with String type to Amplication Id type, defaulting to cuid() for ID generation.
Int (ID)Id (autoincrement)Converts ID fields with Int type to Amplication Id type, using autoincrement() for ID generation.
BooleanBooleanDirect mapping for Boolean types.
DateTime (@default(now()))CreatedAtDateTime fields with @default(now()) are converted to Amplication’s specialized CreatedAt type.
DateTime (@updatedAt)UpdatedAtDateTime fields with @updatedAt are converted to Amplication’s specialized UpdatedAt type.
DateTimeDateTimePlain DateTime fields remain as DateTime in Amplication.
Float, DecimalDecimal NumberPrisma’s Float and Decimal types are converted to Amplication’s Decimal Number type.
Int, BigIntWholeNumberPrisma’s Int and BigInt types are converted to Amplication’s WholeNumber type.
StringSingleLineTextStandard String fields are converted to Amplication’s SingleLineText type, suitable for short text inputs.
JsonJsonJson types are directly equivalent.
EnumOptionSetPrisma Enum types are converted to Amplication’s OptionSet, providing structured choice options.
Enum[]MultiSelectOptionSetPrisma Enum[] arrays are converted to MultiSelectOptionSet, allowing multiple selections from options.
Model relationLookupRelations to other models are converted to Amplication’s Lookup type, establishing entity relationships.

Common Id Field Conversion Scenarios

The id field is central to Amplication’s entity model, and its conversion requires careful handling. Here are common scenarios you might encounter:

Log Warnings: Addressing Potential Issues

During schema processing, Amplication provides logs, including (Info) and (Warning) messages. While the schema will still process with warnings, it’s crucial to review them. Warnings indicate potential discrepancies or areas where the conversion might not perfectly align with your original schema’s intent. Addressing warnings proactively can prevent unexpected behavior in your generated services.

Here are the most common warning scenarios you might encounter and how to address them:

Conclusion

By understanding how Amplication converts your Prisma schema, you gain valuable insight into how Amplication helps you establish and maintain a standardized data model. Review the conversion logs after uploading your schema and explore your newly created entities in Amplication’s ERD view.