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

intro: multiSchema-aware SQL Server #3466

Merged
merged 1 commit into from
Dec 7, 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 @@ -77,6 +77,72 @@ async fn multiple_schemas_w_tables_are_introspected(api: &TestApi) -> TestResult
Ok(())
}

#[test_connector(
tags(Postgres),
exclude(CockroachDb),
preview_features("multiSchema"),
namespaces("first", "second")
)]
async fn multiple_schemas_w_tables_are_reintrospected(api: &TestApi) -> TestResult {
let schema_name = "first";
let other_name = "second";
let create_schema = format!("CREATE Schema \"{schema_name}\"",);
let create_table = format!("CREATE TABLE \"{schema_name}\".\"A\" (id Text PRIMARY KEY, data Text)",);
let create_primary = format!("CREATE INDEX \"A_idx\" ON \"{schema_name}\".\"A\" (\"data\")",);

api.database().raw_cmd(&create_schema).await?;
api.database().raw_cmd(&create_table).await?;
api.database().raw_cmd(&create_primary).await?;

let create_schema = format!("CREATE Schema \"{other_name}\"",);
let create_table = format!("CREATE TABLE \"{other_name}\".\"B\" (id Text PRIMARY KEY, data Text)",);
let create_primary = format!("CREATE INDEX \"B_idx\" ON \"{other_name}\".\"B\" (\"data\")",);

api.database().raw_cmd(&create_schema).await?;
api.database().raw_cmd(&create_table).await?;
api.database().raw_cmd(&create_primary).await?;

let input = indoc! {r#"
model A {
id String @id
data String?

@@index([data], map: "A_idx")
@@schema("first")
}

model B {
id String @id
data String?

@@index([data], map: "B_idx")
@@schema("first")
}
"#};

let expected = expect![[r#"
model A {
id String @id
data String?

@@index([data], map: "A_idx")
@@schema("first")
}

model B {
id String @id
data String?

@@index([data], map: "B_idx")
@@schema("second")
}
"#]];

api.expect_re_introspected_datamodel(input, expected).await;

Ok(())
}

#[test_connector(
tags(Postgres),
exclude(CockroachDb),
Expand Down Expand Up @@ -167,6 +233,68 @@ async fn multiple_schemas_w_cross_schema_are_introspected(api: &TestApi) -> Test
Ok(())
}

#[test_connector(
tags(Postgres),
exclude(CockroachDb),
preview_features("multiSchema"),
namespaces("first", "second")
)]
async fn multiple_schemas_w_cross_schema_are_reintrospected(api: &TestApi) -> TestResult {
let schema_name = "first";
let other_name = "second";
let create_schema = format!("CREATE Schema \"{schema_name}\"",);
let create_table = format!("CREATE TABLE \"{schema_name}\".\"A\" (id Text PRIMARY KEY)",);
//Todo
api.database().raw_cmd(&create_schema).await?;
api.database().raw_cmd(&create_table).await?;

let create_schema = format!("CREATE Schema \"{other_name}\"",);
let create_table = format!(
"CREATE TABLE \"{other_name}\".\"B\" (id Text PRIMARY KEY, fk Text References \"{schema_name}\".\"A\"(\"id\"))",
);

api.database().raw_cmd(&create_schema).await?;
api.database().raw_cmd(&create_table).await?;

let input = indoc! {r#"
model A {
id String @id
B B[]

@@schema("first")
}

model B {
id String @id
fk String?
A A? @relation(fields: [fk], references: [id], onDelete: NoAction, onUpdate: NoAction)

@@schema("first")
}
"#};

let expected = expect![[r#"
model A {
id String @id
B B[]

@@schema("first")
}

model B {
id String @id
fk String?
A A? @relation(fields: [fk], references: [id], onDelete: NoAction, onUpdate: NoAction)

@@schema("second")
}
"#]];

api.expect_re_introspected_datamodel(input, expected).await;

Ok(())
}

#[test_connector(tags(Postgres), preview_features("multiSchema"), namespaces("first", "second"))]
async fn multiple_schemas_w_cross_schema_fks_w_duplicate_names_are_introspected(api: &TestApi) -> TestResult {
let schema_name = "first";
Expand Down Expand Up @@ -400,22 +528,6 @@ async fn same_table_name_with_relation_in_two_schemas(api: &TestApi) -> TestResu
"#]];

api.expect_datamodel(&expected).await;

Ok(())
}

//cross schema
// fks
// enums

//Edge cases
//name conflicts
// what if the names are used somewhere???
// table
// enum
//invalid names
// schema
// table
// enum
// re-introspection
// table
// enum