uqa_sql/schema/table_alteration/
ordering.rs1use crate::ast::AlterTableAction;
10
11#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
12pub enum AlterOrder {
13 Drop,
14 Type,
15 AddColumn,
16 SetExpression,
17 AddConstraint,
18 ColumnAttributes,
19 AddKey,
20 AddDefault,
21 Other,
22}
23
24pub fn execution_order(action: &AlterTableAction) -> AlterOrder {
25 match action {
26 AlterTableAction::DropColumn { .. }
27 | AlterTableAction::DropConstraint { .. }
28 | AlterTableAction::DropDefault { .. }
29 | AlterTableAction::DropNotNull { .. }
30 | AlterTableAction::DropIdentity { .. }
31 | AlterTableAction::DropExpression { .. } => AlterOrder::Drop,
32 AlterTableAction::AlterColumnType { .. } => AlterOrder::Type,
33 AlterTableAction::AddColumn { .. } => AlterOrder::AddColumn,
34 AlterTableAction::SetExpression { .. } => AlterOrder::SetExpression,
35 AlterTableAction::AddCheckConstraint { .. }
36 | AlterTableAction::AddNotNullConstraint { .. }
37 | AlterTableAction::AddForeignKeyConstraint { .. } => AlterOrder::AddConstraint,
38 AlterTableAction::SetNotNull { .. } => AlterOrder::ColumnAttributes,
39 AlterTableAction::AddKeyConstraint { .. } => AlterOrder::AddKey,
40 AlterTableAction::SetDefault { .. } | AlterTableAction::AddIdentity { .. } => {
41 AlterOrder::AddDefault
42 }
43 _ => AlterOrder::Other,
44 }
45}