# Generated by Django 2.1 on 2018-10-23 15:38

import base.fields
import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('entities', '0001_initial'),
        ('documents', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='AcquiredProtocol',
            fields=[
                ('id', models.CharField(default=base.fields.generate_id, editable=False, max_length=22, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('active', models.BooleanField(default=True)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='DataSource',
            fields=[
                ('id', models.CharField(default=base.fields.generate_id, editable=False, max_length=22, primary_key=True, serialize=False)),
                ('hardware_id', models.CharField(db_index=True, max_length=510)),
                ('name', models.CharField(db_index=True, max_length=510)),
                ('canonical_name', models.SlugField(max_length=510)),
                ('active', models.BooleanField(default=True)),
                ('coords', base.fields.ValidatedJSONField(blank=True, null=True, schema={'additionalProperties': False, 'properties': {'srid': {'type': 'number'}, 'x': {'type': 'number'}, 'y': {'type': 'number'}}, 'required': ['srid', 'x', 'y'], 'type': 'object'})),
                ('geometry', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
                ('documents', models.ManyToManyField(related_name='data_sources', to='documents.Document')),
            ],
            options={
                'ordering': ['hardware_id'],
            },
        ),
        migrations.CreateModel(
            name='DataSourceType',
            fields=[
                ('id', models.SlugField(max_length=255, primary_key=True, serialize=False)),
                ('description', models.CharField(blank=True, max_length=255, null=True)),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.CreateModel(
            name='Frequency',
            fields=[
                ('id', models.CharField(default=base.fields.generate_id, editable=False, max_length=22, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('minutes', models.DecimalField(decimal_places=8, max_digits=16)),
                ('tolerance_lower', models.DecimalField(blank=True, decimal_places=8, max_digits=16, null=True)),
                ('tolerance_upper', models.DecimalField(blank=True, decimal_places=8, max_digits=16, null=True)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='MeasurementProtocol',
            fields=[
                ('id', models.SlugField(max_length=255, primary_key=True, serialize=False)),
                ('description', models.CharField(blank=True, max_length=255, null=True)),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.CreateModel(
            name='MeasurementUnit',
            fields=[
                ('id', models.SlugField(max_length=255, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=255)),
                ('abbreviation', models.CharField(blank=True, max_length=255, null=True)),
                ('si', models.BooleanField()),
                ('si_conversion', models.DecimalField(decimal_places=8, max_digits=16)),
                ('si_unit', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='derived_units', to='targets.MeasurementUnit')),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.CreateModel(
            name='Target',
            fields=[
                ('id', models.CharField(default=base.fields.generate_id, editable=False, max_length=22, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=510)),
                ('canonical_name', models.SlugField(max_length=510, unique=True)),
                ('can_emit_alerts', models.BooleanField(default=False)),
                ('meta', base.fields.ValidatedJSONField(default=dict, schema={'additionalProperties': False, 'patternProperties': {'^.*$': {'additionalProperties': False, 'properties': {'name': {'type': 'string'}, 'order': {'type': 'number'}, 'value': {'type': ['number', 'string', 'boolean', 'null']}}, 'required': ['value'], 'type': 'object'}}, 'type': 'object'})),
                ('coords', base.fields.ValidatedJSONField(blank=True, null=True, schema={'additionalProperties': False, 'properties': {'srid': {'type': 'number'}, 'x': {'type': 'number'}, 'y': {'type': 'number'}}, 'required': ['srid', 'x', 'y'], 'type': 'object'})),
                ('geometry', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
                ('perimeter', django.contrib.gis.db.models.fields.MultiPolygonField(blank=True, null=True, srid=4326)),
                ('documents', models.ManyToManyField(related_name='targets', to='documents.Document')),
                ('entity', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='targets', to='entities.Entity')),
            ],
            options={
                'ordering': ['canonical_name'],
            },
        ),
        migrations.CreateModel(
            name='TargetSection',
            fields=[
                ('id', models.CharField(default=base.fields.generate_id, editable=False, max_length=22, primary_key=True, serialize=False)),
                ('name', models.CharField(db_index=True, max_length=510)),
                ('canonical_name', models.SlugField(max_length=510)),
                ('meta', base.fields.ValidatedJSONField(schema={'additionalProperties': False, 'patternProperties': {'^.*$': {'additionalProperties': False, 'properties': {'name': {'type': 'string'}, 'order': {'type': 'number'}, 'value': {'type': ['number', 'string', 'boolean', 'null']}}, 'required': ['value'], 'type': 'object'}}, 'type': 'object'})),
                ('coords', base.fields.ValidatedJSONField(schema={'additionalProperties': False, 'properties': {'srid': {'type': 'number'}, 'x': {'type': 'number'}, 'y': {'type': 'number'}}, 'required': ['srid', 'x', 'y'], 'type': 'object'})),
                ('geometry', django.contrib.gis.db.models.fields.PointField(srid=4326)),
                ('perimeter', django.contrib.gis.db.models.fields.MultiPolygonField(blank=True, null=True, srid=4326)),
                ('documents', models.ManyToManyField(related_name='sections', to='documents.Document')),
                ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='targets.TargetSection')),
                ('target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sections', to='targets.Target')),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='TargetSectionType',
            fields=[
                ('id', models.SlugField(max_length=255, primary_key=True, serialize=False)),
                ('description', models.CharField(blank=True, max_length=255, null=True)),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.CreateModel(
            name='TargetState',
            fields=[
                ('id', models.SlugField(max_length=255, primary_key=True, serialize=False)),
                ('description', models.CharField(blank=True, max_length=255, null=True)),
                ('default', models.BooleanField(default=False)),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.CreateModel(
            name='TargetType',
            fields=[
                ('id', models.SlugField(max_length=255, primary_key=True, serialize=False)),
                ('description', models.CharField(blank=True, max_length=255, null=True)),
                ('default', models.BooleanField(default=False)),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.CreateModel(
            name='Threshold',
            fields=[
                ('id', models.CharField(default=base.fields.generate_id, editable=False, max_length=22, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('active', models.BooleanField(default=True)),
                ('lower', models.DecimalField(blank=True, decimal_places=8, max_digits=16, null=True)),
                ('upper', models.DecimalField(blank=True, decimal_places=8, max_digits=16, null=True)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Timeseries',
            fields=[
                ('id', models.CharField(default=base.fields.generate_id, editable=False, max_length=22, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=255)),
                ('canonical_name', models.CharField(max_length=255, unique=True)),
                ('description', models.TextField(blank=True, null=True)),
                ('highlight', models.BooleanField(db_index=True, default=False)),
                ('type', models.CharField(choices=[('manual', 'Manually input series'), ('raw', 'Raw series'), ('derived', 'Derived series')], db_index=True, default='raw', max_length=127)),
                ('labels', base.fields.ValidatedJSONField(blank=True, default=list, null=True, schema={'items': {'additionalProperties': False, 'properties': {'key': {'type': 'string'}, 'value': {'type': 'string'}}, 'required': ['key', 'value'], 'type': 'object'}, 'type': 'array'})),
                ('range_lower', models.DecimalField(blank=True, decimal_places=8, max_digits=16, null=True)),
                ('range_upper', models.DecimalField(blank=True, decimal_places=8, max_digits=16, null=True)),
                ('data_source', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='timeseries', to='targets.DataSource')),
                ('inputs', models.ManyToManyField(blank=True, related_name='derivations', to='targets.Timeseries')),
                ('section', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='timeseries', to='targets.TargetSection')),
                ('target', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='timeseries', to='targets.Target')),
                ('unit', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='timeseries', to='targets.MeasurementUnit')),
            ],
            options={
                'verbose_name_plural': 'timeseries',
                'ordering': ['canonical_name'],
            },
        ),
        migrations.CreateModel(
            name='Zone',
            fields=[
                ('id', models.CharField(max_length=255, primary_key=True, serialize=False)),
                ('natural_key', models.CharField(max_length=255, unique=True)),
                ('name', models.CharField(max_length=255)),
                ('canonical_name', models.SlugField(max_length=255)),
                ('target_count', models.IntegerField(default=0)),
                ('coords', base.fields.ValidatedJSONField(schema={'additionalProperties': False, 'properties': {'srid': {'type': 'number'}, 'x': {'type': 'number'}, 'y': {'type': 'number'}}, 'required': ['srid', 'x', 'y'], 'type': 'object'})),
                ('geometry', django.contrib.gis.db.models.fields.PointField(srid=4326)),
                ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='targets.Zone')),
            ],
            options={
                'ordering': ['natural_key'],
            },
        ),
        migrations.CreateModel(
            name='ZoneType',
            fields=[
                ('id', models.SlugField(max_length=255, primary_key=True, serialize=False)),
                ('description', models.CharField(blank=True, max_length=255, null=True)),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.AddField(
            model_name='zone',
            name='type',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='targets.ZoneType'),
        ),
        migrations.AddField(
            model_name='threshold',
            name='timeseries',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='thresholds', to='targets.Timeseries'),
        ),
        migrations.AddField(
            model_name='targetsection',
            name='type',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='targets.TargetSectionType'),
        ),
        migrations.AddField(
            model_name='target',
            name='state',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='targets.TargetState'),
        ),
        migrations.AddField(
            model_name='target',
            name='type',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='targets.TargetType'),
        ),
        migrations.AddField(
            model_name='target',
            name='zone',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='targets', to='targets.Zone'),
        ),
        migrations.AddField(
            model_name='frequency',
            name='protocol',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='frequencies', to='targets.MeasurementProtocol'),
        ),
        migrations.AddField(
            model_name='frequency',
            name='timeseries',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='frequencies', to='targets.Timeseries'),
        ),
        migrations.AddField(
            model_name='datasource',
            name='section',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='data_sources', to='targets.TargetSection'),
        ),
        migrations.AddField(
            model_name='datasource',
            name='target',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='data_sources', to='targets.Target'),
        ),
        migrations.AddField(
            model_name='datasource',
            name='type',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='targets.DataSourceType'),
        ),
        migrations.AddField(
            model_name='acquiredprotocol',
            name='protocol',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='acquisitions', to='targets.MeasurementProtocol'),
        ),
        migrations.AddField(
            model_name='acquiredprotocol',
            name='timeseries',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='acquired_protocols', to='targets.Timeseries'),
        ),
    ]
