Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(psl): Updated validation for multi-schema attribute detection #3503

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 | }
//  |