From 60d216bc224b7af9aeec9cf02ff3db294293b383 Mon Sep 17 00:00:00 2001 From: Matt <1009003+tantaman@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:08:40 -0400 Subject: [PATCH] fix automigrate when dropping columns on fractionally indexed tables --- core/rs/core/src/automigrate.rs | 4 ++++ .../rs/integration-check/tests/automigrate.rs | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/core/rs/core/src/automigrate.rs b/core/rs/core/src/automigrate.rs index 90091f608..efeda9392 100644 --- a/core/rs/core/src/automigrate.rs +++ b/core/rs/core/src/automigrate.rs @@ -240,6 +240,10 @@ fn drop_columns( table: &str, columns: Vec, ) -> Result { + local_db.exec_safe(&format!( + "DROP VIEW IF EXISTS \"{table}_fractindex\"", + table = crate::util::escape_ident(table) + ))?; for col in columns { local_db.exec_safe(&format!( "ALTER TABLE \"{table}\" DROP \"{column}\"", diff --git a/core/rs/integration-check/tests/automigrate.rs b/core/rs/integration-check/tests/automigrate.rs index fbf09812b..d9d36e06d 100644 --- a/core/rs/integration-check/tests/automigrate.rs +++ b/core/rs/integration-check/tests/automigrate.rs @@ -553,6 +553,28 @@ fn remove_col_impl() -> Result<(), ResultCode> { Ok(()) } +#[test] +fn remove_col_fract_table() { + let db = integration_utils::opendb().expect("db opened"); + db.db + .exec_safe("CREATE TABLE todo (id primary key, content text, position, thing)") + .expect("table made"); + db.db + .exec_safe("SELECT crsql_fract_as_ordered('todo', 'position');") + .expect("as ordered"); + + let schema = " + CREATE TABLE IF NOT EXISTS todo ( + id primary key, + content text, + position + ); + "; + invoke_automigrate(&db.db, schema).expect("migrated"); + + assert!(expect_columns(&db.db, "todo", vec!["id", "content", "position"]).expect("matched")); +} + fn remove_index_impl() -> Result<(), ResultCode> { let db = integration_utils::opendb()?; db.db.exec_safe(