# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-01-06 05:36
from __future__ import unicode_literals

from django.conf import settings
import django.contrib.postgres.fields
import django.contrib.postgres.fields.jsonb
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import versionfield


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='Data',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.SlugField(max_length=100)),
                ('version', versionfield.VersionField(default=0)),
                ('name', models.CharField(max_length=100)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('started', models.DateTimeField(blank=True, null=True)),
                ('finished', models.DateTimeField(blank=True, null=True)),
                ('checksum', models.CharField(blank=True, max_length=40, null=True, validators=[django.core.validators.RegexValidator(code='invalid_checksum', message='Checksum is exactly 40 alphanumerics', regex='^[0-9a-f]{40}$')])),
                ('status', models.CharField(choices=[('UP', 'Uploading'), ('RE', 'Resolving'), ('WT', 'Waiting'), ('PR', 'Processing'), ('OK', 'Done'), ('ER', 'Error'), ('DR', 'Dirty')], default='RE', max_length=2)),
                ('process_pid', models.PositiveIntegerField(blank=True, null=True)),
                ('process_progress', models.PositiveSmallIntegerField(default=0)),
                ('process_rc', models.PositiveSmallIntegerField(blank=True, null=True)),
                ('process_info', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=255), default=[], size=None)),
                ('process_warning', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=255), default=[], size=None)),
                ('process_error', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=255), default=[], size=None)),
                ('input', django.contrib.postgres.fields.jsonb.JSONField(default={})),
                ('output', django.contrib.postgres.fields.jsonb.JSONField(default={})),
                ('descriptor', django.contrib.postgres.fields.jsonb.JSONField(default={})),
                ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'default_permissions': (),
                'abstract': False,
                'permissions': (('view_data', 'Can view data'), ('edit_data', 'Can edit data'), ('share_data', 'Can share data'), ('download_data', 'Can download files from data')),
            },
        ),
        migrations.CreateModel(
            name='DescriptorSchema',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.SlugField(max_length=100)),
                ('version', versionfield.VersionField(default=0)),
                ('name', models.CharField(max_length=100)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('description', models.TextField(blank=True)),
                ('schema', django.contrib.postgres.fields.jsonb.JSONField(default={})),
                ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'default_permissions': (),
                'abstract': False,
                'permissions': (('view_descriptorschema', 'Can view descriptor schema'), ('edit_descriptorschema', 'Can edit descriptor schema'), ('share_descriptorschema', 'Can share descriptor schema')),
            },
        ),
        migrations.CreateModel(
            name='Process',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.SlugField(max_length=100)),
                ('version', versionfield.VersionField(default=0)),
                ('name', models.CharField(max_length=100)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('type', models.CharField(max_length=100, validators=[django.core.validators.RegexValidator(code='invalid_type', message='Type may be alphanumerics separated by colon', regex='^data:[a-z0-9:]+:$')])),
                ('category', models.CharField(default='other', max_length=200, validators=[django.core.validators.RegexValidator(code='invalid_category', message='Category may be alphanumerics separated by colon', regex='^([a-z0-9]+[:\\-])*[a-z0-9]+:$')])),
                ('persistence', models.CharField(choices=[('RAW', 'Raw'), ('CAC', 'Cached'), ('TMP', 'Temp')], default='RAW', max_length=3)),
                ('priority', models.CharField(choices=[('NO', 'Normal'), ('HI', 'High')], default='NO', max_length=2)),
                ('description', models.TextField(default='')),
                ('input_schema', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=[])),
                ('output_schema', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=[])),
                ('run', django.contrib.postgres.fields.jsonb.JSONField(default={})),
                ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'default_permissions': (),
                'abstract': False,
                'permissions': (('view_process', 'Can view process'), ('share_process', 'Can share process')),
            },
        ),
        migrations.CreateModel(
            name='Project',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.SlugField(max_length=100)),
                ('version', versionfield.VersionField(default=0)),
                ('name', models.CharField(max_length=100)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('description', models.TextField(blank=True)),
                ('settings', django.contrib.postgres.fields.jsonb.JSONField(default={})),
                ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('data', models.ManyToManyField(to='flow.Data')),
                ('public_processes', models.ManyToManyField(to='flow.Process')),
            ],
            options={
                'default_permissions': (),
                'abstract': False,
                'permissions': (('view_project', 'Can view project'), ('edit_project', 'Can edit project'), ('share_project', 'Can share project'), ('download_project', 'Can download files from project'), ('add_project', 'Can add data objects to project')),
            },
        ),
        migrations.CreateModel(
            name='Storage',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.SlugField(max_length=100)),
                ('version', versionfield.VersionField(default=0)),
                ('name', models.CharField(max_length=100)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('json', django.contrib.postgres.fields.jsonb.JSONField()),
                ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('data', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='flow.Data')),
            ],
            options={
                'abstract': False,
                'default_permissions': (),
            },
        ),
        migrations.CreateModel(
            name='Trigger',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.SlugField(max_length=100)),
                ('version', versionfield.VersionField(default=0)),
                ('name', models.CharField(max_length=100)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('type', models.CharField(max_length=100, validators=[django.core.validators.RegexValidator(code='invalid_type', message='Type may be alphanumerics separated by colon', regex='^data:[a-z0-9:]+:$')])),
                ('trigger', models.CharField(max_length=500)),
                ('trigger_input', models.CharField(max_length=100)),
                ('input', django.contrib.postgres.fields.jsonb.JSONField(default={})),
                ('autorun', models.BooleanField(default=False)),
                ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('process', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='flow.Process')),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='flow.Project')),
            ],
            options={
                'default_permissions': (),
                'abstract': False,
                'permissions': (('view_trigger', 'Can view trigger'), ('edit_trigger', 'Can edit trigger'), ('share_trigger', 'Can share trigger')),
            },
        ),
        migrations.AddField(
            model_name='data',
            name='descriptor_schema',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='flow.DescriptorSchema'),
        ),
        migrations.AddField(
            model_name='data',
            name='process',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='flow.Process'),
        ),
        migrations.AlterUniqueTogether(
            name='trigger',
            unique_together=set([('slug', 'version')]),
        ),
        migrations.AlterUniqueTogether(
            name='storage',
            unique_together=set([('slug', 'version')]),
        ),
        migrations.AlterUniqueTogether(
            name='project',
            unique_together=set([('slug', 'version')]),
        ),
        migrations.AlterUniqueTogether(
            name='process',
            unique_together=set([('slug', 'version')]),
        ),
        migrations.AlterUniqueTogether(
            name='descriptorschema',
            unique_together=set([('slug', 'version')]),
        ),
        migrations.AlterUniqueTogether(
            name='data',
            unique_together=set([('slug', 'version')]),
        ),
    ]
