mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-22 00:15:20 +01:00
Merge 'Fix tables renaming to existing index and rename indexed columns on ' from Levy A.
Simple bug fixes. Closes #2572
This commit is contained in:
@@ -323,7 +323,13 @@ pub fn translate_alter_table(
|
||||
ast::AlterTableBody::RenameTo(new_name) => {
|
||||
let new_name = new_name.as_str();
|
||||
|
||||
if schema.get_table(new_name).is_some() {
|
||||
if schema.get_table(new_name).is_some()
|
||||
|| schema
|
||||
.indexes
|
||||
.values()
|
||||
.flatten()
|
||||
.any(|index| index.name == normalize_ident(new_name))
|
||||
{
|
||||
return Err(LimboError::ParseError(format!(
|
||||
"there is already another table or index with this name: {new_name}"
|
||||
)));
|
||||
|
||||
@@ -7267,7 +7267,7 @@ pub fn op_rename_column(
|
||||
) -> Result<InsnFunctionStepResult> {
|
||||
load_insn!(
|
||||
RenameColumn {
|
||||
table,
|
||||
table: table_name,
|
||||
column_index,
|
||||
name
|
||||
},
|
||||
@@ -7279,7 +7279,7 @@ pub fn op_rename_column(
|
||||
conn.with_schema_mut(|schema| {
|
||||
let table = schema
|
||||
.tables
|
||||
.get_mut(table)
|
||||
.get_mut(table_name)
|
||||
.expect("table being renamed should be in schema");
|
||||
|
||||
let table = Arc::make_mut(table);
|
||||
@@ -7294,6 +7294,20 @@ pub fn op_rename_column(
|
||||
.columns
|
||||
.get_mut(*column_index)
|
||||
.expect("renamed column should be in schema");
|
||||
|
||||
if let Some(indexes) = schema.indexes.get_mut(table_name) {
|
||||
for index in indexes {
|
||||
let index = Arc::make_mut(index);
|
||||
for index_column in &mut index.columns {
|
||||
if index_column.name
|
||||
== *column.name.as_ref().expect("btree column should be named")
|
||||
{
|
||||
index_column.name = name.to_owned();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
column.name = Some(name.to_owned());
|
||||
});
|
||||
|
||||
|
||||
@@ -126,3 +126,15 @@ do_execsql_test_in_memory_any_error fail-alter-table-drop-primary-key-column-con
|
||||
CREATE TABLE t (a, b, PRIMARY KEY (a));
|
||||
ALTER TABLE t DROP a;
|
||||
}
|
||||
|
||||
do_execsql_test_in_memory_any_error fail-alter-table-rename-to-existing-index {
|
||||
CREATE TABLE x (a);
|
||||
CREATE INDEX y ON x (a);
|
||||
ALTER TABLE x RENAME TO y;
|
||||
}
|
||||
|
||||
do_execsql_test_in_memory_any_error fail-alter-table-rename-to-existing-table {
|
||||
CREATE TABLE x (a);
|
||||
CREATE TABLE y (a);
|
||||
ALTER TABLE x RENAME TO y;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user