Skip to content

Commit

Permalink
Fix drift with missing sort order.
Browse files Browse the repository at this point in the history
Sometimes the database gives us nothing, and sometimes `ASC` depending on its
mood when sort order is not defined. We should compare `None` to be the same as
`Some(Asc)` in these cases.
  • Loading branch information
Julius de Bruijn authored and Julius de Bruijn committed Jan 6, 2022
1 parent 63af639 commit 9ca2234
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions libs/sql-schema-describer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ pub enum SQLSortOrder {
Desc,
}

impl Default for SQLSortOrder {
fn default() -> Self {
Self::Asc
}
}

impl AsRef<str> for SQLSortOrder {
fn as_ref(&self) -> &str {
match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn indexes_match(first: &IndexWalker<'_>, second: &IndexWalker<'_>) -> bool {
&& left_cols.zip(right_cols).all(|(a, b)| {
let names_match = a.as_column().name() == b.as_column().name();
let lengths_match = a.length() == b.length();
let orders_match = a.sort_order() == b.sort_order();
let orders_match = a.sort_order().unwrap_or_default() == b.sort_order().unwrap_or_default();

names_match && lengths_match && orders_match
})
Expand Down
27 changes: 27 additions & 0 deletions migration-engine/migration-engine-tests/tests/schema_push/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use indoc::indoc;
use migration_engine_tests::test_api::*;
use sql_schema_describer::ColumnTypeFamily;

Expand Down Expand Up @@ -393,3 +394,29 @@ fn implicit_relations_indices_are_not_renamed_unnecessarily(api: TestApi) {
.send_sync()
.assert_migration_directories_count(1);
}

#[test_connector(tags(Mysql), preview_features("extendedIndexes"))]
fn mysql_should_diff_column_ordering_correctly_issue_10983(api: TestApi) {
// https://github.com/prisma/prisma/issues/10983

let dm = indoc! {r#"
model a {
id Int @id @default(autoincrement())
b DateTime? @db.DateTime(6)
@@index([b], map: "IDX_b")
}
"#};

let ddl = r#"
CREATE TABLE `a` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`b` datetime(6) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_b` (`b`)
)
"#;

api.raw_cmd(ddl);
api.schema_push_w_datasource(dm).send().assert_green().assert_no_steps();
}

0 comments on commit 9ca2234

Please sign in to comment.