# Generated by Django 3.2.15 on 2022-10-07 08:46

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

import power_query.models


class Migration(migrations.Migration):
    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("power_query", "0003_migration"),
    ]

    operations = [
        migrations.CreateModel(
            name="Parametrizer",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("code", models.SlugField(editable=False, max_length=255, unique=True)),
                ("name", models.CharField(max_length=255, unique=True)),
                (
                    "description",
                    models.TextField(blank=True, max_length=255, null=True),
                ),
                (
                    "value",
                    models.JSONField(
                        default=dict, validators=[power_query.models.validate_queryargs]
                    ),
                ),
                (
                    "system",
                    models.BooleanField(blank=True, default=False, editable=False),
                ),
            ],
            options={
                "verbose_name": "Arguments",
                "verbose_name_plural": "Arguments",
            },
        ),
        migrations.RenameField(
            model_name="dataset",
            old_name="result",
            new_name="value",
        ),
        migrations.RenameField(
            model_name="query",
            old_name="error",
            new_name="sentry_error_id",
        ),
        migrations.RenameField(
            model_name="report",
            old_name="refresh",
            new_name="refresh_daily",
        ),
        migrations.RemoveField(
            model_name="query",
            name="query_args",
        ),
        migrations.RemoveField(
            model_name="report",
            name="available_to",
        ),
        migrations.RemoveField(
            model_name="report",
            name="query_args",
        ),
        migrations.RemoveField(
            model_name="report",
            name="result",
        ),
        migrations.AddField(
            model_name="dataset",
            name="description",
            field=models.CharField(default="", max_length=100),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name="dataset",
            name="extra",
            field=models.BinaryField(
                blank=True,
                help_text="Any other attribute to pass to the formatter",
                null=True,
            ),
        ),
        migrations.AddField(
            model_name="dataset",
            name="hash",
            field=models.CharField(default="", editable=False, max_length=200),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name="query",
            name="active",
            field=models.BooleanField(default=True),
        ),
        migrations.AddField(
            model_name="query",
            name="error_message",
            field=models.CharField(blank=True, max_length=400, null=True),
        ),
        migrations.AddField(
            model_name="query",
            name="refresh_daily",
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name="report",
            name="active",
            field=models.BooleanField(default=True),
        ),
        migrations.AddField(
            model_name="report",
            name="document_title",
            field=models.CharField(blank=True, max_length=255, null=True),
        ),
        migrations.AddField(
            model_name="report",
            name="limit_access_to",
            field=models.ManyToManyField(
                blank=True,
                related_name="_power_query_report_limit_access_to_+",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="dataset",
            name="query",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="datasets",
                to="power_query.query",
            ),
        ),
        migrations.AlterField(
            model_name="query",
            name="name",
            field=models.CharField(max_length=255, unique=True),
        ),
        migrations.AlterField(
            model_name="query",
            name="target",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                to="contenttypes.contenttype",
            ),
        ),
        migrations.AddField(
            model_name="query",
            name="parametrizer",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to="power_query.parametrizer",
            ),
        ),
        migrations.CreateModel(
            name="ReportDocument",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("timestamp", models.DateTimeField(auto_now=True)),
                ("title", models.CharField(max_length=300)),
                ("output", models.BinaryField(blank=True, null=True)),
                ("arguments", models.JSONField(default=dict)),
                (
                    "content_type",
                    models.CharField(
                        choices=[
                            ["csv", "text/csv"],
                            ["html", "text/html"],
                            ["json", "application/json"],
                            ["txt", "text/plain"],
                            ["xls", "application/vnd.ms-excel"],
                            ["xml", "application/xml"],
                            ["yaml", "text/yaml"],
                        ],
                        max_length=5,
                    ),
                ),
                (
                    "dataset",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="power_query.dataset",
                    ),
                ),
                (
                    "limit_access_to",
                    models.ManyToManyField(
                        blank=True,
                        related_name="_power_query_reportdocument_limit_access_to_+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "report",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="documents",
                        to="power_query.report",
                    ),
                ),
            ],
            options={
                "unique_together": {("report", "dataset")},
            },
        ),
    ]
