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 26, 2024
1 parent d3a1c9a commit 099a7ac
Show file tree
Hide file tree
Showing 18 changed files with 132 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 @@ -122,6 +123,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 @@ -432,6 +433,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 @@ -130,6 +131,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 @@ -64,6 +64,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 @@ -124,6 +125,7 @@
{
"name": "Profile",
"dbName": "profile",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -197,6 +199,7 @@
{
"name": "Post",
"dbName": "post",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -352,6 +355,7 @@
{
"name": "Category",
"dbName": "category",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -421,6 +425,7 @@
{
"name": "PostToCategory",
"dbName": "post_to_category",
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -544,6 +549,7 @@
{
"name": "A",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -603,6 +609,7 @@
{
"name": "B",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -644,6 +651,7 @@
{
"name": "NamedCompounds",
"dbName": null,
"schema": null,
"fields": [
{
"name": "a",
Expand Down Expand Up @@ -729,6 +737,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 @@ -76,6 +77,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 @@ -42,6 +43,7 @@
{
"name": "Post",
"dbName": null,
"schema": null,
"fields": [
{
"name": "title",
Expand Down
78 changes: 78 additions & 0 deletions query-engine/dmmf/test_files/schemas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"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",
"nativeType": null,
"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",
"nativeType": null,
"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 @@ -73,6 +74,7 @@
{
"name": "Profile",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -146,6 +148,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 @@ -45,6 +46,7 @@
{
"name": "Post",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand Down

0 comments on commit 099a7ac

Please sign in to comment.