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(introspection, sqlserver): Accept (and ignore) multi-line shared defaults #4884

Merged
merged 3 commits into from
May 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- tags=mssql2017

CREATE TABLE a (
id INT IDENTITY,
savings INT,
CONSTRAINT [A_pkey] PRIMARY KEY (id)
);

EXEC('/* This is a comment */' +
'CREATE DEFAULT NEARLY_NOTHING AS 0');
EXEC('sp_bindefault ''NEARLY_NOTHING'', ''a.savings''');
/*
generator js {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}

model a {
id Int @id(map: "A_pkey") @default(autoincrement())
savings Int?
}
*/
37 changes: 37 additions & 0 deletions schema-engine/sql-migration-tests/tests/migrations/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,43 @@ fn shared_default_constraints_are_ignored_issue_5423(api: TestApi) {
.assert_no_steps();
}

#[test_connector(tags(Mssql))]
fn shared_default_constraints_with_multilines_are_ignored_issue_24275(api: TestApi) {
let schema = api.schema_name();

api.raw_cmd(&format!(
r#"
/* This is a comment */
CREATE DEFAULT [{schema}].dogdog AS 'mugi'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐶

"#
));

api.raw_cmd(&format!(
r#"
CREATE TABLE [{schema}].dogs (
id INT IDENTITY,
name NVARCHAR(255) NOT NULL,
CONSTRAINT [dogs_pkey] PRIMARY KEY CLUSTERED ([id] ASC)
)
"#
));

api.raw_cmd(&format!("sp_bindefault '{schema}.dogdog', '{schema}.dogs.name'"));

let dm = r#"
model dogs {
id Int @id @default(autoincrement())
name String @db.NVarChar(255)
}
"#;

api.schema_push_w_datasource(dm)
.migration_id(Some("first"))
.send()
.assert_green()
.assert_no_steps();
}

#[test_connector(tags(Mssql))]
fn mssql_apply_migrations_error_output(api: TestApi) {
let dm = "";
Expand Down
2 changes: 1 addition & 1 deletion schema-engine/sql-schema-describer/src/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static DEFAULT_DB_GEN: Lazy<Regex> = Lazy::new(|| Regex::new(r"\((.*)\)").unwrap
/// ```ignore
/// CREATE DEFAULT catcat AS 'musti';
/// ```
static DEFAULT_SHARED_CONSTRAINT: Lazy<Regex> = Lazy::new(|| Regex::new(r"^CREATE DEFAULT (.*)").unwrap());
janpio marked this conversation as resolved.
Show resolved Hide resolved
static DEFAULT_SHARED_CONSTRAINT: Lazy<Regex> = Lazy::new(|| Regex::new(r"CREATE DEFAULT (.*)").unwrap());

pub struct SqlSchemaDescriber<'a> {
conn: &'a dyn Queryable,
Expand Down
Loading