-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add timestamps for when email change is confirmed
- Loading branch information
1 parent
8ce0be6
commit 4b40eb3
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/migration/user/m20241226_203420_email_change_validation_timestamps.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::migration::user::User; | ||
use sea_orm_migration::{prelude::*, schema::*}; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager.alter_table(alter_table_add_columns()).await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager.alter_table(alter_table_drop_columns()).await | ||
} | ||
} | ||
|
||
fn alter_table_add_columns() -> TableAlterStatement { | ||
Table::alter() | ||
.table(User::Table) | ||
.add_column_if_not_exists(timestamp_with_time_zone_null( | ||
User::EmailChangeNewConfirmedAt, | ||
)) | ||
.add_column_if_not_exists(timestamp_with_time_zone_null( | ||
User::EmailChangeCurrentConfirmedAt, | ||
)) | ||
.to_owned() | ||
} | ||
|
||
fn alter_table_drop_columns() -> TableAlterStatement { | ||
Table::alter() | ||
.table(User::Table) | ||
.drop_column(User::EmailChangeNewConfirmedAt) | ||
.drop_column(User::EmailChangeCurrentConfirmedAt) | ||
.to_owned() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use insta::assert_snapshot; | ||
use sea_orm::sea_query::PostgresQueryBuilder; | ||
|
||
#[test] | ||
#[cfg_attr(coverage_nightly, coverage(off))] | ||
fn alter_table_add_columns() { | ||
let query = super::alter_table_add_columns(); | ||
|
||
assert_snapshot!(query.to_string(PostgresQueryBuilder)); | ||
} | ||
|
||
#[test] | ||
#[cfg_attr(coverage_nightly, coverage(off))] | ||
fn alter_table_drop_columns() { | ||
let query = super::alter_table_drop_columns(); | ||
|
||
assert_snapshot!(query.to_string(PostgresQueryBuilder)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters