mod promote;
use super::super::naming::temporary_name;
use super::super::quote::quote_ident;
pub struct Duplicate<'a> {
pub table: &'a str,
pub column: &'a str,
pub column_type: Option<&'a str>,
pub nullable: bool,
pub default: Option<&'a str>,
}
impl Duplicate<'_> {
pub fn shadow_name(&self) -> String {
temporary_name(self.column)
}
pub fn add_column(&self) -> String {
let mut sql = format!(
"ALTER TABLE {} ADD COLUMN IF NOT EXISTS {} {}",
quote_ident(self.table),
quote_ident(&self.shadow_name()),
self.column_type.unwrap_or("text")
);
if let Some(default) = self.default {
sql.push_str(&format!(" DEFAULT {default}"));
}
sql
}
}