Learn how you can upload your database into Amplication and how it transforms it into its standardized internal model
Validate: Ensuring Schema Integrity
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.Prepare: Aligning with Amplication's Standards
id
field for each entity.Convert: Optimizing Data Types for Amplication
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.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.
Model Names: PascalCase, Singular, No Underscores
@@map
attribute.
If your original model name deviates from Amplication’s conventions, @@map
is automatically added, preserving the original database table name while using the standardized name within Amplication.@@map
attributes in your schema, Amplication
respects your existing mappings and does not overwrite them.CourseRating
, the underlying database table remains course_rating
, preventing any disruption to existing data or systems.Field Names: camelCase, No Underscores
@map
attribute to preserve your original database column names when necessary. This ensures seamless integration with existing databases and prevents unexpected data mapping issues.@map
attributes on fields are also respected and not overwritten
during this process.item_price
is converted to itemPrice
in your Amplication service, while the @map("item_price")
attribute ensures the database column remains item_price
.Field Types: Ensuring Model Relationships
products
and orders
are corrected to Product
and Order
respectively, ensuring the relationship is clearly defined and consistent with Amplication’s model naming standards.Model IDs: Simplifying Primary Keys
@@id
attribute, which in Prisma can define composite IDs, to focus on single-field primary keys, which aligns with Amplication’s entity structure.@@id([field1, field2])
) are currently not fully supported in
Amplication.@@id([field])
is converted to @@unique([field])
. The original @@id
is replaced with a @@unique
constraint to maintain uniqueness in the database.@@id
now becomes the actual ID field within Amplication. The @id
attribute is added to this field.@default()
attribute (like cuid()
for String IDs or autoincrement()
for Int IDs), Amplication adds one based on the field’s type. This ensures every entity has a properly configured default ID generation strategy.@map
attribute is added to preserve the original field name in the database.@@unique
attribute is updated to reference the new “id” field: @@unique([originalFieldName])
becomes @@unique([id])
.Model ID Field: Ensuring a Standard 'id' Field
id
field. This is a fundamental principle in Amplication, ensuring consistent entity identification across your services.This operation handles two main scenarios:id
but isn’t an ID field (doesn’t have the @id
attribute), it’s renamed to ${modelName}Id
to avoid naming conflicts with the actual ID field that Amplication will ensure exists. A @map
attribute is added to preserve the original name in the database.@id
attribute) has a name other than id
, it’s renamed to id
. Again, a @map
attribute is used to maintain the original field name in the database.id
field, simplifying data access and relationships within your services.Prisma | Amplication | Description |
---|---|---|
String (ID) | Id | Converts 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. |
Boolean | Boolean | Direct mapping for Boolean types. |
DateTime (@default(now()) ) | CreatedAt | DateTime fields with @default(now()) are converted to Amplication’s specialized CreatedAt type. |
DateTime (@updatedAt ) | UpdatedAt | DateTime fields with @updatedAt are converted to Amplication’s specialized UpdatedAt type. |
DateTime | DateTime | Plain DateTime fields remain as DateTime in Amplication. |
Float , Decimal | Decimal Number | Prisma’s Float and Decimal types are converted to Amplication’s Decimal Number type. |
Int , BigInt | WholeNumber | Prisma’s Int and BigInt types are converted to Amplication’s WholeNumber type. |
String | SingleLineText | Standard String fields are converted to Amplication’s SingleLineText type, suitable for short text inputs. |
Json | Json | Json types are directly equivalent. |
Enum | OptionSet | Prisma Enum types are converted to Amplication’s OptionSet , providing structured choice options. |
Enum[] | MultiSelectOptionSet | Prisma Enum[] arrays are converted to MultiSelectOptionSet , allowing multiple selections from options. |
Model relation | Lookup | Relations to other models are converted to Amplication’s Lookup type, establishing entity relationships. |
Id
Field Conversion Scenariosid
field is central to Amplication’s entity model, and its conversion requires careful handling.
Here are common scenarios you might encounter:
Scenario 1: Existing @default Attribute on 'id' Field
id
field already has a @default
attribute, Amplication removes it. This is because Amplication automatically adds a @default
attribute that aligns with the id
type (e.g., cuid()
or autoincrement()
) during conversion. Having multiple @default
attributes is invalid in Prisma schema.Example:Scenario 2: Model Without a Suitable 'id' Field
id
, Amplication proactively adds an id
field. This ensures every entity in Amplication has a clearly defined primary identifier. The added id
field is of type String
and defaults to cuid()
for generating unique IDs.Example:Scenario 3: Multiple Unique Fields, One Named 'id'
id
field (e.g., multiple @unique
fields), and one of them is already named id
, Amplication prioritizes the field named id
. This field is then designated as the primary @id
and configured with an appropriate @default
attribute (like autoincrement()
for Int types).Example:Scenario 4: No Unique Field Named 'id'
id
, Amplication selects a unique field (often the first one encountered) and renames it to id
. To maintain database integrity, a @map
attribute is added, mapping the new id
field back to its original name in the database.Example:(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.
Custom Attributes on Enum Keys
OptionSet
and MultiSelectOptionSet
types handle Enums effectively. However, Amplication currently does not fully support custom attributes like @map
or @@map
directly on Enum keys or Enums themselves.If your Prisma schema uses these attributes on Enums, they will not be preserved in the converted schema.Impact: If your application logic relies heavily on these custom mapping attributes for Enums, you’ll need to manually adjust the generated schema.prisma
or your application code to ensure correct behavior after importing into Amplication.Composite IDs on Models
@@id([field1, field2, ...])
, Amplication adapts this by:@@id
to @@unique
to maintain database-level uniqueness constraints.id
field (String type, cuid()
default) to the model to serve as Amplication’s primary identifier.@@unique
constraint, the shift from a composite ID to a singular id
might require adjustments in how you design relationships and queries within Amplication. Be mindful of this change when working with entities that originally used composite IDs.Amplication logs warnings when it encounters models with @@id
attributes and no existing id
field, alerting you to this conversion.