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

describer: multiSchema-aware SQL Server #3465

Merged
merged 1 commit into from
Dec 6, 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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use introspection_engine_tests::{test_api::*, TestResult};

#[test_connector(tags(Mssql), preview_features("multiSchema"), namespaces("first", "second"))]
async fn multiple_schemas_w_tables_are_introspected(api: &TestApi) -> TestResult {
let schema_name = "first";
let other_name = "second";

let setup = format!("CREATE SCHEMA {schema_name}");
api.database().raw_cmd(&setup).await?;

let setup = format!("CREATE SCHEMA {other_name}");
api.database().raw_cmd(&setup).await?;

let setup = format!("CREATE SCHEMA third");
api.database().raw_cmd(&setup).await?;

let setup = formatdoc!(
r#"
CREATE TABLE [{schema_name}].[A] (
id INT IDENTITY,
data INT,
CONSTRAINT [A_pkey] PRIMARY KEY (id)
);
"#
);
api.database().raw_cmd(&setup).await?;

let setup = formatdoc!(
r#"
CREATE TABLE [{other_name}].[B] (
id INT IDENTITY,
data INT,
CONSTRAINT [B_pkey] PRIMARY KEY (id)
);
"#
);
api.database().raw_cmd(&setup).await?;

let setup = formatdoc!(
r#"
CREATE TABLE [third].[C] (
id INT IDENTITY,
data INT,
CONSTRAINT [C_pkey] PRIMARY KEY (id)
);
"#
);
api.database().raw_cmd(&setup).await?;

let expected = expect![[r#"
generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema"]
}

datasource db {
provider = "sqlserver"
url = "env(TEST_DATABASE_URL)"
schemas = ["first", "second"]
}

model A {
id Int @id @default(autoincrement())
data Int?

@@schema("first")
}

model B {
id Int @id @default(autoincrement())
data Int?

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

api.expect_datamodel(&expected).await;

Ok(())
}
4 changes: 4 additions & 0 deletions libs/sql-schema-describer/src/getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ pub trait Getter {
}

impl Getter for ResultRow {
#[track_caller]
fn get_expect_string(&self, name: &str) -> String {
self.get(name)
.and_then(|x| x.to_string())
.ok_or_else(|| format!("Getting {} from Resultrow {:?} as String failed", name, &self))
.unwrap()
}

#[track_caller]
fn get_expect_char(&self, name: &str) -> char {
self.get(name)
.and_then(|x| x.as_char())
.ok_or_else(|| format!("Getting {} from Resultrow {:?} as char failed", name, &self))
.unwrap()
}

#[track_caller]
fn get_expect_i64(&self, name: &str) -> i64 {
self.get(name)
.and_then(|x| x.as_integer())
.ok_or_else(|| format!("Getting {} from Resultrow {:?} as i64 failed", name, &self))
.unwrap()
}

#[track_caller]
fn get_expect_bool(&self, name: &str) -> bool {
self.get_bool(name)
.ok_or_else(|| format!("Getting {} from Resultrow {:?} as bool failed", name, &self))
Expand Down
2 changes: 2 additions & 0 deletions libs/sql-schema-describer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ pub struct Procedure {
/// A user-defined type. Can map to another type, or be declared as assembly.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct UserDefinedType {
///Namespace of the procedure
namespace_id: NamespaceId,
/// Type name
pub name: String,
/// Type mapping
Expand Down