diff --git a/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs b/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs index f598a9bdbe..5abccdf852 100644 --- a/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs +++ b/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs @@ -436,10 +436,20 @@ impl MutTxId { /// as the update machinery should disallow any incompatible change. /// However, for redundancy and internal soundness of the datastore, /// the compatibility is also checked here. - pub(crate) fn alter_table_row_type(&mut self, table_id: TableId, column_schemas: Vec) -> Result<()> { + pub(crate) fn alter_table_row_type( + &mut self, + table_id: TableId, + mut column_schemas: Vec, + ) -> Result<()> { // Write to the table in the tx state. let ((tx_table, ..), (commit_table, ..)) = self.get_or_create_insert_table_mut(table_id)?; + // Ensure the columns have the right `table_id`. + // NOTE(centril): This should already be done by the update machinery, + // but do it redundantly here too, just in case. + // This is not performance critical, so we don't care that there is overhead. + column_schemas.iter_mut().for_each(|c| c.table_id = table_id); + // Try to change the tables into what we want. let old_column_schemas = tx_table.change_columns_to(column_schemas).map_err(TableError::from)?; // SAFETY: `commit_table` should have a schema identical to that of `tx_table` diff --git a/crates/table/src/table.rs b/crates/table/src/table.rs index 74686d033e..eb41970231 100644 --- a/crates/table/src/table.rs +++ b/crates/table/src/table.rs @@ -291,7 +291,8 @@ impl Table { Self::new_raw(schema, row_layout, static_layout, visitor_prog, squashed_offset, pm) } - /// Change the columns of `self` to those in `column_schemas`. + /// Change the columns of `self` to those in `column_schemas` + /// and returns the old column schemas. /// /// Returns an error if the new list of column is incompatible with the old. pub fn change_columns_to( @@ -334,7 +335,8 @@ impl Table { unsafe { self.change_columns_to_unchecked(column_schemas, validate) } } - /// Change the columns of `self` to those in `column_schemas`. + /// Change the columns of `self` to those in `column_schemas` + /// and returns the old column schemas. /// /// Returns an error if the new list of column is incompatible with the old. ///