Skip to content

Commit

Permalink
fix(psl): Updated validation for multi-schema attribute detection (#3503
Browse files Browse the repository at this point in the history
)

Will now error when no models or enums contain `@@schema` as opposed to just one.
  • Loading branch information
Druue committed Dec 15, 2022
1 parent a9139d1 commit 2ff0967
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,14 @@ async fn multiple_schemas_w_tables_are_reintrospected(api: &TestApi) -> TestResu
let input = indoc! {r#"
model A {
id Int @id @default(autoincrement())
@@schema("first")
}
model B {
id Int @id @default(autoincrement())
@@schema("second")
}
"#};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
datamodel_connector::ConnectorCapability,
diagnostics::DatamodelError,
parser_database::{self, ast::WithSpan, walkers::EnumWalker},
parser_database::{ast::WithSpan, walkers::EnumWalker},
validate::validation_pipeline::context::Context,
};
use std::collections::HashSet;
Expand Down Expand Up @@ -76,11 +76,12 @@ pub(super) fn schema_attribute_missing(r#enum: EnumWalker<'_>, ctx: &mut Context
return;
}

if !ctx
.db
.schema_flags()
.contains(parser_database::SchemaFlags::UsesSchemaAttribute)
{
let datasource = match ctx.datasource {
Some(datasource) => datasource,
None => return,
};

if datasource.schemas_span.is_none() {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,12 @@ pub(super) fn schema_attribute_missing(model: ModelWalker<'_>, ctx: &mut Context
return;
}

if !ctx
.db
.schema_flags()
.contains(parser_database::SchemaFlags::UsesSchemaAttribute)
{
let datasource = match ctx.datasource {
Some(datasource) => datasource,
None => return,
};

if datasource.schemas_span.is_none() {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// This is _not_ valid: once @@schema is specified once, it has to be
// specified for every model and enum.

datasource testds {
provider = "postgresql"
url = env("TEST_DATABASE_URL")
schemas = ["public", "security", "users"]
}

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

model Test {
id Int @id
}

model Test2 {
id Int @id
}

enum UserType {
Bacteria
Archea
Eukaryote
}
// error: This model is missing an `@@schema` attribute.
// --> schema.prisma:15
//  | 
// 14 | 
// 15 | model Test {
// 16 |  id Int @id
// 17 | }
//  | 
// error: This model is missing an `@@schema` attribute.
// --> schema.prisma:19
//  | 
// 18 | 
// 19 | model Test2 {
// 20 |  id Int @id
// 21 | }
//  | 
// error: This enum is missing an `@@schema` attribute.
// --> schema.prisma:23
//  | 
// 22 | 
// 23 | enum UserType {
// 24 |  Bacteria
// 25 |  Archea
// 26 |  Eukaryote
// 27 | }
//  | 

0 comments on commit 2ff0967

Please sign in to comment.