fix: handle mixed user_id formats in UUID migration backfill (refs #206)
Some checks failed
Deploy to Staging / Build Images (pull_request) Successful in 3m36s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 53s
Deploy to Staging / Verify Staging (pull_request) Failing after 8s
Deploy to Staging / Notify Staging Ready (pull_request) Has been skipped
Deploy to Staging / Notify Staging Failure (pull_request) Successful in 8s
Some checks failed
Deploy to Staging / Build Images (pull_request) Successful in 3m36s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 53s
Deploy to Staging / Verify Staging (pull_request) Failing after 8s
Deploy to Staging / Notify Staging Ready (pull_request) Has been skipped
Deploy to Staging / Notify Staging Failure (pull_request) Successful in 8s
user_preferences had rows where user_id already contained user_profiles.id (UUID) instead of auth0_sub. Added second backfill pass matching UUID-format values directly, and cleanup for 2 orphaned rows with no matching profile. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -76,6 +76,20 @@ UPDATE user_notifications SET user_profile_id = up.id
|
|||||||
UPDATE user_preferences SET user_profile_id = up.id
|
UPDATE user_preferences SET user_profile_id = up.id
|
||||||
FROM user_profiles up WHERE user_preferences.user_id = up.auth0_sub AND user_preferences.user_profile_id IS NULL;
|
FROM user_profiles up WHERE user_preferences.user_id = up.auth0_sub AND user_preferences.user_profile_id IS NULL;
|
||||||
|
|
||||||
|
-- 2a-fix. user_preferences has rows where user_id already contains user_profiles.id (UUID)
|
||||||
|
-- instead of auth0_sub. Match these directly by casting to UUID.
|
||||||
|
UPDATE user_preferences SET user_profile_id = up.id
|
||||||
|
FROM user_profiles up
|
||||||
|
WHERE user_preferences.user_id ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
|
||||||
|
AND user_preferences.user_id::uuid = up.id
|
||||||
|
AND user_preferences.user_profile_id IS NULL;
|
||||||
|
|
||||||
|
-- Delete truly orphaned user_preferences (UUID user_id with no matching user_profile)
|
||||||
|
DELETE FROM user_preferences
|
||||||
|
WHERE user_profile_id IS NULL
|
||||||
|
AND user_id ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
|
||||||
|
AND NOT EXISTS (SELECT 1 FROM user_profiles WHERE id = user_preferences.user_id::uuid);
|
||||||
|
|
||||||
UPDATE saved_stations SET user_profile_id = up.id
|
UPDATE saved_stations SET user_profile_id = up.id
|
||||||
FROM user_profiles up WHERE saved_stations.user_id = up.auth0_sub AND saved_stations.user_profile_id IS NULL;
|
FROM user_profiles up WHERE saved_stations.user_id = up.auth0_sub AND saved_stations.user_profile_id IS NULL;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user