use super::Duplicate;
use crate::database::versions::quote::quote_ident;
impl Duplicate<'_> {
pub fn promote(&self) -> Vec<String> {
let table = quote_ident(self.table);
let mut statements = vec![
format!(
"ALTER TABLE {table} DROP COLUMN IF EXISTS {}",
quote_ident(self.column)
),
format!(
"ALTER TABLE {table} RENAME COLUMN {} TO {}",
quote_ident(&self.shadow_name()),
quote_ident(self.column)
),
];
if !self.nullable {
statements.push(format!(
"ALTER TABLE {table} ALTER COLUMN {} SET NOT NULL",
quote_ident(self.column)
));
}
statements
}
pub fn discard(&self) -> String {
format!(
"ALTER TABLE {} DROP COLUMN IF EXISTS {}",
quote_ident(self.table),
quote_ident(&self.shadow_name())
)
}
}