# Generated by Django 4.2.27 on 2026-04-06 23:31

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


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="AbnormalUserLog",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "account_id",
                    models.CharField(
                        db_index=True, max_length=20, verbose_name="账号ID（phone）"
                    ),
                ),
                (
                    "ip_address",
                    models.GenericIPAddressField(
                        blank=True, null=True, verbose_name="IP地址"
                    ),
                ),
                (
                    "real_ip",
                    models.GenericIPAddressField(
                        blank=True, null=True, verbose_name="真实IP（穿透代理后）"
                    ),
                ),
                (
                    "x_forwarded_for",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=255,
                        verbose_name="X-Forwarded-For",
                    ),
                ),
                (
                    "user_agent",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=500,
                        verbose_name="User-Agent",
                    ),
                ),
                (
                    "request_method",
                    models.CharField(
                        blank=True, default="", max_length=10, verbose_name="请求方法"
                    ),
                ),
                (
                    "request_path",
                    models.CharField(
                        blank=True, default="", max_length=500, verbose_name="请求路径"
                    ),
                ),
                (
                    "request_params",
                    models.TextField(
                        blank=True, default="", verbose_name="请求参数（GET/POST）"
                    ),
                ),
                (
                    "request_body",
                    models.TextField(
                        blank=True, default="", verbose_name="请求体（原始）"
                    ),
                ),
                (
                    "request_headers",
                    models.TextField(
                        blank=True, default="", verbose_name="请求头（JSON格式）"
                    ),
                ),
                (
                    "attempt_type",
                    models.CharField(
                        blank=True, default="", max_length=50, verbose_name="攻击类型"
                    ),
                ),
                (
                    "detail",
                    models.TextField(blank=True, default="", verbose_name="详细描述"),
                ),
                (
                    "create_time",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
            ],
            options={
                "verbose_name": "异常用户日志",
                "verbose_name_plural": "异常用户日志",
                "db_table": "abnormal_user_log",
            },
        ),
        migrations.CreateModel(
            name="Permission",
            fields=[
                (
                    "perm_id",
                    models.AutoField(
                        primary_key=True, serialize=False, verbose_name="权限ID"
                    ),
                ),
                (
                    "perm_code",
                    models.CharField(
                        db_index=True,
                        max_length=100,
                        unique=True,
                        verbose_name="权限编码",
                    ),
                ),
                (
                    "perm_name",
                    models.CharField(max_length=100, verbose_name="权限名称"),
                ),
                (
                    "description",
                    models.CharField(
                        blank=True, default="", max_length=200, verbose_name="权限描述"
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
                (
                    "update_time",
                    models.DateTimeField(auto_now=True, verbose_name="更新时间"),
                ),
            ],
            options={
                "verbose_name": "权限",
                "verbose_name_plural": "权限",
                "db_table": "permission",
            },
        ),
        migrations.CreateModel(
            name="Role",
            fields=[
                (
                    "role_id",
                    models.AutoField(
                        primary_key=True, serialize=False, verbose_name="角色ID"
                    ),
                ),
                (
                    "role_code",
                    models.CharField(
                        db_index=True,
                        max_length=50,
                        unique=True,
                        verbose_name="角色编码",
                    ),
                ),
                ("role_name", models.CharField(max_length=50, verbose_name="角色名称")),
                (
                    "description",
                    models.CharField(
                        blank=True, default="", max_length=200, verbose_name="角色描述"
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
                (
                    "update_time",
                    models.DateTimeField(auto_now=True, verbose_name="更新时间"),
                ),
            ],
            options={
                "verbose_name": "角色",
                "verbose_name_plural": "角色",
                "db_table": "role",
            },
        ),
        migrations.CreateModel(
            name="UserRole",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                (
                    "account_id",
                    models.CharField(
                        db_index=True, max_length=11, verbose_name="账号ID"
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
                (
                    "update_time",
                    models.DateTimeField(auto_now=True, verbose_name="更新时间"),
                ),
                (
                    "role",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="houtai.role",
                        verbose_name="角色",
                    ),
                ),
            ],
            options={
                "verbose_name": "用户角色关联",
                "verbose_name_plural": "用户角色关联",
                "db_table": "user_role",
            },
        ),
        migrations.CreateModel(
            name="RolePermission",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                (
                    "create_time",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
                (
                    "permission",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="houtai.permission",
                        verbose_name="权限",
                    ),
                ),
                (
                    "role",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="houtai.role",
                        verbose_name="角色",
                    ),
                ),
            ],
            options={
                "verbose_name": "角色权限关联",
                "verbose_name_plural": "角色权限关联",
                "db_table": "role_permission",
            },
        ),
        migrations.AddIndex(
            model_name="role",
            index=models.Index(fields=["role_code"], name="role_role_co_b9f497_idx"),
        ),
        migrations.AddIndex(
            model_name="permission",
            index=models.Index(
                fields=["perm_code"], name="permission_perm_co_56cbe3_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="abnormaluserlog",
            index=models.Index(
                fields=["account_id"], name="abnormal_us_account_425899_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="abnormaluserlog",
            index=models.Index(
                fields=["ip_address"], name="abnormal_us_ip_addr_3d612b_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="abnormaluserlog",
            index=models.Index(
                fields=["create_time"], name="abnormal_us_create__ee16da_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="userrole",
            unique_together={("account_id", "role")},
        ),
        migrations.AlterUniqueTogether(
            name="rolepermission",
            unique_together={("role", "permission")},
        ),
    ]
