# Generated by Django 5.2.9 on 2026-01-23 09:47

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


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='Trigger',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, db_index=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(db_index=True, max_length=128, verbose_name='触发器名称')),
                ('desc', models.CharField(default='', max_length=512, verbose_name='引用描述')),
                ('trigger_type', models.CharField(choices=[('SCHEDULED', 'Scheduled'), ('EVENT', 'Event')], default='SCHEDULED', max_length=256, verbose_name='触发器类型')),
                ('trigger_setting', models.JSONField(default=dict)),
                ('meta', models.JSONField(default=dict)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.SET_NULL, to='users.user')),
            ],
            options={
                'db_table': 'event_trigger',
            },
        ),
        migrations.CreateModel(
            name='TriggerTask',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, db_index=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('source_type', models.CharField(choices=[('APPLICATION', 'Application'), ('TOOL', 'Tool')], default='APPLICATION', max_length=256, verbose_name='触发器任务类型')),
                ('source_id', models.UUIDField(verbose_name='资源id')),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('parameter', models.JSONField(default=list)),
                ('meta', models.JSONField(default=dict)),
                ('trigger', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='trigger.trigger')),
            ],
            options={
                'db_table': 'event_trigger_task',
                'unique_together': {('trigger', 'source_id', 'source_type')},
            },
        ),
        migrations.CreateModel(
            name='TaskRecord',
            fields=[
                ('create_time', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, db_index=True, verbose_name='修改时间')),
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('source_type', models.CharField(choices=[('APPLICATION', 'Application'), ('TOOL', 'Tool')], default='APPLICATION', max_length=256, verbose_name='触发器任务类型')),
                ('source_id', models.UUIDField(verbose_name='资源id')),
                ('task_record_id', models.UUIDField(verbose_name='任务记录id')),
                ('meta', models.JSONField(default=dict, encoder=common.encoder.encoder.SystemEncoder)),
                ('state', models.CharField(choices=[('PENDING', 'Pending'), ('STARTED', 'Started'), ('SUCCESS', 'Success'), ('FAILURE', 'Failure'), ('REVOKE', 'Revoke'), ('REVOKED', 'Revoked')], default='STARTED', max_length=20, verbose_name='状态')),
                ('run_time', models.FloatField(default=0, verbose_name='运行时长')),
                ('trigger', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='trigger.trigger')),
                ('trigger_task', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='trigger.triggertask')),
            ],
            options={
                'db_table': 'event_trigger_task_record',
            },
        ),
    ]
