# Generated by Django 6.0.1 on 2026-02-12 14:26

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('shop', '0027_wechatuser_is_star_wechatuser_title'),
    ]

    operations = [
        # 1. 迁移旧数据：将 goodsid_id 的值复制到 config_id
        migrations.RunSQL(
            sql="UPDATE shop_order SET config_id = goodsid_id WHERE config_id IS NULL AND goodsid_id IS NOT NULL;",
            reverse_sql="UPDATE shop_order SET goodsid_id = config_id WHERE goodsid_id IS NULL AND config_id IS NOT NULL;"
        ),
        # 2. 解除 goodsid_id 的非空限制，允许其为空（因为新代码不再写入此字段）
        migrations.RunSQL(
            sql="ALTER TABLE shop_order ALTER COLUMN goodsid_id DROP NOT NULL;",
            reverse_sql="ALTER TABLE shop_order ALTER COLUMN goodsid_id SET NOT NULL;"
        ),
    ]
