# Generated by Codex on 2026-04-21

import uuid_utils.compat
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ("users", "0001_initial"),
    ]

    operations = [
        migrations.AlterField(
            model_name="user",
            name="password",
            field=models.CharField(max_length=256, verbose_name="密码"),
        ),
        migrations.AddField(
            model_name="user",
            name="last_login",
            field=models.DateTimeField(blank=True, db_index=True, null=True, verbose_name="最后登录时间"),
        ),
        migrations.AddField(
            model_name="user",
            name="last_active",
            field=models.DateTimeField(blank=True, db_index=True, null=True, verbose_name="最后活跃时间"),
        ),
        migrations.CreateModel(
            name="DeviceSession",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid_utils.compat.uuid7,
                        editable=False,
                        max_length=128,
                        primary_key=True,
                        serialize=False,
                        verbose_name="会话id",
                    ),
                ),
                ("device_id", models.CharField(db_index=True, max_length=128, verbose_name="设备id")),
                (
                    "access_token_hash",
                    models.CharField(db_index=True, max_length=128, unique=True, verbose_name="访问令牌摘要"),
                ),
                (
                    "refresh_token_hash",
                    models.CharField(db_index=True, max_length=128, unique=True, verbose_name="刷新令牌摘要"),
                ),
                ("password_hash", models.CharField(max_length=256, verbose_name="登录时密码摘要")),
                ("login_method", models.CharField(db_index=True, default="LOCAL", max_length=32, verbose_name="登录方式")),
                ("ip_address", models.CharField(blank=True, default="", max_length=64, verbose_name="登录IP")),
                ("user_agent", models.TextField(blank=True, default="", verbose_name="User-Agent")),
                ("access_expires_at", models.DateTimeField(db_index=True, verbose_name="访问令牌过期时间")),
                ("refresh_expires_at", models.DateTimeField(db_index=True, verbose_name="刷新令牌过期时间")),
                ("last_login", models.DateTimeField(blank=True, db_index=True, null=True, verbose_name="登录时间")),
                ("last_active", models.DateTimeField(blank=True, db_index=True, null=True, verbose_name="最后活跃时间")),
                ("revoked_at", models.DateTimeField(blank=True, db_index=True, null=True, verbose_name="吊销时间")),
                ("revoke_reason", models.CharField(blank=True, default="", max_length=128, verbose_name="吊销原因")),
                ("create_time", models.DateTimeField(auto_now_add=True, db_index=True, null=True, verbose_name="创建时间")),
                ("update_time", models.DateTimeField(auto_now=True, db_index=True, null=True, verbose_name="修改时间")),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="device_sessions",
                        to="users.user",
                        verbose_name="用户",
                    ),
                ),
            ],
            options={
                "db_table": "user_device_session",
            },
        ),
        migrations.AddIndex(
            model_name="devicesession",
            index=models.Index(fields=["user", "revoked_at"], name="user_device_user_id_87cd5e_idx"),
        ),
        migrations.AddIndex(
            model_name="devicesession",
            index=models.Index(fields=["refresh_expires_at", "revoked_at"], name="user_device_refresh_a45b49_idx"),
        ),
    ]
