| 123456789101112131415161718192021222324252627 |
- -- Pass the affected company ID as $1. Only restore accounts created as coaches
- -- by the operations gateway that do not have formal student records.
- UPDATE "_User" u
- SET "identityType" = 'coach', "updatedAt" = now()
- WHERE u.company = $1
- AND u."legacyGroupId" = 3
- AND u."legacyUserId" > 0
- AND u."legacyUserData"->>'UserID' = u."legacyUserId"::text
- AND u."legacyUserData"->>'GroupID' = '3'
- AND COALESCE(u."legacyUserData"->>'OpsCreatedAt', '') <> ''
- AND COALESCE(u."identityType", '') IN ('', 'unknown', 'member')
- AND NOT COALESCE(u."isAdmin", false)
- AND NOT COALESCE(u."isDeleted", false)
- AND NOT EXISTS (
- SELECT 1 FROM "CourseAppointment" a
- WHERE a.company = u.company AND a.szyh::text = u."legacyUserId"::text
- UNION ALL
- SELECT 1 FROM "DailyStudyRecord" d
- WHERE d.company = u.company AND d."userId"::text = u."legacyUserId"::text
- UNION ALL
- SELECT 1 FROM "CourseBinding" b
- WHERE b.company = u.company AND b.yhid::text = u."legacyUserId"::text
- UNION ALL
- SELECT 1 FROM "LessonRecord" l
- WHERE l.company = u.company AND l.xymz::text = u."legacyUserId"::text
- )
- RETURNING u."objectId", u."legacyUserId";
|