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>
46 lines
1.5 KiB
Python
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',
|
|
),
|
|
]
|