# Generated by Django 2.2.16 on 2022-01-18 06:22

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


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("contenttypes", "0002_remove_content_type_name"),
    ]

    operations = [
        migrations.CreateModel(
            name="Formatter",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        blank=True, max_length=255, null=True, unique=True
                    ),
                ),
                (
                    "content_type",
                    models.CharField(
                        choices=[
                            ["xls", "application/vnd.ms-excel"],
                            ["txt", "text/plain"],
                            ["csv", "text/csv"],
                            ["html", "text/html"],
                            ["yaml", "text/yaml"],
                            ["json", "application/json"],
                        ],
                        max_length=5,
                    ),
                ),
                ("code", models.TextField(blank=True, null=True)),
            ],
        ),
        migrations.CreateModel(
            name="Query",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        blank=True, max_length=255, null=True, unique=True
                    ),
                ),
                ("description", models.TextField(blank=True, null=True)),
                ("code", models.TextField(blank=True, default="qs=conn.all()")),
                (
                    "info",
                    django.contrib.postgres.fields.jsonb.JSONField(
                        blank=True, default=dict
                    ),
                ),
                (
                    "query_args",
                    django.contrib.postgres.fields.jsonb.JSONField(
                        blank=True, default=dict
                    ),
                ),
                ("error", models.CharField(blank=True, max_length=400, null=True)),
                (
                    "owner",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="power_queries",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "target",
                    models.ForeignKey(
                        default="",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.ContentType",
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "Power Queries",
                "ordering": ("name",),
            },
        ),
        migrations.CreateModel(
            name="Report",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        blank=True, max_length=255, null=True, unique=True
                    ),
                ),
                ("refresh", models.BooleanField(default=False)),
                (
                    "query_args",
                    django.contrib.postgres.fields.jsonb.JSONField(
                        blank=True, default=dict
                    ),
                ),
                ("last_run", models.DateTimeField(blank=True, null=True)),
                ("result", models.BinaryField(blank=True, null=True)),
                (
                    "available_to",
                    models.ManyToManyField(
                        blank=True,
                        related_name="_report_available_to_+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "formatter",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="power_query.Formatter",
                    ),
                ),
                (
                    "owner",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "query",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="power_query.Query",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Dataset",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("last_run", models.DateTimeField(blank=True, null=True)),
                ("result", models.BinaryField(blank=True, null=True)),
                (
                    "info",
                    django.contrib.postgres.fields.jsonb.JSONField(
                        blank=True, default=dict
                    ),
                ),
                (
                    "query",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="power_query.Query",
                    ),
                ),
            ],
        ),
    ]
