Created
January 21, 2023 21:28
-
-
Save spookylukey/eeafa220b61e479694e2acf44902b6e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE "bookings_bookingaccount" | |
SET "email" = NULL, | |
"address_line1" = %s, | |
"address_line2" = %s, | |
"address_city" = %s, | |
"address_county" = %s, | |
"address_country" = NULL, | |
"address_post_code" = %s, | |
"phone_number" = %s, | |
"share_phone_number" = %s, | |
"email_communication" = %s, | |
"subscribe_to_mailings" = NULL, | |
"subscribe_to_newsletter" = %s, | |
"erased_on" = (CASE | |
WHEN erased_on IS NULL THEN %s | |
ELSE erased_on | |
END) | |
WHERE "bookings_bookingaccount"."id" IN | |
(SELECT V0."id" | |
FROM "bookings_bookingaccount" V0 | |
LEFT OUTER JOIN "bookings_booking" V1 ON (V0."id" = V1."account_id") | |
LEFT OUTER JOIN "bookings_payment" V2 ON (V0."id" = V2."account_id") | |
LEFT OUTER JOIN "cciwmain_camp" V3 ON (V1."camp_id" = V3."id") | |
WHERE (NOT (V0."id" IN | |
(SELECT U0."account_id" | |
FROM "bookings_booking" U0 | |
INNER JOIN "cciwmain_camp" U1 ON (U0."camp_id" = U1."id") | |
WHERE U1."end_date" >= %s)) | |
AND ((CASE | |
WHEN bookings_bookingaccount.last_login IS NOT NULL THEN bookings_bookingaccount.last_login | |
ELSE bookings_bookingaccount.created_at | |
END) < %s)) | |
GROUP BY V0."id" | |
HAVING (COALESCE(SUM(V1."amount_due") FILTER ( | |
WHERE NOT (V1."state" IN (%s, %s) | |
AND V1."state" IS NOT NULL)), %s) = (V0."total_received") | |
AND (MAX(V2."created_at") IS NULL | |
OR MAX(V2."created_at") < %s) | |
AND (MAX(V3."end_date") IS NULL | |
OR MAX(V3."end_date") < %s))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment