Skip to main content

rustauth_core/plugin/db/
migration.rs

1/// Plugin migration metadata.
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct PluginMigration {
4    pub name: String,
5    pub body: Option<PluginMigrationBody>,
6}
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum PluginMigrationBody {
10    Sql(String),
11    Plan(Vec<PluginMigrationStep>),
12}
13
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct PluginMigrationStep {
16    pub description: String,
17    pub sql: Option<String>,
18}
19
20impl PluginMigration {
21    pub fn new(name: impl Into<String>) -> Self {
22        Self {
23            name: name.into(),
24            body: None,
25        }
26    }
27
28    #[must_use]
29    pub fn body(mut self, body: PluginMigrationBody) -> Self {
30        self.body = Some(body);
31        self
32    }
33}
34
35impl PluginMigrationStep {
36    pub fn new(description: impl Into<String>) -> Self {
37        Self {
38            description: description.into(),
39            sql: None,
40        }
41    }
42
43    #[must_use]
44    pub fn sql(mut self, sql: impl Into<String>) -> Self {
45        self.sql = Some(sql.into());
46        self
47    }
48}