# Generated by Django 5.2.3 on 2025-06-23 02:14
from django.db.models import QuerySet

import application.models.application
import common.encoder.encoder
import django.contrib.postgres.fields
import django.db.models.deletion
import mptt.fields
import uuid
import uuid_utils.compat
from django.db import migrations, models


def insert_default_data(apps, schema_editor):
    # 创建一个根模块（没有父节点）
    QuerySet(application.models.application.ApplicationFolder).create(id='default', name='根目录',
                                                                      user_id='f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', workspace_id='default')


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('knowledge', '0001_initial'),
        ('models_provider', '0001_initial'),
        ('users', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='Application',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('workspace_id', models.CharField(db_index=True, default='default', max_length=64, verbose_name='工作空间id')),
                ('is_publish', models.BooleanField(default=False, verbose_name='是否发布')),
                ('name', models.CharField(max_length=128, verbose_name='应用名称')),
                ('desc', models.CharField(default='', max_length=512, verbose_name='引用描述')),
                ('prologue', models.CharField(default='', max_length=40960, verbose_name='开场白')),
                ('dialogue_number', models.IntegerField(default=0, verbose_name='会话数量')),
                ('knowledge_setting', models.JSONField(default=application.models.application.get_dataset_setting_dict, verbose_name='数据集参数设置')),
                ('model_setting', models.JSONField(default=application.models.application.get_model_setting_dict, verbose_name='模型参数相关设置')),
                ('model_params_setting', models.JSONField(default=dict, verbose_name='模型参数相关设置')),
                ('tts_model_params_setting', models.JSONField(default=dict, verbose_name='模型参数相关设置')),
                ('problem_optimization', models.BooleanField(default=False, verbose_name='问题优化')),
                ('icon', models.CharField(default='./favicon.ico', max_length=256, verbose_name='应用icon')),
                ('work_flow', models.JSONField(default=dict, verbose_name='工作流数据')),
                ('type', models.CharField(choices=[('SIMPLE', '简易'), ('WORK_FLOW', '工作流')], default='SIMPLE', max_length=256, verbose_name='应用类型')),
                ('problem_optimization_prompt', models.CharField(blank=True, default='()里面是用户问题,根据上下文回答揣测用户问题({question}) 要求: 输出一个补全问题,并且放在<data></data>标签中', max_length=102400, null=True, verbose_name='问题优化提示词')),
                ('tts_model_enable', models.BooleanField(default=False, verbose_name='语音合成模型是否启用')),
                ('stt_model_enable', models.BooleanField(default=False, verbose_name='语音识别模型是否启用')),
                ('tts_type', models.CharField(default='BROWSER', max_length=20, verbose_name='语音播放类型')),
                ('tts_autoplay', models.BooleanField(default=False, verbose_name='自动播放')),
                ('stt_autosend', models.BooleanField(default=False, verbose_name='自动发送')),
                ('clean_time', models.IntegerField(default=180, verbose_name='清理时间')),
                ('file_upload_enable', models.BooleanField(default=False, verbose_name='文件上传是否启用')),
                ('file_upload_setting', models.JSONField(default=dict, verbose_name='文件上传相关设置')),
                ('model', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.SET_NULL, to='models_provider.model')),
                ('stt_model', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='stt_model_id', to='models_provider.model')),
                ('tts_model', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tts_model_id', to='models_provider.model')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='users.user')),
            ],
            options={
                'db_table': 'application',
            },
        ),
        migrations.CreateModel(
            name='ApplicationAccessToken',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('application', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='application.application', verbose_name='应用id')),
                ('access_token', models.CharField(max_length=128, unique=True, verbose_name='用户公开访问 认证token')),
                ('is_active', models.BooleanField(default=True, verbose_name='是否开启公开访问')),
                ('access_num', models.IntegerField(default=100, verbose_name='访问次数')),
                ('white_active', models.BooleanField(default=False, verbose_name='是否开启白名单')),
                ('white_list', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=128), default=list, size=None, verbose_name='白名单列表')),
                ('show_source', models.BooleanField(default=False, verbose_name='是否显示知识来源')),
                ('show_exec', models.BooleanField(default=False, verbose_name='是否显示执行详情')),
                ('language', models.CharField(default=None, max_length=10, null=True, verbose_name='语言')),
            ],
            options={
                'db_table': 'application_access_token',
            },
        ),
        migrations.CreateModel(
            name='ApplicationApiKey',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('secret_key', models.CharField(max_length=1024, unique=True, verbose_name='秘钥')),
                ('workspace_id', models.CharField(db_index=True, default='default', max_length=64, verbose_name='工作空间id')),
                ('is_active', models.BooleanField(default=True, verbose_name='是否开启')),
                ('allow_cross_domain', models.BooleanField(default=False, verbose_name='是否允许跨域')),
                ('cross_domain_list', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=128), default=list, size=None, verbose_name='跨域列表')),
                ('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='application.application', verbose_name='应用id')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.user', verbose_name='用户id')),
            ],
            options={
                'db_table': 'application_api_key',
            },
        ),
        migrations.CreateModel(
            name='ApplicationFolder',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('id', models.CharField(editable=False, max_length=64, primary_key=True, serialize=False, verbose_name='主键id')),
                ('name', models.CharField(max_length=64, verbose_name='文件夹名称')),
                ('desc', models.CharField(blank=True, max_length=200, null=True, verbose_name='描述')),
                ('workspace_id', models.CharField(db_index=True, default='default', max_length=64, verbose_name='工作空间id')),
                ('lft', models.PositiveIntegerField(editable=False)),
                ('rght', models.PositiveIntegerField(editable=False)),
                ('tree_id', models.PositiveIntegerField(db_index=True, editable=False)),
                ('level', models.PositiveIntegerField(editable=False)),
                ('parent', mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='children', to='application.applicationfolder')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='users.user', verbose_name='用户id')),
            ],
            options={
                'db_table': 'application_folder',
            },
        ),
        migrations.AddField(
            model_name='application',
            name='folder',
            field=models.ForeignKey(default='default', on_delete=django.db.models.deletion.DO_NOTHING, to='application.applicationfolder', verbose_name='文件夹id'),
        ),
        migrations.CreateModel(
            name='ApplicationKnowledgeMapping',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('application', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='application.application')),
                ('knowledge', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='knowledge.knowledge')),
            ],
            options={
                'db_table': 'application_knowledge_mapping',
            },
        ),
        migrations.CreateModel(
            name='Chat',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid.UUID('01979a90-ea1d-7033-94d5-38f2e12c6627'), editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('abstract', models.CharField(max_length=1024, verbose_name='摘要')),
                ('chat_user_id', models.UUIDField(default=None, null=True, verbose_name='客户端id')),
                ('chat_user_type', models.CharField(choices=[('ANONYMOUS_USER', '匿名用户'), ('CHAT_USER', '对话用户'), ('SYSTEM_API_KEY', '系统API_KEY'), ('APPLICATION_API_KEY', '应用API_KEY')], default='ANONYMOUS_USER', max_length=64, verbose_name='客户端类型')),
                ('is_deleted', models.BooleanField(default=False, verbose_name='逻辑删除')),
                ('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='application.application')),
            ],
            options={
                'db_table': 'application_chat',
            },
        ),
        migrations.CreateModel(
            name='ChatRecord',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('vote_status', models.CharField(choices=[('-1', '未投票'), ('0', '赞同'), ('1', '反对')], default='-1', max_length=10, verbose_name='投票')),
                ('problem_text', models.CharField(max_length=10240, verbose_name='问题')),
                ('answer_text', models.CharField(max_length=40960, verbose_name='答案')),
                ('answer_text_list', django.contrib.postgres.fields.ArrayField(base_field=models.JSONField(), default=list, size=None, verbose_name='改进标注列表')),
                ('message_tokens', models.IntegerField(default=0, verbose_name='请求token数量')),
                ('answer_tokens', models.IntegerField(default=0, verbose_name='响应token数量')),
                ('const', models.IntegerField(default=0, verbose_name='总费用')),
                ('details', models.JSONField(default=dict, encoder=common.encoder.encoder.SystemEncoder, verbose_name='对话详情')),
                ('improve_paragraph_id_list', django.contrib.postgres.fields.ArrayField(base_field=models.UUIDField(blank=True), default=list, size=None, verbose_name='改进标注列表')),
                ('run_time', models.FloatField(default=0, verbose_name='运行时长')),
                ('index', models.IntegerField(verbose_name='对话下标')),
                ('chat', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='application.chat')),
            ],
            options={
                'db_table': 'application_chat_record',
            },
        ),
        migrations.CreateModel(
            name='WorkFlowVersion',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('workspace_id', models.CharField(db_index=True, default='default', max_length=64, verbose_name='工作空间id')),
                ('name', models.CharField(default='', max_length=128, verbose_name='版本名称')),
                ('publish_user_id', models.UUIDField(default=None, null=True, verbose_name='发布者id')),
                ('publish_user_name', models.CharField(default='', max_length=128, verbose_name='发布者名称')),
                ('work_flow', models.JSONField(default=dict, verbose_name='工作流数据')),
                ('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='application.application')),
            ],
            options={
                'db_table': 'application_work_flow_version',
            },
        ),
        migrations.CreateModel(
            name='ApplicationChatUserStats',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('chat_user_id', models.UUIDField(default=uuid_utils.compat.uuid7, verbose_name='对话用户id')),
                ('chat_user_type', models.CharField(choices=[('ANONYMOUS_USER', '匿名用户'), ('CHAT_USER', '对话用户'), ('SYSTEM_API_KEY', '系统API_KEY'), ('APPLICATION_API_KEY', '应用API_KEY')], default='ANONYMOUS_USER', max_length=64, verbose_name='对话用户类型')),
                ('access_num', models.IntegerField(default=0, verbose_name='访问总次数次数')),
                ('intraday_access_num', models.IntegerField(default=0, verbose_name='当日访问次数')),
                ('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='application.application', verbose_name='应用id')),
            ],
            options={
                'db_table': 'application_chat_user_stats',
                'indexes': [models.Index(fields=['application_id', 'chat_user_id'], name='application_applica_1652ba_idx')],
            },
        ),
        migrations.RunPython(insert_default_data)
    ]
