Skip to main content

linkrs_migration/
config.rs

1use std::path::PathBuf;
2
3#[derive(Debug, Clone)]
4pub struct MigrationConfig {
5    pub batch_size: usize,
6    pub lock_ttl_secs: u64,
7    pub checkpoint_dir: Option<PathBuf>,
8    pub lock_path: Option<PathBuf>,
9    /// Minimum free disk space required on the checkpoint directory
10    /// filesystem before execution starts. 0 disables the preflight check.
11    pub min_free_bytes: u64,
12    /// Bounded stall for the schema-switch drain window. A timeout aborts
13    /// the migration instead of stretching the write stall.
14    pub drain_timeout_ms: u64,
15    /// Directory for pre-migration backups of destructive steps.
16    pub backup_dir: Option<PathBuf>,
17}
18
19impl Default for MigrationConfig {
20    fn default() -> Self {
21        Self {
22            batch_size: 1000,
23            lock_ttl_secs: 300,
24            checkpoint_dir: None,
25            lock_path: None,
26            min_free_bytes: 0,
27            drain_timeout_ms: 5000,
28            backup_dir: None,
29        }
30    }
31}
32
33impl MigrationConfig {
34    pub fn new() -> Self {
35        Self::default()
36    }
37
38    pub fn with_batch_size(mut self, batch_size: usize) -> Self {
39        self.batch_size = batch_size;
40        self
41    }
42
43    pub fn with_lock_ttl(mut self, ttl_secs: u64) -> Self {
44        self.lock_ttl_secs = ttl_secs;
45        self
46    }
47
48    pub fn with_checkpoint_dir(mut self, dir: impl Into<PathBuf>) -> Self {
49        self.checkpoint_dir = Some(dir.into());
50        self
51    }
52
53    pub fn with_lock_path(mut self, path: impl Into<PathBuf>) -> Self {
54        self.lock_path = Some(path.into());
55        self
56    }
57
58    pub fn with_min_free_bytes(mut self, min_free_bytes: u64) -> Self {
59        self.min_free_bytes = min_free_bytes;
60        self
61    }
62
63    pub fn with_drain_timeout_ms(mut self, drain_timeout_ms: u64) -> Self {
64        self.drain_timeout_ms = drain_timeout_ms;
65        self
66    }
67
68    pub fn with_backup_dir(mut self, dir: impl Into<PathBuf>) -> Self {
69        self.backup_dir = Some(dir.into());
70        self
71    }
72}