Skip to content

Commit

Permalink
Indexes are not continously recreated due to missing index algo defau…
Browse files Browse the repository at this point in the history
…lt (prisma#2816)

* test that indexes are not continously recreated due to missing index algo default

* test on all dbs

* test all dbs

* keep the unwrap or default,
not about not rendering defaults to sql
  • Loading branch information
do4gr authored Mar 30, 2022
1 parent 27e0932 commit 135475a
Show file tree
Hide file tree
Showing 4 changed files with 26 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 @@ -247,6 +247,12 @@ pub enum SQLIndexAlgorithm {
Hash,
}

impl Default for SQLIndexAlgorithm {
fn default() -> Self {
Self::BTree
}
}

impl AsRef<str> for SQLIndexAlgorithm {
fn as_ref(&self) -> &str {
match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ impl SqlRenderer for PostgresFlavour {
is_unique: index.index_type().is_unique(),
table_reference: index.table().name().into(),
using: index.algorithm().map(|algo| match algo {
//todo we should think about not rendering this if it is the db default anyways
SQLIndexAlgorithm::BTree => ddl::IndexAlgorithm::BTree,
SQLIndexAlgorithm::Hash => ddl::IndexAlgorithm::Hash,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,5 @@ fn indexes_match(first: &IndexWalker<'_>, second: &IndexWalker<'_>) -> bool {
names_match && lengths_match && orders_match
})
&& first.index_type() == second.index_type()
&& first.algorithm() == second.algorithm()
&& first.algorithm().unwrap_or_default() == second.algorithm().unwrap_or_default()
}
18 changes: 18 additions & 0 deletions migration-engine/migration-engine-tests/tests/schema_push/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,21 @@ fn mysql_should_diff_column_ordering_correctly_issue_10983(api: TestApi) {
api.raw_cmd(ddl);
api.schema_push_w_datasource(dm).send().assert_green().assert_no_steps();
}

#[test_connector(preview_features("extendedIndexes"))]
fn issue_repro_extended_indexes(api: TestApi) {
// https://github.com/prisma/prisma/issues/11631

let dm = indoc! {r#"
model HouseholdTaxSettings {
householdId String
taxYear Int
@@unique([householdId, taxYear])
@@index([householdId])
}
"#};

api.schema_push_w_datasource(dm).send().assert_executable();
api.schema_push_w_datasource(dm).send().assert_green().assert_no_steps();
}

0 comments on commit 135475a

Please sign in to comment.