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
use sea_orm_migration::prelude::*;
/// Adds mfa_enabled, mfa_secret, and auth_source columns to the rustpbx_users
/// table for databases that were created before these fields were introduced.
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let table_name = "rustpbx_users";
if !manager.has_column(table_name, "mfa_enabled").await? {
manager
.alter_table(
Table::alter()
.table(super::user::Entity)
.add_column(
ColumnDef::new(super::user::Column::MfaEnabled)
.boolean()
.not_null()
.default(false),
)
.to_owned(),
)
.await?;
}
if !manager.has_column(table_name, "mfa_secret").await? {
manager
.alter_table(
Table::alter()
.table(super::user::Entity)
.add_column(
ColumnDef::new(super::user::Column::MfaSecret)
.string()
.char_len(64)
.null(),
)
.to_owned(),
)
.await?;
}
if !manager.has_column(table_name, "auth_source").await? {
manager
.alter_table(
Table::alter()
.table(super::user::Entity)
.add_column(
ColumnDef::new(super::user::Column::AuthSource)
.string()
.char_len(32)
.not_null()
.default("local"),
)
.to_owned(),
)
.await?;
}
Ok(())
}
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}