alter_table_row_type: set ColumnSchema::table_id's

This commit is contained in:
Mazdak Farrokhzad
2025-06-25 21:34:16 +02:00
parent 1e7791df0f
commit ebf0345e8a
2 changed files with 15 additions and 3 deletions
@@ -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<ColumnSchema>) -> Result<()> {
pub(crate) fn alter_table_row_type(
&mut self,
table_id: TableId,
mut column_schemas: Vec<ColumnSchema>,
) -> 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`
+4 -2
View File
@@ -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.
///