<commit_before>import time
import os
from server_config import Server_Config
import subprocess

schema_directory = "schema_updates"

DEBUG = True
DEBUG = False

def get_current_schema_version(cfg):
    dbtype = cfg.values['catalog_database_type']
    result = cfg.exec_sql_cmd( "select option_value \
                                 from R_GRID_CONFIGURATION \
                                 where namespace='database' \
                                 and option_name='schema_version';")
    if DEBUG:
        print(cfg.values)
        print(result)
    if (
        (dbtype == "postgres" and
        "relation \"r_grid_configuration\" does not exist" in result[2].decode('utf-8'))
        or
        (dbtype == "mysql" and
        ("Table '%s.R_GRID_CONFIGURATION' doesn't exist" % cfg.values['Database']) in result[2].decode('utf-8'))
        ):
        # create and populate configuration table
        indexstring = ""
        if (dbtype == "mysql"):
            indexstring = "(767)"
        result = cfg.exec_sql_cmd("create table R_GRID_CONFIGURATION ( \
                                        namespace varchar(2700), \
                                        option_name varchar(2700), \
                                        option_value varchar(2700) ); \
                                        create unique index idx_grid_configuration \
                                        on R_GRID_CONFIGURATION (namespace %s, option_name %s); \
                                        insert into R_GRID_CONFIGURATION VALUES ( \
                                        'database', 'schema_version', '1' );" % indexstring)
        if DEBUG:
            print(result)
        if (result[2].decode('utf-8') != ""):
            print(
                "ERROR: Creating Grid Configuration Table did not complete...")
            print(result[2])
            return
        # use default value
        current_schema_version = 1
    else:
        # postgres as default, oracle not tested yet
        resultline = 2
        if (dbtype == "mysql"):
            resultline = 1
        if (dbtype == "oracle"):
            resultline = 12
        current_schema_version = int(
            result[1].decode('utf-8').split("\n")[resultline].strip())
    if DEBUG:
        print("current_schema_version: %d" % current_schema_version)
    return current_schema_version


def get_target_schema_version():
    # default
    target_schema_version = 2
    # read version value from VERSION file
    if os.path.isfile( "/var/lib/irods/VERSION" ):<commit_msg>[#2133] add missing parameter<commit_after>import time
import os
from server_config import Server_Config
import subprocess

schema_directory = "schema_updates"

DEBUG = True
DEBUG = False

def get_current_schema_version(cfg):
    dbtype = cfg.values['catalog_database_type']
    result = cfg.exec_sql_cmd( "select option_value \
                                 from R_GRID_CONFIGURATION \
                                 where namespace='database' \
                                 and option_name='schema_version';")
    if DEBUG:
        print(cfg.values)
        print(result)
    if (
        (dbtype == "postgres" and
        "relation \"r_grid_configuration\" does not exist" in result[2].decode('utf-8'))
        or
        (dbtype == "mysql" and
        ("Table '%s.R_GRID_CONFIGURATION' doesn't exist" % cfg.values['Database']) in result[2].decode('utf-8'))
        ):
        # create and populate configuration table
        indexstring = ""
        if (dbtype == "mysql"):
            indexstring = "(767)"
        result = cfg.exec_sql_cmd("create table R_GRID_CONFIGURATION ( \
                                        namespace varchar(2700), \
                                        option_name varchar(2700), \
                                        option_value varchar(2700) ); \
                                        create unique index idx_grid_configuration \
                                        on R_GRID_CONFIGURATION (namespace %s, option_name %s); \
                                        insert into R_GRID_CONFIGURATION VALUES ( \
                                        'database', 'schema_version', '1' );" % ( indexstring, indexstring) )
        if DEBUG:
            print(result)
        if (result[2].decode('utf-8') != ""):
            print(
                "ERROR: Creating Grid Configuration Table did not complete...")
            print(result[2])
            return
        # use default value
        current_schema_version = 1
    else:
        # postgres as default, oracle not tested yet
        resultline = 2
        if (dbtype == "mysql"):
            resultline = 1
        if (dbtype == "oracle"):
            resultline = 12
        current_schema_version = int(
            result[1].decode('utf-8').split("\n")[resultline].strip())
    if DEBUG:
        print("current_schema_version: %d" % current_schema_version)
    return current_schema_version


def get_target_schema_version():
    # default
    target_schema_version = 2
    # read version value from VERSION file
    if os.path.isfile( "/var/lib/irods/VERSION" ):
{'fraction_non_alphanumeric': 0.09776046738072054, 'fraction_numerical': 0.012852969814995131, 'mean_word_length': 1.6652828230409964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '930008', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1293, 'n_words': 324}