-
-
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 User column to store the user's new email before it's confi…
…rmed (#536)
- Loading branch information
1 parent
72cb363
commit 8ce0be6
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
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,52 @@ | ||
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(string_null(User::PendingEmail)) | ||
.to_owned() | ||
} | ||
|
||
fn alter_table_drop_columns() -> TableAlterStatement { | ||
Table::alter() | ||
.table(User::Table) | ||
.drop_column(User::PendingEmail) | ||
.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
6 changes: 6 additions & 0 deletions
6
...ter__migration__user__m20241226_080735_pending_email__tests__alter_table_add_columns.snap
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,6 @@ | ||
--- | ||
source: src/migration/user/m20241226_080735_pending_email.rs | ||
expression: query.to_string(PostgresQueryBuilder) | ||
snapshot_kind: text | ||
--- | ||
ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "pending_email" varchar NULL |
6 changes: 6 additions & 0 deletions
6
...er__migration__user__m20241226_080735_pending_email__tests__alter_table_drop_columns.snap
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,6 @@ | ||
--- | ||
source: src/migration/user/m20241226_080735_pending_email.rs | ||
expression: query.to_string(PostgresQueryBuilder) | ||
snapshot_kind: text | ||
--- | ||
ALTER TABLE "user" DROP COLUMN "pending_email" |
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