Skip to content

Commit 2729d5a

Browse files
authored
fix: fix prisma#24068 (#5515)
[ORM-1099](https://linear.app/prisma-company/issue/ORM-1099/24068-sqlserver-migrate-issues) We've been discarding the namespace in a few places. I kept the namespace wherever it's available even if it's currently not used (mysql and sqlite). Fixes prisma/prisma#24068
1 parent 186ab85 commit 2729d5a

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

schema-engine/connectors/sql-schema-connector/src/flavour/mssql/destructive_change_checker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl DestructiveChangeCheckerFlavour for MssqlDestructiveChangeCheckerFlavour {
7676
plan.push_warning(
7777
SqlMigrationWarningCheck::RiskyCast {
7878
table: columns.previous.table().name().to_owned(),
79-
namespace: None,
79+
namespace: columns.previous.table().namespace().map(str::to_owned),
8080
column: columns.previous.name().to_owned(),
8181
previous_type,
8282
next_type,
@@ -88,7 +88,7 @@ impl DestructiveChangeCheckerFlavour for MssqlDestructiveChangeCheckerFlavour {
8888
plan.push_warning(
8989
SqlMigrationWarningCheck::NotCastable {
9090
table: columns.previous.table().name().to_owned(),
91-
namespace: None,
91+
namespace: columns.previous.table().namespace().map(str::to_owned),
9292
column: columns.previous.name().to_owned(),
9393
previous_type: format!("{:?}", columns.previous.column_type_family()),
9494
next_type: format!("{:?}", columns.next.column_type_family()),
@@ -134,7 +134,7 @@ impl DestructiveChangeCheckerFlavour for MssqlDestructiveChangeCheckerFlavour {
134134
SqlMigrationWarningCheck::DropAndRecreateColumn {
135135
column: columns.previous.name().to_owned(),
136136
table: columns.previous.table().name().to_owned(),
137-
namespace: None,
137+
namespace: columns.previous.table().namespace().map(str::to_owned),
138138
},
139139
step_index,
140140
)

schema-engine/connectors/sql-schema-connector/src/flavour/mysql/destructive_change_checker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl DestructiveChangeCheckerFlavour for MysqlDestructiveChangeCheckerFlavour {
7474
plan.push_warning(
7575
SqlMigrationWarningCheck::RiskyCast {
7676
table: columns.previous.table().name().to_owned(),
77-
namespace: None,
77+
namespace: columns.previous.table().namespace().map(str::to_owned),
7878
column: columns.previous.name().to_owned(),
7979
previous_type,
8080
next_type,
@@ -86,7 +86,7 @@ impl DestructiveChangeCheckerFlavour for MysqlDestructiveChangeCheckerFlavour {
8686
plan.push_warning(
8787
SqlMigrationWarningCheck::NotCastable {
8888
table: columns.previous.table().name().to_owned(),
89-
namespace: None,
89+
namespace: columns.previous.table().namespace().map(str::to_owned),
9090
column: columns.previous.name().to_owned(),
9191
previous_type,
9292
next_type,
@@ -133,7 +133,7 @@ impl DestructiveChangeCheckerFlavour for MysqlDestructiveChangeCheckerFlavour {
133133
SqlMigrationWarningCheck::DropAndRecreateColumn {
134134
column: columns.previous.name().to_owned(),
135135
table: columns.previous.table().name().to_owned(),
136-
namespace: None,
136+
namespace: columns.previous.table().namespace().map(str::to_owned),
137137
},
138138
step_index,
139139
)

schema-engine/connectors/sql-schema-connector/src/flavour/sqlite/destructive_change_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl DestructiveChangeCheckerFlavour for SqliteDestructiveChangeCheckerFlavour {
6161
plan.push_warning(
6262
SqlMigrationWarningCheck::RiskyCast {
6363
table: columns.previous.table().name().to_owned(),
64-
namespace: None,
64+
namespace: columns.previous.table().namespace().map(str::to_owned),
6565
column: columns.previous.name().to_owned(),
6666
previous_type: format!("{:?}", columns.previous.column_type_family()),
6767
next_type: format!("{:?}", columns.next.column_type_family()),

schema-engine/sql-migration-tests/tests/migrations/mssql/multi_schema.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,42 @@ fn multi_schema_tests(_api: TestApi) {
10751075
}),
10761076
skip: None,
10771077
},
1078+
TestData {
1079+
name: "issue prisma/prisma#24068",
1080+
description: "Modify the primary key of a table in a namespace",
1081+
schema: Schema {
1082+
common: base_schema.into(),
1083+
first: indoc! {r#"
1084+
model Report {
1085+
id String @id
1086+
1087+
@@schema("two")
1088+
}"#}
1089+
.into(),
1090+
second: Some(indoc! {r#"
1091+
model Report {
1092+
id String @id @unique @db.NVarChar(450)
1093+
1094+
@@schema("two")
1095+
}"#}
1096+
.into())
1097+
},
1098+
namespaces,
1099+
schema_push: SchemaPush::PushAnd(WithSchema::First, &SchemaPush::PushCustomAnd(CustomPushStep {
1100+
warnings: &["A unique constraint covering the columns `[id]` on the table `Report` will be added. If there are existing duplicate values, this will fail."],
1101+
errors: &[],
1102+
with_schema: WithSchema::Second,
1103+
executed_steps: ExecutedSteps::NonZero,
1104+
}, &SchemaPush::Done)),
1105+
assertion: Box::new(|assert| {
1106+
assert
1107+
.assert_has_table_with_ns("two", "Report")
1108+
.assert_table_with_ns("two", "Report", |table| {
1109+
table.assert_column("id", |column| column.assert_is_required().assert_type_is_string())
1110+
});
1111+
}),
1112+
skip: None,
1113+
},
10781114
];
10791115

10801116
// traverse_ is always the answer

0 commit comments

Comments
 (0)