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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/// Represents a payload for performing database diffs.
pub struct DiffPayload {
    first_db: String,
    second_db: String,
    only_tables: bool,
    only_sequences: bool,
    only_count: bool,
    chunk_size: i64,
    max_connections: i64,
    include_tables: Vec<String>,
    exclude_tables: Vec<String>,
    schema_name: String,
}

impl DiffPayload {
    /// Creates a new `DiffPayload` instance.
    ///
    /// # Arguments
    ///
    /// * `first_db` - The name of the first database.
    /// * `second_db` - The name of the second database.
    /// * `only_data` - A flag indicating whether to compare only data.
    /// * `only_sequences` - A flag indicating whether to compare only sequences.
    /// * `count_only` - A flag indicating whether to count differences only.
    /// * `chunk_size` - The chunk size for processing large tables.
    /// * `max_connections` - The maximum number of database connections to use.
    /// * `include_tables` - A list of tables to include in the comparison.
    /// * `exclude_tables` - A list of tables to exclude in the comparison.
    /// * `schema_name` - The name of the schema to compare.
    ///
    /// # Returns
    ///
    /// A new `DiffPayload` instance.
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        first_db: impl Into<String>,
        second_db: impl Into<String>,
        only_tables: bool,
        only_sequences: bool,
        only_count: bool,
        chunk_size: i64,
        max_connections: i64,
        include_tables: Vec<impl Into<String>>,
        exclude_tables: Vec<impl Into<String>>,
        schema_name: impl Into<String>,
    ) -> Self {
        let has_included_tables = !include_tables.is_empty();
        let has_excluded_tables = !exclude_tables.is_empty();

        if has_included_tables && has_excluded_tables {
            panic!("Cannot include and exclude tables at the same time");
        }

        Self {
            first_db: first_db.into(),
            second_db: second_db.into(),
            only_tables,
            only_sequences,
            only_count,
            chunk_size,
            max_connections,
            include_tables: include_tables.into_iter().map(|t| t.into()).collect(),
            exclude_tables: exclude_tables.into_iter().map(|t| t.into()).collect(),
            schema_name: schema_name.into(),
        }
    }

    pub fn first_db(&self) -> &str {
        &self.first_db
    }
    pub fn second_db(&self) -> &str {
        &self.second_db
    }
    pub fn only_tables(&self) -> bool {
        self.only_tables
    }
    pub fn only_sequences(&self) -> bool {
        self.only_sequences
    }
    pub fn only_count(&self) -> bool {
        self.only_count
    }
    pub fn chunk_size(&self) -> i64 {
        self.chunk_size
    }
    pub fn max_connections(&self) -> u32 {
        self.max_connections as u32
    }
    pub fn included_tables(&self) -> &Vec<String> {
        &self.include_tables
    }
    pub fn excluded_tables(&self) -> &Vec<String> {
        &self.exclude_tables
    }
    pub fn schema_name(&self) -> &str {
        &self.schema_name
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    #[should_panic = "Cannot include and exclude tables at the same time"]
    fn test_new_diff_payload() {
        _ = DiffPayload::new(
            "first_db",
            "second_db",
            false,
            false,
            false,
            10000,
            10,
            vec!["table1"],
            vec!["table2"],
            "schema_name",
        );
    }
}