# Generated by Django 3.0.7 on 2020-07-03 16:58

from django.db import migrations

INSERT_CVE_LABEL_SQL = """
INSERT INTO cve_label (
    cve_label_id,
    cve_label_code,
    cve_label_name,
    display_order,
    created_by,
    created_at,
    updated_by,
    updated_at)
VALUES( %s,
        %s,
        %s,
        %s,
        "migration",
        NOW(),
        "migration",
        NOW());
"""

ROLLBACK_CVE_LABEL_SQL = """
DELETE
FROM cve_label
WHERE cve_label_id = %s;
"""

INSERT_CVSS3_SQL = """
INSERT INTO cvss3 (
    cvss3_severity_code,
    cvss3_severity_level,
    created_by,
    created_at,
    updated_by,
    updated_at)
VALUES(
    %s,
    %s,
    "migration",
    NOW(),
    "migration",
    NOW());
"""

ROLLBACK_CVSS3_SQL = """
DELETE
FROM cvss3
WHERE cvss3_severity_code = %s;
"""

INSERT_CVSS2_SQL = """
INSERT INTO cvss2 (
    cvss2_severity_code,
    cvss2_severity_level,
    created_by,
    created_at,
    updated_by,
    updated_at)
VALUES(
    %s,
    %s,
    "migration",
    NOW(),
    "migration",
    NOW());
"""

ROLLBACK_CVSS2_SQL = """
DELETE
FROM cvss2
WHERE cvss2_severity_code = %s;
"""

INSERT_CVE_SEVERITY_SQL = """
INSERT INTO cve_severity (
    cve_severity_code,
    cve_severity_name,
    display_order,
    created_by,
    created_at,
    updated_by,
    updated_at)
VALUES(
    %s,
    %s,
    %s,
    "migration",
    NOW(),
    "migration",
    NOW());
"""

ROLLBACK_CVE_SEVERITY_SQL = """
DELETE
FROM cve_severity
WHERE cve_severity_code = %s;
"""


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0002_auto_20200703_1657"),
    ]

    operations = [
        # cve label
        migrations.RunSQL(
            sql=[(INSERT_CVE_LABEL_SQL, [1, "todo", "要対応", 1])],
            reverse_sql=[(ROLLBACK_CVE_LABEL_SQL, [1])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVE_LABEL_SQL, [2, "not_required", "対応不要", 2])],
            reverse_sql=[(ROLLBACK_CVE_LABEL_SQL, [2])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVE_LABEL_SQL, [3, "done", "対応済み", 3])],
            reverse_sql=[(ROLLBACK_CVE_LABEL_SQL, [3])],
        ),
        # cvss3
        migrations.RunSQL(
            sql=[(INSERT_CVSS3_SQL, ["NONE", 1])],
            reverse_sql=[(ROLLBACK_CVSS3_SQL, ["NONE"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVSS3_SQL, ["LOW", 2])],
            reverse_sql=[(ROLLBACK_CVSS3_SQL, ["LOW"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVSS3_SQL, ["MEDIUM", 3])],
            reverse_sql=[(ROLLBACK_CVSS3_SQL, ["MEDIUM"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVSS3_SQL, ["HIGH", 4])],
            reverse_sql=[(ROLLBACK_CVSS3_SQL, ["HIGH"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVSS3_SQL, ["CRITICAL", 5])],
            reverse_sql=[(ROLLBACK_CVSS3_SQL, ["CRITICAL"])],
        ),
        # cvss2
        migrations.RunSQL(
            sql=[(INSERT_CVSS2_SQL, ["LOW", 1])],
            reverse_sql=[(ROLLBACK_CVSS2_SQL, ["LOW"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVSS2_SQL, ["MEDIUM", 2])],
            reverse_sql=[(ROLLBACK_CVSS2_SQL, ["MEDIUM"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVSS2_SQL, ["HIGH", 3])],
            reverse_sql=[(ROLLBACK_CVSS2_SQL, ["HIGH"])],
        ),
        # cve_severity
        migrations.RunSQL(
            sql=[(INSERT_CVE_SEVERITY_SQL, ["CRITICAL", "Critical", 1])],
            reverse_sql=[(ROLLBACK_CVSS2_SQL, ["CRITICAL"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVE_SEVERITY_SQL, ["HIGH", "High", 2])],
            reverse_sql=[(ROLLBACK_CVSS2_SQL, ["CRITICAL"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVE_SEVERITY_SQL, ["MEDIUM", "Medium", 3])],
            reverse_sql=[(ROLLBACK_CVSS2_SQL, ["MEDIUM"])],
        ),
        migrations.RunSQL(
            sql=[(INSERT_CVE_SEVERITY_SQL, ["LOW", "Low", 4])],
            reverse_sql=[(ROLLBACK_CVSS2_SQL, ["LOW"])],
        ),
    ]
