""" `10342` → اشتراکِ یک‌ماهه (۲۰۲۶-۱۰-۱۲، به گفته‌ی مالک «احتمالاً همان یک‌ماهه»؛ پیشخان را خودمان ندیده‌ایم). بازار آن را زیرِ com.tadrisino.math.app می‌شناسد؛ نوعش (اشتراکی یا تک‌خرید) را API بدونِ خریدِ واقعی نمی‌گوید. اگر اشتباه بود: «Bazaar sku» همان پلن را در ادمین خالی کنید. همان قاعده‌ی 0014: دقیقاً یک پلنِ فروشیِ ۳۰ روزه. """ from django.core.cache import cache from django.db import migrations SKU = '10342' def forward(apps, schema_editor): Plan = apps.get_model('subscription', 'Plan') if Plan.objects.filter(bazaar_sku=SKU).exists(): return plans = list(Plan.objects.filter(kind='subscription', on_sale=True, duration_days=30)) if len(plans) != 1: raise RuntimeError(f'SKUِ بازار {SKU}: باید دقیقاً یک اشتراکِ فروشیِ ۳۰ روزه باشد، {len(plans)} تا پیدا شد.') if not plans[0].bazaar_sku: plans[0].bazaar_sku = SKU plans[0].save(update_fields=['bazaar_sku']) cache.delete('subscription:plans:v3') # مثلِ 0014: سیگنالِ post_save در migration نمی‌آید def backward(apps, schema_editor): apps.get_model('subscription', 'Plan').objects.filter(bazaar_sku=SKU).update(bazaar_sku='') cache.delete('subscription:plans:v3') class Migration(migrations.Migration): dependencies = [('subscription', '0014_bazaar_skus_2026_10')] operations = [migrations.RunPython(forward, backward)]