rustyroad 1.8.7

Rusty Road is a framework written in Rust that is based on Ruby on Rails. It is designed to provide the familiar conventions and ease of use of Ruby on Rails, while also taking advantage of the performance and efficiency of Rust.
use super::super::SqlOperation;
use super::action::Action;

pub(super) fn assemble(table: &str, stmt: &str, actions: Vec<Action>) -> Vec<SqlOperation> {
    let (mut adds, mut drops, mut other) = (Vec::new(), Vec::new(), Vec::new());
    for action in actions {
        match action {
            Action::Add(name) => adds.push(name),
            Action::Drop(name) => drops.push(name),
            Action::Constraint(name) => other.push(SqlOperation::Cleanup {
                summary: format!("ALTER TABLE {table} ADD CONSTRAINT {name}"),
                down_sql: format!("ALTER TABLE {table} DROP CONSTRAINT IF EXISTS {name};"),
            }),
            Action::Raw(sql) => other.push(SqlOperation::RawSql { sql }),
        }
    }
    let mut ops = Vec::new();
    if !adds.is_empty() {
        ops.push(SqlOperation::AlterTableAddColumn {
            table_name: table.to_string(),
            columns: adds,
            full_sql: stmt.to_string(),
        });
    }
    ops.extend(other);
    if !drops.is_empty() {
        ops.push(SqlOperation::AlterTableDropColumn {
            table_name: table.to_string(),
            columns: drops,
            full_sql: stmt.to_string(),
        });
    }
    ops
}