Skip to content

Commit

Permalink
chore(users): change entity_type column of roles to non-optional (#6435)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 authored Oct 30, 2024
1 parent bb246e2 commit 62067e4
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/diesel_models/src/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ diesel::table! {
#[max_length = 64]
last_modified_by -> Varchar,
#[max_length = 64]
entity_type -> Nullable<Varchar>,
entity_type -> Varchar,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ diesel::table! {
#[max_length = 64]
last_modified_by -> Varchar,
#[max_length = 64]
entity_type -> Nullable<Varchar>,
entity_type -> Varchar,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/user_role/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/db/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/services/authorization/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 62067e4

Please sign in to comment.