migrations: Update 0516 to handle invites with non-default streams.

We update the existing migration, because any deployment which had
invitations with non-default streams in this state cannot have
proceeded past this migration yet.
This commit is contained in:
Alex Vandiver 2024-05-08 16:51:40 +00:00 committed by Tim Abbott
parent 3f80bc1b41
commit a1a14527db
1 changed files with 22 additions and 11 deletions

View File

@ -30,16 +30,18 @@ WHERE id IN (WITH too_many_confirmations
)
"""
NO_CONFIRMATIONS = """
DELETE FROM zerver_preregistrationuser
WHERE NOT EXISTS(SELECT 1
FROM confirmation_confirmation
WHERE content_type_id = (SELECT id
FROM django_content_type
WHERE app_label = 'zerver'
AND model = 'preregistrationuser')
AND object_id = zerver_preregistrationuser.id)
AND referred_by_id IS NOT NULL
NO_CONFIRMATIONS_TEMP_TABLE = """
CREATE TEMPORARY TABLE zerver_0516_no_confirmations AS (
SELECT id FROM zerver_preregistrationuser
WHERE NOT EXISTS(SELECT 1
FROM confirmation_confirmation
WHERE content_type_id = (SELECT id
FROM django_content_type
WHERE app_label = 'zerver'
AND model = 'preregistrationuser')
AND object_id = zerver_preregistrationuser.id)
AND referred_by_id IS NOT NULL
)
"""
@ -55,5 +57,14 @@ class Migration(migrations.Migration):
operations = [
migrations.RunSQL(TOO_MANY_CONFIRMATIONS, elidable=True),
migrations.RunSQL(NO_CONFIRMATIONS, elidable=True),
migrations.RunSQL(NO_CONFIRMATIONS_TEMP_TABLE, elidable=True),
migrations.RunSQL(
"DELETE FROM zerver_preregistrationuser_streams WHERE preregistrationuser_id IN (SELECT id FROM zerver_0516_no_confirmations)",
elidable=True,
),
migrations.RunSQL(
"DELETE FROM zerver_preregistrationuser WHERE id IN (SELECT id FROM zerver_0516_no_confirmations)",
elidable=True,
),
migrations.RunSQL("DROP TABLE zerver_0516_no_confirmations", elidable=True),
]