use sql_splitter::generate::{CompileOptions, Generate, TableCountOverride};
use sql_splitter::parser::SqlDialect;
use tempfile::{NamedTempFile, TempPath};
fn model_path() -> std::path::PathBuf {
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/generate/legacy_fixture.yaml")
}
pub fn generated_fixture(
dialect: SqlDialect,
rows: Option<u64>,
tables: Option<&[&str]>,
seed: u64,
) -> TempPath {
let path = NamedTempFile::new()
.expect("create temp file for generated fixture")
.into_temp_path();
let mut compile = CompileOptions {
seed: Some(seed),
..Default::default()
};
if let Some(rows) = rows {
compile
.table_rows
.push(TableCountOverride::rows("tenants", rows));
}
if let Some(tables) = tables {
compile.tables = tables.iter().map(|t| t.to_string()).collect();
}
Generate::builder()
.config(model_path())
.output_dialect(dialect)
.compile(compile)
.output(path.to_path_buf())
.run()
.expect("generate legacy fixture from the public generate API");
path
}