Files
MathApp/accounts/migrations/0008_remove_guest_login.py
Zareian 663252a260 Remove the guest system entirely: no is_guest/device_id, no guest throttles, phone login is the only way in
accounts.0008 drops the columns and refuses to run while guest rows exist.
Docs describe the current state; tests that only proved guest behaviour are gone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-05 18:20:10 +03:30

46 lines
1.5 KiB
Python

# Generated by Django 5.2.17 on 2026-10-05 14:25
from django.db import migrations
def refuse_if_guests_remain(apps, schema_editor):
"""
ورودِ مهمان حذف شده؛ ستونِ is_guest که برود، حسابِ مهمان بی‌هیچ نشانه‌ای یک کاربرِ بی‌شماره
می‌شود. پس تا مهمانی مانده، migration عمداً می‌شکند: اول مهمان‌ها را پاک کنید
(manage.py delete_users)، بعد migrate.
"""
User = apps.get_model('accounts', 'User')
left = User.objects.filter(is_guest=True).count()
if left:
raise RuntimeError(
f'{left} حسابِ مهمان (is_guest=True) هنوز در دیتابیس هست؛ پیش از این migration با '
f'delete_users پاکشان کنید، وگرنه به کاربرِ بی‌شماره تبدیل می‌شوند.'
)
class Migration(migrations.Migration):
dependencies = [
('accounts', '0007_hash_refresh_tokens'),
]
operations = [
migrations.RunPython(refuse_if_guests_remain, migrations.RunPython.noop),
migrations.RemoveConstraint(
model_name='user',
name='uniq_guest_device_id',
),
migrations.RemoveField(
model_name='session',
name='device_id',
),
migrations.RemoveField(
model_name='user',
name='device_id',
),
migrations.RemoveField(
model_name='user',
name='is_guest',
),
]