""" Session.refresh_token از این به بعد هشِ SHA-256 است (accounts/models.py، hash_refresh_token). ردیف‌های موجود هش می‌شوند تا توکن‌هایی که کلاینت‌ها در دست دارند همچنان کار کنند. از هش نمی‌شود خودِ توکن را ساخت؛ برگرداندنِ این migration هش‌ها را سرِ جایشان می‌گذارد و کدِ قبلی آن‌ها را نمی‌شناسد، یعنی هر کاربر یک بار دوباره وارد می‌شود. """ import hashlib from django.db import migrations def hash_existing(apps, schema_editor): Session = apps.get_model('accounts', 'Session') # اول مادی کردن، بعد نوشتن: کرسرِ بازِ SQLite وسطِ حلقه‌ی نوشتن قفل می‌سازد (CLAUDE.md). rows = list(Session.objects.values_list('id', 'refresh_token')) for pk, raw in rows: Session.objects.filter(pk=pk).update(refresh_token=hashlib.sha256(raw.encode()).hexdigest()) class Migration(migrations.Migration): dependencies = [ ('accounts', '0006_profile_birth_date_drop_parent_phone'), ] operations = [ migrations.RunPython(hash_existing, migrations.RunPython.noop), ]