# Generated by Django 6.0.4 on 2026-08-04 06:35

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Achievement',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.TextField(verbose_name='成就名称')),
                ('description', models.TextField(verbose_name='成就描述')),
                ('icon', models.TextField(verbose_name='图标')),
                ('rarity', models.TextField(choices=[('bronze', '青铜'), ('silver', '白银'), ('gold', '黄金'), ('platinum', '白金')], default='bronze', verbose_name='稀有度')),
                ('hidden', models.BooleanField(db_default=False, default=False, verbose_name='是否隐藏')),
                ('metric', models.TextField(verbose_name='指标名')),
                ('operator', models.TextField(choices=[('gte', '大于等于'), ('lte', '小于等于')], default='gte', verbose_name='比较符')),
                ('threshold', models.IntegerField(verbose_name='阈值')),
                ('visible', models.BooleanField(db_default=True, default=True, verbose_name='是否上架')),
                ('unlock_count', models.IntegerField(db_default=0, default=0, verbose_name='已解锁人数')),
                ('order', models.IntegerField(db_default=0, default=0, verbose_name='排序')),
                ('create_time', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'verbose_name': '成就',
                'verbose_name_plural': '成就',
                'db_table': 'achievement',
                'ordering': ('order', 'id'),
            },
        ),
        migrations.CreateModel(
            name='UserStat',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('metrics', models.JSONField(db_default=models.Value({}, output_field=models.JSONField()), default=dict)),
                ('update_time', models.DateTimeField(auto_now=True)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='achievement_stat', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'user_stat',
            },
        ),
        migrations.CreateModel(
            name='UserAchievement',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('unlock_time', models.DateTimeField(auto_now_add=True)),
                ('backfilled', models.BooleanField(db_default=False, default=False)),
                ('notified', models.BooleanField(db_default=False, default=False)),
                ('achievement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='achievement.achievement')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='achievements', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'user_achievement',
                'ordering': ('-unlock_time',),
                'indexes': [models.Index(fields=['user', '-unlock_time'], name='user_achv_time_idx'), models.Index(fields=['user', 'notified'], name='user_achv_notified_idx')],
                'constraints': [models.UniqueConstraint(fields=('user', 'achievement'), name='unique_user_achievement')],
            },
        ),
    ]
