# Generated by Django 4.2.28 on 2026-06-10 12:00

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        ('db', '0061_external_user_tokens'),
    ]

    operations = [
        migrations.CreateModel(
            name='CollectionTokenGrant',
            fields=[
                (
                    'id',
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name='ID',
                    ),
                ),
                (
                    'role',
                    models.CharField(
                        choices=[('owner', 'Owner'), ('viewer', 'Viewer')]
                    ),
                ),
                (
                    'created_at',
                    models.DateTimeField(default=django.utils.timezone.now),
                ),
                (
                    'collection',
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='token_grants',
                        to='db.collection',
                    ),
                ),
                (
                    'created_by',
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name='user_created_%(class)s',
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    'token',
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='collection_grants',
                        to='db.token',
                    ),
                ),
            ],
        ),
        migrations.AddConstraint(
            model_name='collectiontokengrant',
            constraint=models.UniqueConstraint(
                fields=('token', 'collection', 'role'),
                name='db_collectiontokengrant_unique',
            ),
        ),
    ]
