# Generated by Django 5.1.5 on 2025-03-06 10:23

import core.models
import django.contrib.postgres.indexes
import django.core.validators
import django.db.models.deletion
import django_ltree.fields
import timezone_field.fields
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0012_alter_user_first_name_max_length'),
        ('django_ltree', '0001_create_extension'),
    ]

    operations = [
        migrations.CreateModel(
            name='User',
            fields=[
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')),
                ('sub', models.CharField(blank=True, help_text='Required. 255 characters or fewer. Letters, numbers, and @/./+/-/_/: characters only.', max_length=255, null=True, unique=True, validators=[django.core.validators.RegexValidator(message='Enter a valid sub. This value may contain only letters, numbers, and @/./+/-/_/: characters.', regex='^[\\w.@+-:]+\\Z')], verbose_name='sub')),
                ('full_name', models.CharField(blank=True, max_length=100, null=True, verbose_name='full name')),
                ('short_name', models.CharField(blank=True, max_length=20, null=True, verbose_name='short name')),
                ('email', models.EmailField(blank=True, max_length=254, null=True, verbose_name='identity email address')),
                ('admin_email', models.EmailField(blank=True, max_length=254, null=True, unique=True, verbose_name='admin email address')),
                ('language', models.CharField(choices=settings.LANGUAGES, default='en-us', help_text='The language in which the user wants to see the interface.', max_length=10, verbose_name='language')),
                ('timezone', timezone_field.fields.TimeZoneField(choices_display='WITH_GMT_OFFSET', default='UTC', help_text='The timezone in which the user wants to see times.', use_pytz=False)),
                ('is_device', models.BooleanField(default=False, help_text='Whether the user is a device or a real user.', verbose_name='device')),
                ('is_staff', models.BooleanField(default=False, help_text='Whether the user can log into this admin site.', verbose_name='staff status')),
                ('is_active', models.BooleanField(default=True, help_text='Whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
                ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
                ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
            ],
            options={
                'verbose_name': 'user',
                'verbose_name_plural': 'users',
                'db_table': 'drive_user',
            },
            managers=[
                ('objects', core.models.UserManager()),
            ],
        ),
        migrations.CreateModel(
            name='Item',
            fields=[
                ('path', django_ltree.fields.PathField(unique=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')),
                ('title', models.CharField(max_length=255, verbose_name='title')),
                ('link_reach', models.CharField(choices=[('restricted', 'Restricted'), ('authenticated', 'Authenticated'), ('public', 'Public')], default='restricted', max_length=20)),
                ('link_role', models.CharField(choices=[('reader', 'Reader'), ('editor', 'Editor')], default='reader', max_length=20)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('ancestors_deleted_at', models.DateTimeField(blank=True, null=True)),
                ('filename', models.CharField(blank=True, max_length=255, null=True)),
                ('type', models.CharField(choices=[('folder', 'Folder'), ('file', 'File')], default='folder', max_length=30)),
                ('upload_state', models.CharField(blank=True, choices=[('pending', 'Pending'), ('uploaded', 'Uploaded')], max_length=20, null=True)),
                ('numchild', models.PositiveIntegerField(default=0)),
                ('numchild_folder', models.PositiveIntegerField(default=0)),
                ('creator', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.RESTRICT, related_name='items_created', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Item',
                'verbose_name_plural': 'Items',
                'db_table': 'drive_item',
            },
        ),
        migrations.CreateModel(
            name='Invitation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')),
                ('email', models.EmailField(max_length=254, verbose_name='email address')),
                ('role', models.CharField(choices=[('reader', 'Reader'), ('editor', 'Editor'), ('administrator', 'Administrator'), ('owner', 'Owner')], default='reader', max_length=20)),
                ('issuer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='invitations', to=settings.AUTH_USER_MODEL)),
                ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invitations', to='core.item')),
            ],
            options={
                'verbose_name': 'Item invitation',
                'verbose_name_plural': 'Item invitations',
                'db_table': 'drive_invitation',
            },
        ),
        migrations.CreateModel(
            name='ItemAccess',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')),
                ('team', models.CharField(blank=True, max_length=100)),
                ('role', models.CharField(choices=[('reader', 'Reader'), ('editor', 'Editor'), ('administrator', 'Administrator'), ('owner', 'Owner')], default='reader', max_length=20)),
                ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='accesses', to='core.item')),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Item/user relation',
                'verbose_name_plural': 'Item/user relations',
                'db_table': 'drive_item_access',
                'ordering': ('-created_at',),
            },
        ),
        migrations.CreateModel(
            name='ItemFavorite',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')),
                ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='favorited_by_users', to='core.item')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='favorite_items', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Item favorite',
                'verbose_name_plural': 'Item favorites',
                'db_table': 'drive_item_favorite',
            },
        ),
        migrations.CreateModel(
            name='LinkTrace',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')),
                ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='link_traces', to='core.item')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='link_traces', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Item/user link trace',
                'verbose_name_plural': 'Item/user link traces',
                'db_table': 'drive_link_trace',
            },
        ),
        migrations.AddIndex(
            model_name='item',
            index=django.contrib.postgres.indexes.GistIndex(fields=['path'], name='drive_item_path_a306e2_gist'),
        ),
        migrations.AddConstraint(
            model_name='item',
            constraint=models.CheckConstraint(condition=models.Q(('deleted_at__isnull', True), ('deleted_at', models.F('ancestors_deleted_at')), _connector='OR'), name='check_deleted_at_matches_ancestors_deleted_at_when_set'),
        ),
        migrations.AddConstraint(
            model_name='item',
            constraint=models.CheckConstraint(condition=models.Q(models.Q(models.Q(('filename__isnull', False), ('type', 'file')), models.Q(models.Q(('type', 'file'), _negated=True), ('filename__isnull', True)), _connector='OR')), name='check_filename_set_for_files'),
        ),
        migrations.AddConstraint(
            model_name='invitation',
            constraint=models.UniqueConstraint(fields=('email', 'item'), name='email_and_item_unique_together'),
        ),
        migrations.AddConstraint(
            model_name='itemaccess',
            constraint=models.UniqueConstraint(condition=models.Q(('user__isnull', False)), fields=('user', 'item'), name='unique_item_user', violation_error_message='This user is already in this item.'),
        ),
        migrations.AddConstraint(
            model_name='itemaccess',
            constraint=models.UniqueConstraint(condition=models.Q(('team__gt', '')), fields=('team', 'item'), name='unique_item_team', violation_error_message='This team is already in this item.'),
        ),
        migrations.AddConstraint(
            model_name='itemaccess',
            constraint=models.CheckConstraint(condition=models.Q(models.Q(('team', ''), ('user__isnull', False)), models.Q(('team__gt', ''), ('user__isnull', True)), _connector='OR'), name='check_item_access_either_user_or_team', violation_error_message='Either user or team must be set, not both.'),
        ),
        migrations.AddConstraint(
            model_name='itemfavorite',
            constraint=models.UniqueConstraint(fields=('user', 'item'), name='unique_item_favorite_user', violation_error_message='This item is already targeted by a favorite relation instance for the same user.'),
        ),
        migrations.AddConstraint(
            model_name='linktrace',
            constraint=models.UniqueConstraint(fields=('user', 'item'), name='unique_link_trace_item_user', violation_error_message='A link trace already exists for this item/user.'),
        ),
        migrations.RunSQL(
            "CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;",
            reverse_sql="DROP EXTENSION IF EXISTS fuzzystrmatch;",
        ),
    ]
