use crate::adapters::bigquery::constants::RELAYOUT_SUFFIX;
use crate::adapters::bigquery::main::session::_layout_problems::layout_problems;
use crate::adapters::dispatch::models::Destination;
use crate::loader::errors::LoaderError;
use crate::loader::models::TableSpec;
pub async fn layout_drift(
destination: &Destination,
spec: &TableSpec,
(exists, reload): (bool, bool),
) -> Result<(Option<String>, Option<String>), LoaderError> {
let drift = match destination {
Destination::BigQuery(bigquery) if exists && !spec.layout.is_empty() => {
layout_problems(bigquery, &spec.destination, &spec.layout).await?
}
_ => None,
};
Ok(match (drift, reload) {
(None, _) => (None, None),
(Some(drift), false) => (
Some(format!(
"{drift}; load with --reload to rebuild it as configured, or change the config to match"
)),
None,
),
(Some(drift), true) => (
None,
Some(format!(
"{drift}; --reload renames the table to {}{RELAYOUT_SUFFIX} and creates it anew laid out as configured, then drops the renamed one, which keeps its rows should the load fail in between",
spec.destination.table
)),
),
})
}