Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading