# Generated by Django 2.1.1 on 2018-09-20 09:17

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [("coursera", "0001_initial")]

    operations = [
        migrations.RunSQL(
            sql=[
                """
                CREATE MATERIALIZED VIEW course_memberships_view
                AS
                SELECT
                MD5(MD5(MD5(eitdigital_user_id) || course_id) || course_membership_ts)::varchar(50) as id,
                eitdigital_user_id,
                course_id,
                course_membership_role,
                course_membership_ts
                FROM
                course_memberships
                """,
                """
                CREATE UNIQUE INDEX ON course_memberships_view (id)
                """,
                """
                CREATE INDEX ON course_memberships_view (course_id, course_membership_role)
                """,
            ],
            reverse_sql="""
            DROP MATERIALIZED VIEW IF EXISTS course_memberships_view
            """,
        )
    ]
