Skip to content

Commit

Permalink
prevent changing columns, this should've been considered destructive …
Browse files Browse the repository at this point in the history
…from the start
  • Loading branch information
jeromegn committed Nov 28, 2024
1 parent a3a2cc6 commit 2bf3890
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/corro-types/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ pub enum ApplySchemaError {
DropTableWithoutDestructiveFlag(String),
#[error("won't remove column without the destructive flag set (table: '{0}', column: '{1}')")]
RemoveColumnWithoutDestructiveFlag(String, String),
#[error("can't add a primary key (table: '{0}', column: '{1}')")]
#[error("won't change column without the destructive flag set (table: '{0}', column: '{1}')")]
ChangeColumnWithoutDestructiveFlag(String, String),
#[error("can't add a primary key (table: '{0}', columns: '{1}')")]
AddPrimaryKey(String, String),
#[error("can't modify primary keys (table: '{0}')")]
ModifyPrimaryKeys(String),
Expand Down Expand Up @@ -447,6 +449,14 @@ pub fn apply_schema(
changed_cols.keys().collect::<Vec<_>>()
);

if !changed_cols.is_empty() {
// TODO: add destructive flag
return Err(ApplySchemaError::ChangeColumnWithoutDestructiveFlag(
table.name.clone(),
changed_cols.keys().cloned().collect::<Vec<_>>().join(","),
));
}

let new_col_names = new_table
.columns
.keys()
Expand Down

0 comments on commit 2bf3890

Please sign in to comment.