Skip to content

Commit

Permalink
feat: add schema to dmmf
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Nov 7, 2024
1 parent 92f6d89 commit 41b1aa8
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prisma-fmt/src/get_datamodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mod tests {
{
"name": "User",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -119,6 +120,7 @@ mod tests {
{
"name": "Post",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down
2 changes: 2 additions & 0 deletions prisma-fmt/src/get_dmmf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ mod tests {
{
"name": "A",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -429,6 +430,7 @@ mod tests {
{
"name": "B",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down
2 changes: 2 additions & 0 deletions query-engine/dmmf/src/ast_builders/datamodel_ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fn composite_type_to_dmmf(ct: walkers::CompositeTypeWalker<'_>) -> Model {
Model {
name: ct.name().to_owned(),
db_name: None,
schema: None,
fields: ct
.fields()
.filter(|field| !matches!(field.r#type(), ScalarFieldType::Unsupported(_)))
Expand Down Expand Up @@ -127,6 +128,7 @@ fn model_to_dmmf(model: walkers::ModelWalker<'_>) -> Model {
Model {
name: model.name().to_owned(),
db_name: model.mapped_name().map(ToOwned::to_owned),
schema: model.schema().map(|(s, _)| s.to_owned()),
fields: model
.fields()
.filter(|field| !should_skip_model_field(field))
Expand Down
2 changes: 2 additions & 0 deletions query-engine/dmmf/src/serialization_ast/datamodel_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub struct Function {
pub struct Model {
pub name: String,
pub db_name: Option<String>,
pub schema: Option<String>,

pub fields: Vec<Field>,
pub primary_key: Option<PrimaryKey>,
pub unique_fields: Vec<Vec<String>>,
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions query-engine/dmmf/test_files/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "User",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down
9 changes: 9 additions & 0 deletions query-engine/dmmf/test_files/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{
"name": "User",
"dbName": "user",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -118,6 +119,7 @@
{
"name": "Profile",
"dbName": "profile",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -187,6 +189,7 @@
{
"name": "Post",
"dbName": "post",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -333,6 +336,7 @@
{
"name": "Category",
"dbName": "category",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -398,6 +402,7 @@
{
"name": "PostToCategory",
"dbName": "post_to_category",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -515,6 +520,7 @@
{
"name": "A",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -571,6 +577,7 @@
{
"name": "B",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -610,6 +617,7 @@
{
"name": "NamedCompounds",
"dbName": null,
"schema": null,
"fields": [
{
"name": "a",
Expand Down Expand Up @@ -691,6 +699,7 @@
{
"name": "MappedSingles",
"dbName": null,
"schema": null,
"fields": [
{
"name": "a",
Expand Down
1 change: 1 addition & 0 deletions query-engine/dmmf/test_files/ignore.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "User",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down
2 changes: 2 additions & 0 deletions query-engine/dmmf/test_files/indexes_mongodb.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "Post",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -69,6 +70,7 @@
{
"name": "Comment",
"dbName": null,
"schema": null,
"fields": [
{
"name": "userId",
Expand Down
1 change: 1 addition & 0 deletions query-engine/dmmf/test_files/indexes_mysql.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "Post",
"dbName": null,
"schema": null,
"fields": [
{
"name": "title",
Expand Down
1 change: 1 addition & 0 deletions query-engine/dmmf/test_files/indexes_postgres.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "Example",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down
2 changes: 2 additions & 0 deletions query-engine/dmmf/test_files/indexes_sqlserver.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "Example",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -40,6 +41,7 @@
{
"name": "Post",
"dbName": null,
"schema": null,
"fields": [
{
"name": "title",
Expand Down
76 changes: 76 additions & 0 deletions query-engine/dmmf/test_files/schemas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"enums": [],
"models": [
{
"name": "A",
"dbName": null,
"schema": "public",
"fields": [
{
"name": "id",
"kind": "scalar",
"isList": false,
"isRequired": true,
"isUnique": false,
"isId": true,
"isReadOnly": false,
"hasDefaultValue": false,
"type": "Int",
"isGenerated": false,
"isUpdatedAt": false
}
],
"primaryKey": null,
"uniqueFields": [],
"uniqueIndexes": [],
"isGenerated": false
},
{
"name": "B",
"dbName": null,
"schema": "test",
"fields": [
{
"name": "id",
"kind": "scalar",
"isList": false,
"isRequired": true,
"isUnique": false,
"isId": true,
"isReadOnly": false,
"hasDefaultValue": false,
"type": "Int",
"isGenerated": false,
"isUpdatedAt": false
}
],
"primaryKey": null,
"uniqueFields": [],
"uniqueIndexes": [],
"isGenerated": false
}
],
"types": [],
"indexes": [
{
"model": "A",
"type": "id",
"isDefinedOnField": true,
"fields": [
{
"name": "id"
}
]
},
{
"model": "B",
"type": "id",
"isDefinedOnField": true,
"fields": [
{
"name": "id"
}
]
}
]
}
22 changes: 22 additions & 0 deletions query-engine/dmmf/test_files/schemas.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
datasource pg {
provider = "postgresql"
url = "postgresql://"
schemas = ["public", "test"]
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema"]
}

model A {
id Int @id
@@schema("public")
}

model B {
id Int @id
@@schema("test")
}
1 change: 1 addition & 0 deletions query-engine/dmmf/test_files/source_with_comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "Author",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down
1 change: 1 addition & 0 deletions query-engine/dmmf/test_files/source_with_generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "Author",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down
3 changes: 3 additions & 0 deletions query-engine/dmmf/test_files/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "User",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -69,6 +70,7 @@
{
"name": "Profile",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -138,6 +140,7 @@
{
"name": "UserInfo",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down
2 changes: 2 additions & 0 deletions query-engine/dmmf/test_files/without_relation_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "User",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -43,6 +44,7 @@
{
"name": "Post",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down

0 comments on commit 41b1aa8

Please sign in to comment.