From 6fd3d6439c81ce7e2e8d418aa54926e807be7d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ka=C5=BAmierczak?= <38044074+Mrkazik99@users.noreply.github.com> Date: Fri, 13 Sep 2024 07:35:55 +0200 Subject: [PATCH] feat(migrations): Add field in user to handle force change password (#323) * feat(migrations): Add field in user to handle force change password * feat(migrations): fix naming convention --- migrations/src/lib.rs | 2 + ...01_add_user_force_change_password_field.rs | 55 +++++++++++++++++++ migrations/src/models/v1/user.rs | 1 + 3 files changed, 58 insertions(+) create mode 100644 migrations/src/m20240907_000001_add_user_force_change_password_field.rs diff --git a/migrations/src/lib.rs b/migrations/src/lib.rs index 5b854888b..92ace16f2 100644 --- a/migrations/src/lib.rs +++ b/migrations/src/lib.rs @@ -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 { @@ -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), ] } } diff --git a/migrations/src/m20240907_000001_add_user_force_change_password_field.rs b/migrations/src/m20240907_000001_add_user_force_change_password_field.rs new file mode 100644 index 000000000..3e57bf370 --- /dev/null +++ b/migrations/src/m20240907_000001_add_user_force_change_password_field.rs @@ -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(()) + } +} diff --git a/migrations/src/models/v1/user.rs b/migrations/src/models/v1/user.rs index 0ef3134df..76b3c2532 100644 --- a/migrations/src/models/v1/user.rs +++ b/migrations/src/models/v1/user.rs @@ -26,6 +26,7 @@ pub enum User { IsEmailConfirmed, IsAdmin, IsActive, + ForceChangePassword, Picture, CreateTime, UpdateTime,