From 002acbb9dc873f3ef2c8326fbdd11989dc96cb3e Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Wed, 7 May 2025 12:59:30 -0300 Subject: [PATCH] add check for unique contraint in auto index creation --- core/translate/schema.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/translate/schema.rs b/core/translate/schema.rs index 50bd6841d..d4060b11c 100644 --- a/core/translate/schema.rs +++ b/core/translate/schema.rs @@ -265,6 +265,7 @@ fn check_automatic_pk_index_required( options, } => { let mut primary_key_definition = None; + let mut has_unique_definition = false; // Check table constraints for PRIMARY KEY if let Some(constraints) = constraints { @@ -336,6 +337,8 @@ fn check_automatic_pk_index_required( typename, is_descending: false, }); + } else if matches!(constraint.constraint, ast::ColumnConstraint::Unique(..)) { + has_unique_definition = true; } } } @@ -346,7 +349,9 @@ fn check_automatic_pk_index_required( } // Check if we need an automatic index - let needs_auto_index = if let Some(primary_key_definition) = &primary_key_definition { + let needs_auto_index = if has_unique_definition { + true + } else if let Some(primary_key_definition) = &primary_key_definition { match primary_key_definition { PrimaryKeyDefinitionType::Simple { typename,