Skip to content

Commit 60d216b

Browse files
committed
fix automigrate when dropping columns on fractionally indexed tables
1 parent d7de7d1 commit 60d216b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

core/rs/core/src/automigrate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ fn drop_columns(
240240
table: &str,
241241
columns: Vec<String>,
242242
) -> Result<ResultCode, ResultCode> {
243+
local_db.exec_safe(&format!(
244+
"DROP VIEW IF EXISTS \"{table}_fractindex\"",
245+
table = crate::util::escape_ident(table)
246+
))?;
243247
for col in columns {
244248
local_db.exec_safe(&format!(
245249
"ALTER TABLE \"{table}\" DROP \"{column}\"",

core/rs/integration-check/tests/automigrate.rs

+22
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,28 @@ fn remove_col_impl() -> Result<(), ResultCode> {
553553
Ok(())
554554
}
555555

556+
#[test]
557+
fn remove_col_fract_table() {
558+
let db = integration_utils::opendb().expect("db opened");
559+
db.db
560+
.exec_safe("CREATE TABLE todo (id primary key, content text, position, thing)")
561+
.expect("table made");
562+
db.db
563+
.exec_safe("SELECT crsql_fract_as_ordered('todo', 'position');")
564+
.expect("as ordered");
565+
566+
let schema = "
567+
CREATE TABLE IF NOT EXISTS todo (
568+
id primary key,
569+
content text,
570+
position
571+
);
572+
";
573+
invoke_automigrate(&db.db, schema).expect("migrated");
574+
575+
assert!(expect_columns(&db.db, "todo", vec!["id", "content", "position"]).expect("matched"));
576+
}
577+
556578
fn remove_index_impl() -> Result<(), ResultCode> {
557579
let db = integration_utils::opendb()?;
558580
db.db.exec_safe(

0 commit comments

Comments
 (0)