mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 17:05:36 +01:00
Merge 'Return error on attempting to drop index associated with PRIMARY KEY and UNIQUE constraints' from
Closes issue #2455. Also includes tests. Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com> Closes #2461
This commit is contained in:
@@ -353,6 +353,15 @@ pub fn translate_drop_index(
|
||||
)));
|
||||
}
|
||||
}
|
||||
// Return an error if the index is associated with a unique or primary key constraint.
|
||||
if let Some(idx) = maybe_index {
|
||||
if idx.unique {
|
||||
return Err(crate::error::LimboError::InvalidArgument(
|
||||
"index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let cdc_table = prepare_cdc_if_necessary(&mut program, schema, SQLITE_TABLEID)?;
|
||||
|
||||
|
||||
@@ -44,3 +44,15 @@ do_execsql_test_on_specific_db {:memory:} drop-index-after-ops-1 {
|
||||
DROP INDEX t_idx6;
|
||||
SELECT count(*) FROM sqlite_schema WHERE type='index' AND name='t_idx6';
|
||||
} {0}
|
||||
|
||||
# Test dropping of indices associated with unique or primary contraint indices produces an error
|
||||
do_execsql_test_in_memory_error_content drop-index-primary-key-index {
|
||||
CREATE TABLE t15a (id TEXT PRIMARY KEY );
|
||||
DROP INDEX sqlite_autoindex_t15a_1;
|
||||
} {"index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped"}
|
||||
|
||||
|
||||
do_execsql_test_in_memory_error_content drop-index-unique-index {
|
||||
CREATE TABLE t15b (id INT UNIQUE );
|
||||
DROP INDEX sqlite_autoindex_t15b_1;
|
||||
} {"index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped"}
|
||||
@@ -191,9 +191,13 @@ proc run_test_expecting_error_content {sqlite_exec db_name sql expected_error_te
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Remove box-drawing characters, multiplication signs, and other non-ASCII junk
|
||||
set cleaned_result [regsub -all {[\u2500-\u257F\u00D7]} $result ""]
|
||||
#TODO any other possible cleanups?
|
||||
|
||||
# Normalize both the actual and expected error messages
|
||||
# Remove all whitespace, newlines, and special characters for comparison
|
||||
set normalized_actual [regsub -all {[[:space:]]|[[:punct:]]} $result ""]
|
||||
set normalized_actual [regsub -all {[[:space:]]|[[:punct:]]} $cleaned_result ""]
|
||||
set normalized_expected [regsub -all {[[:space:]]|[[:punct:]]} $expected_error_text ""]
|
||||
|
||||
# Convert to lowercase for case-insensitive comparison
|
||||
|
||||
Reference in New Issue
Block a user