fix(profile): use user_role_profile_id column, not id, for profession tables
All checks were successful
build-and-release / build (companies) (push) Successful in 4s
build-and-release / build (catering-services) (push) Successful in 5s
build-and-release / build (cron) (push) Successful in 5s
build-and-release / build (customers) (push) Successful in 5s
build-and-release / build (developers) (push) Successful in 4s
build-and-release / build (employees) (push) Successful in 5s
build-and-release / build (fitness-trainers) (push) Successful in 4s
build-and-release / build (gateway) (push) Successful in 4s
build-and-release / build (job-seekers) (push) Successful in 3s
build-and-release / build (graphic-designers) (push) Successful in 5s
build-and-release / build (jobs) (push) Successful in 5s
build-and-release / build (makeup-artists) (push) Successful in 4s
build-and-release / build (leads) (push) Successful in 5s
build-and-release / build (photographers) (push) Successful in 3s
build-and-release / build (payments) (push) Successful in 5s
build-and-release / build (tutors) (push) Successful in 5s
build-and-release / build (ugc-content-creators) (push) Successful in 3s
build-and-release / build (social-media-managers) (push) Successful in 5s
build-and-release / build (video-editors) (push) Successful in 3s
build-and-release / build (users) (push) Successful in 7m58s

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 <noreply@anthropic.com>
This commit is contained in:
Ashwin Kumar Sivakumar 2026-07-15 00:57:39 +05:30
parent 89a2076974
commit fb681accc3

View file

@ -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)