1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
use super::database_inspection_results::DatabaseInspectionResults;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Table {
pub table: String,
pub namespace: Option<String>,
}
impl Table {
pub fn from_column(column: &Column) -> Self {
Self {
table: column.table.clone(),
namespace: column.namespace.clone(),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Column {
pub table: String,
pub namespace: Option<String>,
pub column: String,
}
/// This trait should be implemented by warning and unexecutable migration types. It lets them
/// describe what data they need from the current state of the database to be as accurate and
/// informative as possible.
pub(super) trait Check {
/// Indicates that the row count for the table with the returned name should be inspected.
fn needed_table_row_count(&self) -> Option<Table> {
None
}
/// Indicates that the the number of non-null values should be inspected for the returned table and column.
fn needed_column_value_count(&self) -> Option<Column> {
None
}
/// This function will always be called for every check in a migration. Each change must check
/// for the data it needs in the database inspection results. If there is no data, it should
/// assume the current state of the database could not be inspected and warn with a best effort
/// message explaining under which conditions the migration could not be applied or would cause
/// data loss.
///
/// The only case where `None` should be returned is when there is data about the current state
/// of the database, and that data indicates that the migration step would be executable and
/// safe.
fn evaluate(&self, database_check_results: &DatabaseInspectionResults) -> Option<String>;
}