# Generated by Django 3.0.3 on 2020-02-22 01:46

import check_constraint.models
import demo.models.function.non_null_count
from django.db import migrations, models, connection


class Migration(migrations.Migration):

    dependencies = [
        ("demo", "0002_auto_20200218_0733"),
    ]

    operations = [
        migrations.AddConstraint(
            model_name="book",
            constraint=check_constraint.models.AnnotatedCheckConstraint(
                annotations={
                    "not_null_count": demo.models.function.non_null_count.NotNullCount(
                        "amount_off", "percentage"
                    )
                },
                check=models.Q(not_null_count=1),
                name="demo_book_optional_field_provided",
            ),
        ),
    ]

    def apply(self, project_state, schema_editor, collect_sql=False):
        if schema_editor.connection.alias == "mysql":
            for operation in self.operations:
                # Save the state before the operation has run
                operation.state_forwards(self.app_label, project_state)
            return project_state

        return super(Migration, self).apply(
            project_state, schema_editor, collect_sql=collect_sql
        )

    def unapply(self, project_state, schema_editor, collect_sql=False):
        if schema_editor.connection.alias == "mysql":
            return project_state

        return super(Migration, self).unapply(
            project_state, schema_editor, collect_sql=collect_sql
        )
