# Generated by Django 4.2.14 on 2024-07-16 09:29

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


class Migration(migrations.Migration):

    replaces = [
        ('sodarcache', '0001_initial'),
        ('sodarcache', '0002_make_user_optional'),
        ('sodarcache', '0003_add_index'),
        ('sodarcache', '0004_update_jsonfield'),
    ]

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('projectroles', '0006_add_remote_projects'),
    ]

    operations = [
        migrations.CreateModel(
            name='JSONCacheItem',
            fields=[
                (
                    'id',
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name='ID',
                    ),
                ),
                (
                    'app_name',
                    models.CharField(help_text='App name', max_length=255),
                ),
                (
                    'name',
                    models.CharField(
                        help_text='Name or title of the item given by the data '
                        'setting app',
                        max_length=255,
                    ),
                ),
                (
                    'date_modified',
                    models.DateTimeField(
                        auto_now_add=True, help_text='DateTime of the update'
                    ),
                ),
                (
                    'sodar_uuid',
                    models.UUIDField(
                        default=uuid.uuid4,
                        help_text='Item SODAR UUID',
                        unique=True,
                    ),
                ),
                (
                    'data',
                    models.JSONField(
                        default=dict, help_text='Cached data as JSON'
                    ),
                ),
                (
                    'project',
                    models.ForeignKey(
                        blank=True,
                        help_text='Project in which the item belongs '
                        '(optional)',
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='cached_items',
                        to='projectroles.project',
                    ),
                ),
                (
                    'user',
                    models.ForeignKey(
                        blank=True,
                        help_text='User who updated the item (optional)',
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                'abstract': False,
                'unique_together': {('project', 'app_name', 'name')},
                'indexes': [
                    models.Index(
                        fields=['project', 'app_name', 'name'],
                        name='sodarcache__project_e54b84_idx',
                    )
                ],
            },
        ),
    ]
