tools/migrations/teacher_dashboard_migration_1/upgrade.py
def upgrade_cohort_db(cursor, database):
    """
    This upgrades the cohort database table
    :param cursor:
    :param database:
    :return:
    """

    """
    Rename invitation_code to inv_code column
    """
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'invitation_code'")
    result = cursor.fetchall()
    if result:
        cursor.execute("ALTER TABLE cohort "
                       "Change invitation_code inv_code varchar(255) ")
        cursor.execute("ALTER TABLE cohort "
                       "ADD UNIQUE (inv_code) ")
        cursor.execute("SELECT id, name, inv_code FROM cohort")
        rows = cursor.fetchall()
        for row in rows:
            """
            if no class has inv_code, set the name as same as inv_code
            """
            if row[2] is None:
                q = "UPDATE cohort SET inv_code = %s WHERE id = %s" 
                data = (row[1], row[0])
                cursor.execute(q, data)

    """
    Add column max_students
    """
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'max_students'")
    result = cursor.fetchall()
    if not result:
        cursor.execute("ALTER TABLE cohort "
                       "ADD max_students int NOT NULL DEFAULT 30")

    """
    Add class_language_id column and name the foreign key
    """
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'language_id'")
    result = cursor.fetchall()
    if not result:
        cursor.execute("ALTER TABLE cohort "
                       "ADD language_id int(3)")
        cursor.execute("ALTER TABLE cohort "
                       "ADD CONSTRAINT FK_language_id "
                       "FOREIGN KEY (language_id) REFERENCES language (id)")

    This upgrades the cohort database table
    :param cursor:
    :param database:
    :return:
    
This upgrades the cohort database table
This upgrades the cohort database table
def upgrade_cohort_db(cursor, database):
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'invitation_code'")
    result = cursor.fetchall()
    if result:
        cursor.execute("ALTER TABLE cohort "
                       "Change invitation_code inv_code varchar(255) ")
        cursor.execute("ALTER TABLE cohort "
                       "ADD UNIQUE (inv_code) ")
        cursor.execute("SELECT id, name, inv_code FROM cohort")
        rows = cursor.fetchall()
        for row in rows:
            if row[2] is None:
                q = "UPDATE cohort SET inv_code = %s WHERE id = %s" 
                data = (row[1], row[0])
                cursor.execute(q, data)
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'max_students'")
    result = cursor.fetchall()
    if not result:
        cursor.execute("ALTER TABLE cohort "
                       "ADD max_students int NOT NULL DEFAULT 30")
    cursor.execute("SELECT * FROM information_schema.COLUMNS "
                   "WHERE TABLE_SCHEMA = '" + database +
                   "' AND TABLE_NAME = 'cohort' "
                   "AND COLUMN_NAME = 'language_id'")
    result = cursor.fetchall()
    if not result:
        cursor.execute("ALTER TABLE cohort "
                       "ADD language_id int(3)")
        cursor.execute("ALTER TABLE cohort "
                       "ADD CONSTRAINT FK_language_id "
                       "FOREIGN KEY (language_id) REFERENCES language (id)")
def upgrade_cohort_db ( cursor , database ) : """
    Rename invitation_code to inv_code column
    """ cursor . execute ( "SELECT * FROM information_schema.COLUMNS " "WHERE TABLE_SCHEMA = '" + database + "' AND TABLE_NAME = 'cohort' " "AND COLUMN_NAME = 'invitation_code'" ) result = cursor . fetchall ( ) if result : cursor . execute ( "ALTER TABLE cohort " "Change invitation_code inv_code varchar(255) " ) cursor . execute ( "ALTER TABLE cohort " "ADD UNIQUE (inv_code) " ) cursor . execute ( "SELECT id, name, inv_code FROM cohort" ) rows = cursor . fetchall ( ) for row in rows : """
            if no class has inv_code, set the name as same as inv_code
            """ if row [ 2 ] is None : q = "UPDATE cohort SET inv_code = %s WHERE id = %s" data = ( row [ 1 ] , row [ 0 ] ) cursor . execute ( q , data ) """
    Add column max_students
    """ cursor . execute ( "SELECT * FROM information_schema.COLUMNS " "WHERE TABLE_SCHEMA = '" + database + "' AND TABLE_NAME = 'cohort' " "AND COLUMN_NAME = 'max_students'" ) result = cursor . fetchall ( ) if not result : cursor . execute ( "ALTER TABLE cohort " "ADD max_students int NOT NULL DEFAULT 30" ) """
    Add class_language_id column and name the foreign key
    """ cursor . execute ( "SELECT * FROM information_schema.COLUMNS " "WHERE TABLE_SCHEMA = '" + database + "' AND TABLE_NAME = 'cohort' " "AND COLUMN_NAME = 'language_id'" ) result = cursor . fetchall ( ) if not result : cursor . execute ( "ALTER TABLE cohort " "ADD language_id int(3)" ) cursor . execute ( "ALTER TABLE cohort " "ADD CONSTRAINT FK_language_id " "FOREIGN KEY (language_id) REFERENCES language (id)" )
This upgrades the cohort database table
This upgrades the cohort database table
"""
    This upgrades the cohort database table
    :param cursor:
    :param database:
    :return:
    """ """
    Rename invitation_code to inv_code column
    """ """
            if no class has inv_code, set the name as same as inv_code
            """ """
    Add column max_students
    """ """
    Add class_language_id column and name the foreign key
    """
None
cursor
None
database
None