toasty_core/schema/db/
migration.rs

1/// Database migration generate from a [`super::SchemaDiff`] by a driver.
2pub enum Migration {
3    Sql(String),
4}
5
6impl Migration {
7    /// Create a new SQL migration from a single SQL string.
8    pub fn new_sql(sql: String) -> Self {
9        Migration::Sql(sql)
10    }
11
12    /// Create a new SQL migration from multiple SQL statements.
13    /// Statements are joined with breakpoint markers.
14    pub fn new_sql_with_breakpoints<S: AsRef<str>>(statements: &[S]) -> Self {
15        let sql = statements
16            .iter()
17            .map(|s| s.as_ref())
18            .collect::<Vec<_>>()
19            .join("\n-- #[toasty::breakpoint]\n");
20        Migration::Sql(sql)
21    }
22
23    /// Get individual SQL statements by splitting on breakpoint markers.
24    pub fn statements(&self) -> Vec<&str> {
25        match self {
26            Migration::Sql(sql) => sql.split("\n-- #[toasty::breakpoint]\n").collect(),
27        }
28    }
29}
30
31/// Metadata about a migration that has already been applied to a database.
32pub struct AppliedMigration {
33    id: u64,
34}
35
36impl AppliedMigration {
37    pub fn new(id: u64) -> Self {
38        Self { id }
39    }
40
41    pub fn id(&self) -> u64 {
42        self.id
43    }
44}