From 9ddae2e9c2bd8d6d2ac64d36e995d49970597729 Mon Sep 17 00:00:00 2001 From: Daniel Sonck Date: Thu, 5 Sep 2024 12:35:57 +0200 Subject: [PATCH] fix(migrations): add user IsActive and IsAdmin fields --- ...905_000001_add_user_active_admin_fields.rs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 migrations/src/m20240905_000001_add_user_active_admin_fields.rs diff --git a/migrations/src/m20240905_000001_add_user_active_admin_fields.rs b/migrations/src/m20240905_000001_add_user_active_admin_fields.rs new file mode 100644 index 000000000..3b9f7ee0d --- /dev/null +++ b/migrations/src/m20240905_000001_add_user_active_admin_fields.rs @@ -0,0 +1,60 @@ +// Copyright 2023 Daniƫl Sonck. +// +// 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(DeriveEntityModel)] +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::IsAdmin) + .boolean() + .not_null() + .default(false), + ) + .add_column( + ColumnDef::new(User::IsActive) + .boolean() + .not_null() + .default(true), + ) + .to_owned(), + ) + .await?; + + Ok(()) + } + + async fn down( + &self, + manager: &SchemaManager, + ) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(User::Table) + .drop_column(User::IsActive) + .drop_column(User::IsAdmin) + .to_owned(), + ) + .await?; + } +}