SELECT profile_image, profile_image_back, migration_status, mapped_portal_user_id
	FROM public.zz_ref_entrainment_program_registration_info where program_id = 2 and migration_status = 'migrated' and mapped_portal_user_id is not null; --746


SELECT id, user_id, id_front_back_only_from_download_link, id_back_only_download_link, email_to_which_invoice_to_be_sent, name_in_which_invoice_to_be_issued, invoice_address, tan, gstin, are_you_registered_under_gst, when_was_your_last_hdb_msd, since_when_have_you_been_associated_with_this_path, how_many_hdb_msd_have_you_done, which_of_the_following_have_you_experienced, song_preference_1, song_preference_2, rm_rating, rm_review, contact_person, created_at, updated_at, deleted_at, created_by, updated_by, infinitheism_contact, pincode, hdb_year
	FROM public.user_profile_extension
	where user_id 
	in (SELECT mapped_portal_user_id
			FROM public.zz_ref_entrainment_program_registration_info 
			where program_id = 2
			and migration_status = 'migrated'
			and mapped_portal_user_id is not null)
	and (id_front_back_only_from_download_link is null 
	     or trim(id_front_back_only_from_download_link) = '' 
		 or id_back_only_download_link is null 
		 or trim(id_back_only_download_link) = '');



UPDATE public.user_profile_extension upe
SET 
    id_front_back_only_from_download_link = CASE 
        WHEN upe.id_front_back_only_from_download_link IS NULL 
             OR trim(upe.id_front_back_only_from_download_link) = '' 
        THEN ref.profile_image
        ELSE upe.id_front_back_only_from_download_link
    END,
    id_back_only_download_link = CASE 
        WHEN upe.id_back_only_download_link IS NULL 
             OR trim(upe.id_back_only_download_link) = '' 
        THEN ref.profile_image_back
        ELSE upe.id_back_only_download_link
    END
FROM public.zz_ref_entrainment_program_registration_info ref
WHERE upe.user_id = ref.mapped_portal_user_id
  AND ref.program_id = 2
  AND ref.migration_status = 'migrated'
  AND ref.mapped_portal_user_id IS NOT NULL; --746



SELECT id_front_back_only_from_download_link, id_back_only_download_link, email_to_which_invoice_to_be_sent, name_in_which_invoice_to_be_issued, invoice_address, tan, gstin, are_you_registered_under_gst, when_was_your_last_hdb_msd, since_when_have_you_been_associated_with_this_path, how_many_hdb_msd_have_you_done, which_of_the_following_have_you_experienced, song_preference_1, song_preference_2, rm_rating,infinitheism_contact, pincode, hdb_year
	FROM public.user_profile_extension upe 
	join hdb_program_registration hr on hr.user_id = upe.user_id
	where hr.program_id = 38
	and (id_front_back_only_from_download_link is null 
	     or trim(id_front_back_only_from_download_link) = ''); --397
		 
	

SELECT id_front_back_only_from_download_link, id_back_only_download_link, email_to_which_invoice_to_be_sent, name_in_which_invoice_to_be_issued, invoice_address, tan, gstin, are_you_registered_under_gst, when_was_your_last_hdb_msd, since_when_have_you_been_associated_with_this_path, how_many_hdb_msd_have_you_done, which_of_the_following_have_you_experienced, song_preference_1, song_preference_2, rm_rating,infinitheism_contact, pincode, hdb_year
	FROM public.user_profile_extension upe 
	join hdb_program_registration hr on hr.user_id = upe.user_id
	where hr.program_id = 38
	and (id_back_only_download_link is null 
		 or trim(id_back_only_download_link) = ''); --1005 



SELECT id_front_back_only_from_download_link, id_back_only_download_link, email_to_which_invoice_to_be_sent, name_in_which_invoice_to_be_issued, invoice_address, tan, gstin, are_you_registered_under_gst, when_was_your_last_hdb_msd, since_when_have_you_been_associated_with_this_path, how_many_hdb_msd_have_you_done, which_of_the_following_have_you_experienced, song_preference_1, song_preference_2, rm_rating,infinitheism_contact, pincode, hdb_year
	FROM public.user_profile_extension upe 
	join hdb_program_registration hr on hr.user_id = upe.user_id
	where hr.program_id = 38
	and (id_front_back_only_from_download_link is null 
	     or trim(id_front_back_only_from_download_link) = ''
		 or id_back_only_download_link is null 
		 or trim(id_back_only_download_link) = ''); --1005
