use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MigrationConfig {
pub path: PathBuf,
pub prefix_style: MigrationPrefixStyle,
pub checksums: bool,
pub statement_breakpoints: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MigrationPrefixStyle {
Sequential,
Timestamp,
}
impl Default for MigrationConfig {
fn default() -> Self {
Self {
path: PathBuf::from("toasty"),
prefix_style: MigrationPrefixStyle::Sequential,
checksums: false,
statement_breakpoints: true,
}
}
}
impl MigrationConfig {
pub fn new() -> Self {
Self::default()
}
pub fn path(mut self, path: impl Into<PathBuf>) -> Self {
self.path = path.into();
self
}
pub fn prefix_style(mut self, style: MigrationPrefixStyle) -> Self {
self.prefix_style = style;
self
}
pub fn get_migrations_dir(&self) -> PathBuf {
self.path.join("migrations")
}
pub fn get_snapshots_dir(&self) -> PathBuf {
self.path.join("snapshots")
}
pub fn get_history_file_path(&self) -> PathBuf {
self.path.join("history.toml")
}
}