parameters: (db_version, sql_filename, connection, cursor, no_transaction)
docstring: Goes through the sql and runs lines based on the version numbers. SQL version should be stated as follows:
  
          ##version: 1.0.0
          INSERT INTO ...
  
          ##version: 1.1.0
          CREATE TABLE ...
docstring_summary: Goes through the sql and runs lines based on the version numbers. SQL version should be stated as follows:
docstring_tokens: Goes through the sql and runs lines based on the version numbers . SQL version should be stated as follows :
function: def run_migration(db_version, sql_filename, connection, cursor, no_transaction):
      """
          Goes through the sql and runs lines based on the version numbers. SQL version should be stated as follows:
  
          ##version: 1.0.0
          INSERT INTO ...
  
          ##version: 1.1.0
          CREATE TABLE ...
      """
      sql_file = open(sql_filename, 'r')
      sql_version = (0, 0, 0)
      run_line = False
      statements = OrderedDict()
      statement = ''
      for line in sql_file:
          if line.startswith('##'):
              sql_version = tuple(map(int, line.split(':')[1].strip().split('.')))
              run_line = is_version_larger(sql_version, db_version)
              continue
          # skip blank lines
          if len(line.strip()) < 1:
              continue
          # skip comments
          if line.startswith('#'):
              continue
          # skip sql comments
          if line.startswith('--') and len(line) > 2 and line[2].isspace():
              continue
          # only execute sql line if the last version seen in the file is greater than the db_version
          if run_line:
              line = line.strip()
              simplified_line = strip_trailing_comment_from_line(line)
              statement = statement + ' ' + simplified_line
              if simplified_line.endswith(';'):
                  if sql_version not in statements:
                      statements[sql_version] = [statement]
                  else:
                      statements[sql_version].append(statement)
                  statement = ''
      if len(statements) > 0:
          run_statements(statements, connection, cursor, no_transaction)
      else:
          print('Everything up to date, nothing to migrate.', file=OUTPUT_FILE)
function_tokens: def run_migration ( db_version , sql_filename , connection , cursor , no_transaction ) : sql_file = open ( sql_filename , 'r' ) sql_version = ( 0 , 0 , 0 ) run_line = False statements = OrderedDict ( ) statement = '' for line in sql_file : if line . startswith ( '##' ) : sql_version = tuple ( map ( int , line . split ( ':' ) [ 1 ] . strip ( ) . split ( '.' ) ) ) run_line = is_version_larger ( sql_version , db_version ) continue # skip blank lines if len ( line . strip ( ) ) < 1 : continue # skip comments if line . startswith ( '#' ) : continue # skip sql comments if line . startswith ( '--' ) and len ( line ) > 2 and line [ 2 ] . isspace ( ) : continue # only execute sql line if the last version seen in the file is greater than the db_version if run_line : line = line . strip ( ) simplified_line = strip_trailing_comment_from_line ( line ) statement = statement + ' ' + simplified_line if simplified_line . endswith ( ';' ) : if sql_version not in statements : statements [ sql_version ] = [ statement ] else : statements [ sql_version ] . append ( statement ) statement = '' if len ( statements ) > 0 : run_statements ( statements , connection , cursor , no_transaction ) else : print ( 'Everything up to date, nothing to migrate.' , file = OUTPUT_FILE )