text: # (c) 2020 Michał Górny
  # 2-clause BSD license
  
  # Generated by Django 3.0.6 on 2020-05-10 07:41
  
  from django.db import migrations, models
  from django.db.backends.base.schema import BaseDatabaseSchemaEditor
  import django.db.models.deletion
  
  from goose.models import DataClass
  
  
  def add_data_classes(apps: migrations.state.StateApps,
                       schema_editor: BaseDatabaseSchemaEditor
                       ) -> None:
      DataClass(
          name='id',
          description='Unique system identifier',
          data_type=DataClass.DataClassType.STRING,
          public=False).save()
      DataClass(
          name='profile',
          description='Profile used',
          data_type=DataClass.DataClassType.STRING,
          public=True).save()
      DataClass(
          name='world',
          description='Packages found in @world',
          data_type=DataClass.DataClassType.STRING_ARRAY,
          public=True).save()
  
  
  class Migration(migrations.Migration):
  
      initial = True
  
      operations = [
          migrations.CreateModel(
              name='DataClass',
              fields=[
                  ('id', models.AutoField(
                      auto_created=True,
                      primary_key=True,
                      serialize=False,
                      verbose_name='ID')),
                  ('name', models.CharField(
                      help_text='Name used in submission JSON',
                      max_length=32,
                      unique=True)),
                  ('description', models.CharField(
                      help_text='Human-readable description of the data',
                      max_length=128)),
                  ('data_type', models.IntegerField(
                      choices=[(1, 'String'), (2, 'String Array')],
                      help_text='Type of data reported')),
                  ('public', models.BooleanField(
                      help_text='Whether the data is a publicly '
                                'reported statistic')),
              ],
          ),
          migrations.CreateModel(
              name='Value',
              fields=[
                  ('id', models.AutoField(
                      auto_created=True,
                      primary_key=True,
                      serialize=False,
                      verbose_name='ID')),
                  ('value', models.CharField(
                      help_text='The value',
                      max_length=256)),
                  ('data_class', models.ForeignKey(
                      help_text='Class of the data represented '
                                'by the value',
                      on_delete=django.db.models.deletion.CASCADE,
                      to='goose.DataClass')),
              ],
          ),
          migrations.CreateModel(
              name='Count',
              fields=[
                  ('id', models.AutoField(
                      auto_created=True,
                      primary_key=True,
                      serialize=False,
                      verbose_name='ID')),
                  ('count', models.IntegerField(
                      default=1,
                      help_text='Number of occurrences of the value')),
                  ('inclusion_time', models.DateTimeField(
                      default=None,
                      help_text='Timestamp of including the data '
                                'in overall statistic',
                      null=True)),
                  ('value', models.ForeignKey(
                      help_text='The value',
                      on_delete=django.db.models.deletion.CASCADE,
                      to='goose.Value')),
              ],
          ),
          migrations.AddConstraint(
              model_name='value',
              constraint=models.UniqueConstraint(
                  fields=('data_class', 'value'), name='unique_value'),
          ),
          migrations.AddConstraint(
              model_name='count',
              constraint=models.UniqueConstraint(
                  fields=('value', 'inclusion_time'),
                  name='unique_count'),
          ),
          migrations.RunPython(add_data_classes),
      ]
  