chore(users): change entity_type column of roles to non-optional (#6435)

This commit is contained in:
Riddhiagrawal001
2024-10-30 18:02:15 +05:30
committed by GitHub
parent bb246e27b7
commit 62067e406a
8 changed files with 17 additions and 7 deletions

View File

@ -18,7 +18,7 @@ pub struct Role {
pub created_by: String,
pub last_modified_at: PrimitiveDateTime,
pub last_modified_by: String,
pub entity_type: Option<enums::EntityType>,
pub entity_type: enums::EntityType,
}
#[derive(router_derive::Setter, Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
@ -35,7 +35,7 @@ pub struct RoleNew {
pub created_by: String,
pub last_modified_at: PrimitiveDateTime,
pub last_modified_by: String,
pub entity_type: Option<enums::EntityType>,
pub entity_type: enums::EntityType,
}
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]

View File

@ -1235,7 +1235,7 @@ diesel::table! {
#[max_length = 64]
last_modified_by -> Varchar,
#[max_length = 64]
entity_type -> Nullable<Varchar>,
entity_type -> Varchar,
}
}

View File

@ -1181,7 +1181,7 @@ diesel::table! {
#[max_length = 64]
last_modified_by -> Varchar,
#[max_length = 64]
entity_type -> Nullable<Varchar>,
entity_type -> Varchar,
}
}

View File

@ -92,7 +92,7 @@ pub async fn create_role(
org_id: user_from_token.org_id,
groups: req.groups,
scope: req.role_scope,
entity_type: Some(EntityType::Merchant),
entity_type: EntityType::Merchant,
created_by: user_from_token.user_id.clone(),
last_modified_by: user_from_token.user_id,
created_at: now,

View File

@ -354,7 +354,7 @@ impl RoleInterface for MockDb {
None => true,
};
matches_merchant && role.org_id == *org_id && role.entity_type == entity_type
matches_merchant && role.org_id == *org_id && Some(role.entity_type) == entity_type
})
.take(limit_usize)
.cloned()

View File

@ -119,7 +119,7 @@ impl From<diesel_models::role::Role> for RoleInfo {
role_name: role.role_name,
groups: role.groups.into_iter().map(Into::into).collect(),
scope: role.scope,
entity_type: role.entity_type.unwrap_or(EntityType::Merchant),
entity_type: role.entity_type,
is_invitable: true,
is_deletable: true,
is_updatable: true,

View File

@ -0,0 +1,4 @@
-- This file should undo anything in `up.sql`
ALTER TABLE roles ALTER COLUMN entity_type DROP DEFAULT;
ALTER TABLE roles ALTER COLUMN entity_type DROP NOT NULL;

View File

@ -0,0 +1,6 @@
-- Your SQL goes here
UPDATE roles SET entity_type = 'merchant' WHERE entity_type IS NULL;
ALTER TABLE roles ALTER COLUMN entity_type SET DEFAULT 'merchant';
ALTER TABLE roles ALTER COLUMN entity_type SET NOT NULL;