Skip to content

Commit

Permalink
fix automigrate when dropping columns on fractionally indexed tables
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Sep 11, 2023
1 parent d7de7d1 commit 60d216b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/rs/core/src/automigrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ fn drop_columns(
table: &str,
columns: Vec<String>,
) -> Result<ResultCode, ResultCode> {
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}\"",
Expand Down
22 changes: 22 additions & 0 deletions core/rs/integration-check/tests/automigrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 60d216b

Please sign in to comment.