diff --git a/simulator/model/mod.rs b/simulator/model/mod.rs index 9f125a15b..a2120cd63 100644 --- a/simulator/model/mod.rs +++ b/simulator/model/mod.rs @@ -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(); } diff --git a/simulator/shrink/plan.rs b/simulator/shrink/plan.rs index 6da5d93e8..9f80f78cc 100644 --- a/simulator/shrink/plan.rs +++ b/simulator/shrink/plan.rs @@ -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 } => { diff --git a/sql_generation/generation/query.rs b/sql_generation/generation/query.rs index a21a37231..17fe0f843 100644 --- a/sql_generation/generation/query.rs +++ b/sql_generation/generation/query.rs @@ -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));