tools/migrations/teacher_dashboard_migration_1/downgrade.py
def downgrade_cohort_db(cursor, database):
    """
    This downgrades the cohort database table
    :param cursor:
    :param database:
    :return:
    """

    """
    Drop max_students column
    """
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'max_students'")
    result = cursor.fetchone()
    if result:
        cursor.execute("ALTER TABLE cohort "
                       "DROP COLUMN max_students")

    """
    Remove foreign key and drop column language_id
    """
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'language_id'")
    result = cursor.fetchone()
    if result:
        cursor.execute("ALTER TABLE cohort DROP FOREIGN KEY FK_language_id")
        cursor.execute("ALTER TABLE cohort "
                       "DROP COLUMN language_id")

    """
    Change inv_code back to invitation_code
    """
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'inv_code'")
    result = cursor.fetchone()
    if result:
        cursor.execute("ALTER TABLE cohort "
                       "Change inv_code invitation_code char(50) NOT NULL")

    This downgrades the cohort database table
    :param cursor:
    :param database:
    :return:
    
This downgrades the cohort database table
This downgrades the cohort database table
def downgrade_cohort_db(cursor, database):
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'max_students'")
    result = cursor.fetchone()
    if result:
        cursor.execute("ALTER TABLE cohort "
                       "DROP COLUMN max_students")
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'language_id'")
    result = cursor.fetchone()
    if result:
        cursor.execute("ALTER TABLE cohort DROP FOREIGN KEY FK_language_id")
        cursor.execute("ALTER TABLE cohort "
                       "DROP COLUMN language_id")
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'inv_code'")
    result = cursor.fetchone()
    if result:
        cursor.execute("ALTER TABLE cohort "
                       "Change inv_code invitation_code char(50) NOT NULL")
def downgrade_cohort_db ( cursor , database ) : """
    Drop max_students column
    """ cursor . execute ( "SELECT * FROM information_schema.COLUMNS " "WHERE TABLE_SCHEMA = '" + database + "' AND TABLE_NAME = 'cohort' " "AND COLUMN_NAME = 'max_students'" ) result = cursor . fetchone ( ) if result : cursor . execute ( "ALTER TABLE cohort " "DROP COLUMN max_students" ) """
    Remove foreign key and drop column language_id
    """ cursor . execute ( "SELECT * FROM information_schema.COLUMNS " "WHERE TABLE_SCHEMA = '" + database + "' AND TABLE_NAME = 'cohort' " "AND COLUMN_NAME = 'language_id'" ) result = cursor . fetchone ( ) if result : cursor . execute ( "ALTER TABLE cohort DROP FOREIGN KEY FK_language_id" ) cursor . execute ( "ALTER TABLE cohort " "DROP COLUMN language_id" ) """
    Change inv_code back to invitation_code
    """ cursor . execute ( "SELECT * FROM information_schema.COLUMNS " "WHERE TABLE_SCHEMA = '" + database + "' AND TABLE_NAME = 'cohort' " "AND COLUMN_NAME = 'inv_code'" ) result = cursor . fetchone ( ) if result : cursor . execute ( "ALTER TABLE cohort " "Change inv_code invitation_code char(50) NOT NULL" )
This downgrades the cohort database table
This downgrades the cohort database table
"""
    This downgrades the cohort database table
    :param cursor:
    :param database:
    :return:
    """ """
    Drop max_students column
    """ """
    Remove foreign key and drop column language_id
    """ """
    Change inv_code back to invitation_code
    """
None
cursor
None
database
None