migratrom 0.2.0

Declarative, self-verifying database migrations (core engine).
Documentation
//! Column-definition rendering for `CREATE TABLE` / `ADD COLUMN`.

use super::identifiers::quote_ident;
use crate::types::ColumnDef;

/// Render one column line: `"name" type [DEFAULT ...] [NOT NULL]`.
pub fn render_column_def(col: &ColumnDef) -> String {
    let mut parts = vec![quote_ident(&col.name), col.type_sql.clone()];
    if let Some(default_sql) = &col.default_sql {
        parts.push(default_sql.clone());
    }
    if !col.nullable {
        parts.push("NOT NULL".to_string());
    }
    parts.join(" ")
}

/// Comma-joined column definition lines (newline-indented, as the siblings do).
pub fn render_column_list(columns: &[ColumnDef]) -> String {
    columns
        .iter()
        .map(render_column_def)
        .collect::<Vec<_>>()
        .join(",\n  ")
}