From fb681accc3e11e1ebe30f5fef88b285dea9bf125 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Sivakumar Date: Wed, 15 Jul 2026 00:57:39 +0530 Subject: [PATCH] fix(profile): use user_role_profile_id column, not id, for profession tables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The profession-specific tables (photographer_profiles, tutor_profiles, etc.) were extended with a separate user_role_profile_id FK column and a NOT NULL user_id column, but every generic profile query still treated the shared user_role_profiles.id value as if it were the profession table's own `id` PK, and never supplied user_id at all. Result: PATCH /api/profile 500'd with "null value in column user_id violates not-null constraint" on every first-time save for any of the 10 professional roles — profile saves were completely broken, which cascades into submit-for-verification always running off an empty fallback payload with no real data or documents. Fixes get_profile, save_profile, set_profile_status, and fetch_saved_profile_by_urp_id to query/write user_role_profile_id (and populate user_id on insert) instead of assuming id. Co-Authored-By: Claude Sonnet 5 --- apps/users/src/handlers/profile.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/users/src/handlers/profile.rs b/apps/users/src/handlers/profile.rs index 030b6fe..34a144d 100644 --- a/apps/users/src/handlers/profile.rs +++ b/apps/users/src/handlers/profile.rs @@ -156,7 +156,7 @@ async fn get_profile( }; let query = format!( - r#"SELECT custom_data, status FROM {} WHERE id = $1"#, + r#"SELECT custom_data, status FROM {} WHERE user_role_profile_id = $1"#, table ); @@ -333,9 +333,9 @@ async fn save_profile( let query = format!( r#" - INSERT INTO {table} (id, custom_data, status, updated_at) - VALUES ($1, $2, 'DRAFT', NOW()) - ON CONFLICT (id) DO UPDATE SET + INSERT INTO {table} (user_id, user_role_profile_id, custom_data, status, updated_at) + VALUES ($1, $2, $3, 'DRAFT', NOW()) + ON CONFLICT (user_id) DO UPDATE SET custom_data = EXCLUDED.custom_data, updated_at = NOW() "# @@ -347,6 +347,7 @@ async fn save_profile( }; match sqlx::query(&query) + .bind(auth.user_id) .bind(user_role_profile_id) .bind(&input.profile_data) .execute(&state.pool) @@ -610,7 +611,7 @@ async fn set_profile_status(state: &AppState, user_id: Uuid, role_key: &str, sta if let Some(table) = role_to_table(role_key) { let q = format!( - "UPDATE {} SET status = $1, updated_at = NOW() WHERE id = $2", + "UPDATE {} SET status = $1, updated_at = NOW() WHERE user_role_profile_id = $2", table ); sqlx::query(&q) @@ -670,7 +671,7 @@ async fn fetch_saved_profile_by_urp_id( role_key: &str, ) -> serde_json::Value { if let Some(table) = role_to_table(role_key) { - let q = format!(r#"SELECT custom_data FROM {} WHERE id = $1"#, table); + let q = format!(r#"SELECT custom_data FROM {} WHERE user_role_profile_id = $1"#, table); if let Ok(Some(row)) = sqlx::query(&q) .bind(user_role_profile_id) .fetch_optional(&state.pool)