generate ALTER COLUMN

This commit is contained in:
pedrocarlo
2025-10-10 00:04:38 -03:00
parent a18a472685
commit 49e96afd39
3 changed files with 28 additions and 5 deletions

View File

@@ -561,8 +561,6 @@ impl Shadow for AlterTable {
});
}
AlterTableType::AlterColumn { old, new } => {
// TODO: have to see correct behaviour with indexes to see if we should error out
// in case there is some sort of conflict with this change
let col = table.columns.iter_mut().find(|c| c.name == *old).unwrap();
*col = new.clone();
}

View File

@@ -120,6 +120,8 @@ impl InteractionPlan {
| Property::DeleteSelect { queries, .. }
| Property::DropSelect { queries, .. }
| Property::Queries { queries } => {
// Remove placeholder queries
queries.retain(|query| !matches!(query, Query::Placeholder));
extensional_queries.append(queries);
}
Property::AllTableHaveExpectedContent { tables } => {

View File

@@ -456,7 +456,31 @@ impl ArbitraryFrom<(&Table, &[AlterTableTypeDiscriminants])> for AlterTableType
column: Column::arbitrary(rng, context),
},
AlterTableTypeDiscriminants::AlterColumn => {
todo!();
let col_diff = get_column_diff(table);
if col_diff.is_empty() {
// Generate a DropColumn if we can drop a column
return AlterTableType::arbitrary_from(
rng,
context,
(
table,
if choices.contains(&AlterTableTypeDiscriminants::DropColumn) {
ALTER_TABLE_NO_ALTER_COL
} else {
ALTER_TABLE_NO_ALTER_COL_NO_DROP
},
),
);
}
let col_idx = pick_index(col_diff.len(), rng);
let col_name = col_diff.get_index(col_idx).unwrap();
AlterTableType::AlterColumn {
old: col_name.to_string(),
new: Column::arbitrary(rng, context),
}
}
AlterTableTypeDiscriminants::RenameColumn => AlterTableType::RenameColumn {
old: pick(&table.columns, rng).name.clone(),
@@ -501,8 +525,7 @@ impl Arbitrary for AlterTable {
) {
(true, true) => ALTER_TABLE_ALL,
(true, false) => ALTER_TABLE_NO_ALTER_COL,
(false, true) => ALTER_TABLE_NO_DROP,
(false, false) => ALTER_TABLE_NO_ALTER_COL_NO_DROP,
(false, true) | (false, false) => ALTER_TABLE_NO_ALTER_COL_NO_DROP,
};
let alter_table_type = AlterTableType::arbitrary_from(rng, context, (table, choices));