# Generated by Django 4.2.29 on 2026-04-17 18:09

from django.db import migrations, models


def backfill_empty_resolution(apps, schema_editor):
    """将历史 resolution='' 的记录回填为 '720p'（choices 约束前的旧数据）。"""
    GenerationRecord = apps.get_model('generation', 'GenerationRecord')
    GenerationRecord.objects.filter(resolution='').update(resolution='720p')


def reverse_backfill(apps, schema_editor):
    """回滚时不恢复为空字符串（历史数据无法精确识别）。"""
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('generation', '0019_duration_nullable'),
    ]

    operations = [
        migrations.AddField(
            model_name='quotaconfig',
            name='base_token_price_1080p',
            field=models.DecimalField(decimal_places=2, default=51, max_digits=10, verbose_name='1080P单价-不含视频(元/百万tokens)'),
        ),
        migrations.AddField(
            model_name='quotaconfig',
            name='base_token_price_1080p_video',
            field=models.DecimalField(decimal_places=2, default=31, max_digits=10, verbose_name='1080P单价-含视频(元/百万tokens)'),
        ),
        # 先回填历史空值，再改 choices 约束，避免 MySQL 严格模式 IntegrityError
        migrations.RunPython(backfill_empty_resolution, reverse_backfill),
        migrations.AlterField(
            model_name='generationrecord',
            name='resolution',
            field=models.CharField(choices=[('480p', '480P'), ('720p', '720P'), ('1080p', '1080P')], default='720p', max_length=10, verbose_name='分辨率'),
        ),
    ]
