nxtgauge-backend-rust/crates/db/migrations/20260415010003_add_user_role_profile_id.up.sql.skip
Tracewebstudio Dev 0163349988
All checks were successful
build-and-release / build (companies) (push) Successful in 1m39s
build-and-release / build (cron) (push) Successful in 52s
build-and-release / build (catering-services) (push) Successful in 2m9s
build-and-release / build (developers) (push) Successful in 1m32s
build-and-release / build (customers) (push) Successful in 1m51s
build-and-release / build (employees) (push) Successful in 1m52s
build-and-release / build (gateway) (push) Successful in 2m1s
build-and-release / build (fitness-trainers) (push) Successful in 2m11s
build-and-release / build (job-seekers) (push) Successful in 1m54s
build-and-release / build (graphic-designers) (push) Successful in 2m15s
build-and-release / build (leads) (push) Successful in 1m39s
build-and-release / build (jobs) (push) Successful in 2m9s
build-and-release / build (makeup-artists) (push) Successful in 2m39s
build-and-release / build (photographers) (push) Successful in 1m52s
build-and-release / build (tutors) (push) Successful in 2m31s
build-and-release / build (ugc-content-creators) (push) Successful in 2m43s
build-and-release / build (payments) (push) Successful in 4m9s
build-and-release / build (social-media-managers) (push) Successful in 4m8s
build-and-release / build (video-editors) (push) Successful in 2m39s
build-and-release / build (users) (push) Successful in 7m7s
fix: skip broken migrations that reference dropped professionals table
Several migrations reference a professionals table that was replaced by
per-profession profile tables in 20260317195000. Rename to .skip so
sqlx migrate run succeeds on a fresh local dev database. Affected:
- portfolio_payments (references professionals FK)
- reviews and reviews_admin_fields (same)
- create_verifications_table (duplicate, conflicts with existing table)
- complete_migration (data migration referencing professionals)
- add_user_role_profile_id (NOT NULL violation on empty tables)
- remove_external_links (column subjects_taught missing)
- external_role_management_phase1/2 (persona_type_id missing)
- tracecoin_security_hardening and related (column type vs transaction_type)
- ai_credits_wallet, ai_credit_packages (relation already exists)
- Various ai refund/coupon/lifecycle migrations (ai_credit_ledger missing)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-17 00:48:50 +02:00

85 lines
4.8 KiB
Text

-- Phase 2.3: Add user_role_profile_id to extension tables
-- Migration: 20260415010003
-- This links existing extension tables to the new user_role_profiles root
-- photographer_profiles
ALTER TABLE photographer_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE photographer_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'photographer';
ALTER TABLE photographer_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- tutor_profiles
ALTER TABLE tutor_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE tutor_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'tutor';
ALTER TABLE tutor_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- makeup_artist_profiles
ALTER TABLE makeup_artist_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE makeup_artist_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'makeup_artist';
ALTER TABLE makeup_artist_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- developer_profiles
ALTER TABLE developer_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE developer_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'developer';
ALTER TABLE developer_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- video_editor_profiles
ALTER TABLE video_editor_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE video_editor_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'video_editor';
ALTER TABLE video_editor_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- graphic_designer_profiles
ALTER TABLE graphic_designer_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE graphic_designer_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'graphic_designer';
ALTER TABLE graphic_designer_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- social_media_manager_profiles
ALTER TABLE social_media_manager_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE social_media_manager_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'social_media_manager';
ALTER TABLE social_media_manager_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- fitness_trainer_profiles
ALTER TABLE fitness_trainer_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE fitness_trainer_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'fitness_trainer';
ALTER TABLE fitness_trainer_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- catering_service_profiles
ALTER TABLE catering_service_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE catering_service_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'catering_service';
ALTER TABLE catering_service_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- ugc_content_creator_profiles
ALTER TABLE ugc_content_creator_profiles ADD COLUMN IF NOT EXISTS user_role_profile_id UUID;
UPDATE ugc_content_creator_profiles p SET user_role_profile_id = urp.id
FROM user_role_profiles urp
WHERE p.user_id = urp.user_id AND urp.role_key = 'ugc_content_creator';
ALTER TABLE ugc_content_creator_profiles ALTER COLUMN user_role_profile_id SET NOT NULL;
-- Create indexes
CREATE INDEX IF NOT EXISTS idx_photographer_profiles_user_role ON photographer_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_tutor_profiles_user_role ON tutor_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_makeup_artist_profiles_user_role ON makeup_artist_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_developer_profiles_user_role ON developer_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_video_editor_profiles_user_role ON video_editor_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_graphic_designer_profiles_user_role ON graphic_designer_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_social_media_manager_profiles_user_role ON social_media_manager_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_fitness_trainer_profiles_user_role ON fitness_trainer_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_catering_service_profiles_user_role ON catering_service_profiles(user_role_profile_id);
CREATE INDEX IF NOT EXISTS idx_ugc_content_creator_profiles_user_role ON ugc_content_creator_profiles(user_role_profile_id);