# Generated by Django 2.2.6 on 2019-12-03 03:50

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Membership',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('creation_time', models.DateTimeField(auto_now_add=True)),
                ('deletion_time', models.DateTimeField(default=None, editable=False, null=True)),
                ('permissions', models.CharField(choices=[('R', 'Read'), ('W', 'Write'), ('A', 'Admin')], default='R', max_length=1)),
                ('creator', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
                'base_manager_name': 'objects',
                'default_manager_name': 'objects',
            },
        ),
        migrations.CreateModel(
            name='Team',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('creation_time', models.DateTimeField(auto_now_add=True)),
                ('deletion_time', models.DateTimeField(default=None, editable=False, null=True)),
                ('name', models.CharField(max_length=200)),
                ('creator', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('members', models.ManyToManyField(related_name='teams', through='simple_django_teams.Membership', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
                'base_manager_name': 'objects',
                'default_manager_name': 'objects',
            },
        ),
        migrations.AddField(
            model_name='membership',
            name='team',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='memberships', to='simple_django_teams.Team'),
        ),
        migrations.AddField(
            model_name='membership',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='memberships', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddConstraint(
            model_name='team',
            constraint=models.UniqueConstraint(condition=models.Q(deletion_time__isnull=True), fields=('name',), name='unique_active_organisation_names'),
        ),
        migrations.AddConstraint(
            model_name='membership',
            constraint=models.UniqueConstraint(condition=models.Q(deletion_time__isnull=True), fields=('user', 'team'), name='one_active_membership_per_user_per_team'),
        ),
    ]
