Skip to content

Commit

Permalink
feat(migrations): Add field in user to handle force change password (#…
Browse files Browse the repository at this point in the history
…323)

* feat(migrations): Add field in user to handle force change password

* feat(migrations): fix naming convention
  • Loading branch information
Mrkazik99 authored Sep 13, 2024
1 parent c99f4b0 commit 6fd3d64
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod m20240718_000010_create_userpermission;
mod m20240726_000001_normalize_schema;
mod m20240807_000001_add_segmentation_column;
mod m20240905_000001_add_user_active_admin_fields;
mod m20240907_000001_add_user_force_change_password_field;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
Expand All @@ -44,6 +45,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240726_000001_normalize_schema::Migration),
Box::new(m20240807_000001_add_segmentation_column::Migration),
Box::new(m20240905_000001_add_user_active_admin_fields::Migration),
Box::new(m20240907_000001_add_user_force_change_password_field::Migration),
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2024 Mateusz Kaźmierczakk.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// licenses/AGPL.txt.
use sea_orm_migration::prelude::*;

use crate::models::v1::User;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(
&self,
manager: &SchemaManager,
) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(User::Table)
.add_column(
ColumnDef::new(User::ForceChangePassword)
.boolean()
.not_null()
.default(false),
)
.to_owned(),
)
.await?;

Ok(())
}

async fn down(
&self,
manager: &SchemaManager,
) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(User::Table)
.drop_column(User::ForceChangePassword)
.to_owned(),
)
.await?;

Ok(())
}
}
1 change: 1 addition & 0 deletions migrations/src/models/v1/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum User {
IsEmailConfirmed,
IsAdmin,
IsActive,
ForceChangePassword,
Picture,
CreateTime,
UpdateTime,
Expand Down

0 comments on commit 6fd3d64

Please sign in to comment.