pub mod backfill;
pub mod duplicate;
pub mod model;
mod plan_complete;
mod plan_start;
pub mod trigger;
use super::quote::quote_ident;
use model::Migration;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Plan {
pub statements: Vec<String>,
pub backfill_tables: Vec<String>,
pub promotions: Vec<(String, String)>,
pub drops: Vec<(String, String)>,
pub renames: Vec<(String, String, String)>,
pub deferred_not_null: Vec<(String, String)>,
}
pub fn plan(migration: &Migration, latest_schema: &str) -> Plan {
let mut combined = Plan::default();
for operation in &migration.operations {
let plan = plan_start::plan(operation, latest_schema);
combined.statements.extend(plan.statements);
combined.backfill_tables.extend(plan.backfill_tables);
combined.promotions.extend(plan.promotions);
combined.drops.extend(plan.drops);
combined.renames.extend(plan.renames);
combined.deferred_not_null.extend(plan.deferred_not_null);
}
combined.backfill_tables.sort();
combined.backfill_tables.dedup();
combined
}
fn new_ref(column: &str) -> String {
format!("NEW.{}", quote_ident(column))
}