parameters: ()
docstring: main function to run mysql migration
docstring_summary: main function to run mysql migration
docstring_tokens: main function to run mysql migration
function: def main():
      """ main function to run mysql migration """
      parser = argparse.ArgumentParser(description='cBioPortal DB migration script')
      parser.add_argument('-y', '--suppress_confirmation', default=False, action='store_true')
      parser.add_argument('-p', '--properties-file', type=str, required=True,
                          help='Path to portal.properties file')
      parser.add_argument('-s', '--sql', type=str, required=True,
                          help='Path to official migration.sql script.')
      parser.add_argument('-f', '--force', default=False, action='store_true', help='Force to run database migration')
      parser.add_argument('--no-transaction', default=False, action='store_true', help="""
          Do not run migration in a single transaction. Only use this when you known what you are doing!!!
      """)
      parser = parser.parse_args()
  
      properties_filename = parser.properties_file
      sql_filename = parser.sql
  
      # check existence of properties file and sql file
      if not os.path.exists(properties_filename):
          print('properties file %s cannot be found' % (properties_filename), file=ERROR_FILE)
          usage()
          sys.exit(2)
      if not os.path.exists(sql_filename):
          print('sql file %s cannot be found' % (sql_filename), file=ERROR_FILE)
          usage()
          sys.exit(2)
  
      # parse properties file
      portal_properties = get_portal_properties(properties_filename)
      if portal_properties is None:
          print('failure reading properties file (%s)' % (properties_filename), file=ERROR_FILE)
          sys.exit(1)
  
      # warn user
      if not parser.suppress_confirmation:
          warn_user()
  
      # set up - get db cursor
      connection, cursor = get_db_cursor(portal_properties)
      if cursor is None:
          print('failure connecting to sql database', file=ERROR_FILE)
          sys.exit(1)
  
      # execute - get the database version and run the migration
      with contextlib.closing(connection):
          db_version = get_db_version(cursor)
          if is_version_larger(MULTI_REFERENCE_GENOME_SUPPORT_MIGRATION_STEP, db_version):
              #retrieve reference genomes from database
              check_reference_genome(portal_properties, cursor, parser.force)
          if not is_version_larger(SAMPLE_FK_MIGRATION_STEP, db_version):
              check_and_remove_type_of_cancer_id_foreign_key(cursor)
          run_migration(db_version, sql_filename, connection, cursor, parser.no_transaction)
          # TODO: remove this after we update mysql version
          # check invalid foreign key only when current db version larger or qeuals to GENERIC_ASSAY_MIGRATION_STEP
          if not is_version_larger(GENERIC_ASSAY_MIGRATION_STEP, db_version):
              check_and_remove_invalid_foreign_keys(cursor)
      print('Finished.', file=OUTPUT_FILE)
function_tokens: def main ( ) : parser = argparse . ArgumentParser ( description = 'cBioPortal DB migration script' ) parser . add_argument ( '-y' , '--suppress_confirmation' , default = False , action = 'store_true' ) parser . add_argument ( '-p' , '--properties-file' , type = str , required = True , help = 'Path to portal.properties file' ) parser . add_argument ( '-s' , '--sql' , type = str , required = True , help = 'Path to official migration.sql script.' ) parser . add_argument ( '-f' , '--force' , default = False , action = 'store_true' , help = 'Force to run database migration' ) parser . add_argument ( '--no-transaction' , default = False , action = 'store_true' , help = """
          Do not run migration in a single transaction. Only use this when you known what you are doing!!!
      """ ) parser = parser . parse_args ( ) properties_filename = parser . properties_file sql_filename = parser . sql # check existence of properties file and sql file if not os . path . exists ( properties_filename ) : print ( 'properties file %s cannot be found' % ( properties_filename ) , file = ERROR_FILE ) usage ( ) sys . exit ( 2 ) if not os . path . exists ( sql_filename ) : print ( 'sql file %s cannot be found' % ( sql_filename ) , file = ERROR_FILE ) usage ( ) sys . exit ( 2 ) # parse properties file portal_properties = get_portal_properties ( properties_filename ) if portal_properties is None : print ( 'failure reading properties file (%s)' % ( properties_filename ) , file = ERROR_FILE ) sys . exit ( 1 ) # warn user if not parser . suppress_confirmation : warn_user ( ) # set up - get db cursor connection , cursor = get_db_cursor ( portal_properties ) if cursor is None : print ( 'failure connecting to sql database' , file = ERROR_FILE ) sys . exit ( 1 ) # execute - get the database version and run the migration with contextlib . closing ( connection ) : db_version = get_db_version ( cursor ) if is_version_larger ( MULTI_REFERENCE_GENOME_SUPPORT_MIGRATION_STEP , db_version ) : #retrieve reference genomes from database check_reference_genome ( portal_properties , cursor , parser . force ) if not is_version_larger ( SAMPLE_FK_MIGRATION_STEP , db_version ) : check_and_remove_type_of_cancer_id_foreign_key ( cursor ) run_migration ( db_version , sql_filename , connection , cursor , parser . no_transaction ) # TODO: remove this after we update mysql version # check invalid foreign key only when current db version larger or qeuals to GENERIC_ASSAY_MIGRATION_STEP if not is_version_larger ( GENERIC_ASSAY_MIGRATION_STEP , db_version ) : check_and_remove_invalid_foreign_keys ( cursor ) print ( 'Finished.' , file = OUTPUT_FILE )