diff --git a/libs/datamodel/core/src/json/dmmf/mod.rs b/libs/datamodel/core/src/json/dmmf/mod.rs index 037b939278e3..a849e00286f5 100644 --- a/libs/datamodel/core/src/json/dmmf/mod.rs +++ b/libs/datamodel/core/src/json/dmmf/mod.rs @@ -57,6 +57,14 @@ pub struct Model { pub documentation: Option, pub id_fields: Vec, pub unique_fields: Vec>, + pub unique_indexes: Vec, +} + +#[serde(rename_all = "camelCase")] +#[derive(Debug, serde::Serialize, serde::Deserialize)] +pub struct UniqueIndex { + pub name: Option, + pub fields: Vec, } #[serde(rename_all = "camelCase")] diff --git a/libs/datamodel/core/src/json/dmmf/to_dmmf.rs b/libs/datamodel/core/src/json/dmmf/to_dmmf.rs index 3b20c960ae80..105246867b5c 100644 --- a/libs/datamodel/core/src/json/dmmf/to_dmmf.rs +++ b/libs/datamodel/core/src/json/dmmf/to_dmmf.rs @@ -72,6 +72,20 @@ fn model_to_dmmf(model: &dml::Model) -> Model { } }) .collect(), + unique_indexes: model + .indices + .iter() + .filter_map(|i| { + if i.tpe == IndexType::Unique { + Some(UniqueIndex { + name: i.name.clone(), + fields: i.fields.clone(), + }) + } else { + None + } + }) + .collect(), } } diff --git a/libs/datamodel/core/tests/render_to_dmmf/files/functions.json b/libs/datamodel/core/tests/render_to_dmmf/files/functions.json index d83751dab755..79e26a616ce2 100644 --- a/libs/datamodel/core/tests/render_to_dmmf/files/functions.json +++ b/libs/datamodel/core/tests/render_to_dmmf/files/functions.json @@ -48,7 +48,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] } ] } \ No newline at end of file diff --git a/libs/datamodel/core/tests/render_to_dmmf/files/general.json b/libs/datamodel/core/tests/render_to_dmmf/files/general.json index fd6420136bf1..7bb81201e4df 100644 --- a/libs/datamodel/core/tests/render_to_dmmf/files/general.json +++ b/libs/datamodel/core/tests/render_to_dmmf/files/general.json @@ -114,7 +114,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] }, { "name": "Profile", @@ -184,7 +185,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] }, { "name": "Post", @@ -326,7 +328,8 @@ "title", "createdAt" ], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] }, { "name": "Category", @@ -392,7 +395,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] }, { "name": "PostToCategory", @@ -498,7 +502,11 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [["postTitle", "categoryId"]], + "uniqueIndexes": [{ + "name": "MyUniqueIndex", + "fields": ["postTitle", "categoryId"] + }] }, { "name": "A", @@ -555,7 +563,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] }, { "name": "B", @@ -595,7 +604,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] } ] } \ No newline at end of file diff --git a/libs/datamodel/core/tests/render_to_dmmf/files/general.prisma b/libs/datamodel/core/tests/render_to_dmmf/files/general.prisma index 8cf2c86f08ae..f5f38092d4d7 100644 --- a/libs/datamodel/core/tests/render_to_dmmf/files/general.prisma +++ b/libs/datamodel/core/tests/render_to_dmmf/files/general.prisma @@ -50,6 +50,7 @@ model PostToCategory { post Post @relation(fields: [postTitle, postCreatedAt], references: [title, createdAt]) category Category @relation(fields: [categoryId], references: [id]) + @@unique([postTitle, categoryId], name: "MyUniqueIndex") @@map("post_to_category") } diff --git a/libs/datamodel/core/tests/render_to_dmmf/files/source.json b/libs/datamodel/core/tests/render_to_dmmf/files/source.json index c0a251b5309e..31a8878aa22f 100644 --- a/libs/datamodel/core/tests/render_to_dmmf/files/source.json +++ b/libs/datamodel/core/tests/render_to_dmmf/files/source.json @@ -48,7 +48,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] } ] } \ No newline at end of file diff --git a/libs/datamodel/core/tests/render_to_dmmf/files/source_with_comments.json b/libs/datamodel/core/tests/render_to_dmmf/files/source_with_comments.json index b621e01fd34e..abad7feec470 100644 --- a/libs/datamodel/core/tests/render_to_dmmf/files/source_with_comments.json +++ b/libs/datamodel/core/tests/render_to_dmmf/files/source_with_comments.json @@ -37,7 +37,8 @@ "isGenerated": false, "documentation": "My author model.", "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] } ] } \ No newline at end of file diff --git a/libs/datamodel/core/tests/render_to_dmmf/files/source_with_generator.json b/libs/datamodel/core/tests/render_to_dmmf/files/source_with_generator.json index 2f8ffb0c13d5..0b64f170bea2 100644 --- a/libs/datamodel/core/tests/render_to_dmmf/files/source_with_generator.json +++ b/libs/datamodel/core/tests/render_to_dmmf/files/source_with_generator.json @@ -35,7 +35,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] } ] } \ No newline at end of file diff --git a/libs/datamodel/core/tests/render_to_dmmf/files/without_relation_name.json b/libs/datamodel/core/tests/render_to_dmmf/files/without_relation_name.json index d44ed04dc334..42205318473a 100644 --- a/libs/datamodel/core/tests/render_to_dmmf/files/without_relation_name.json +++ b/libs/datamodel/core/tests/render_to_dmmf/files/without_relation_name.json @@ -39,7 +39,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] }, { "name": "Post", @@ -96,7 +97,8 @@ ], "isGenerated": false, "idFields": [], - "uniqueFields": [] + "uniqueFields": [], + "uniqueIndexes": [] } ] } \ No newline at end of file