<commit_before>__author__ = "<NAME>"

DB_VERSION = 0

import logging

from Pegasus.db.admin.admin_loader import *
from Pegasus.db.admin.versions.base_version import *
from Pegasus.db.schema import *
from sqlalchemy.exc import *

log = logging.getLogger(__name__)

class Version(BaseVersion):
    
    def __init__(self, connection):
        super(Version, self).__init__(connection)

    def update(self, force=False):
        log.debug("Updating to version %s" % DB_VERSION)
        query = "ALTER TABLE invocation ADD COLUMN remote_cpu_time NUMERIC(10,3) NULL"
        if self.db.connection().dialect.name != 'sqlite':
            query += ' AFTER remote_duration'
        self.execute(query)
        self.execute("ALTER TABLE job_instance ADD COLUMN multiplier_factor INT NOT NULL DEFAULT 1")
        self.execute("ALTER TABLE job_instance ADD COLUMN exitcode INT NULL")
        
        success = ['JOB_SUCCESS', 'POST_SCRIPT_SUCCESS']
        failure = ['PRE_SCRIPT_FAILED', 'SUBMIT_FAILED', 'JOB_FAILURE', 'POST_SCRIPT_FAILED']

        q = self.db.query(JobInstance.job_instance_id).order_by(JobInstance.job_instance_id)
        for r in q.all():
            qq = self.db.query(Jobstate.state)
            qq = qq.filter(Jobstate.job_instance_id == r.job_instance_id)
            qq = qq.order_by(Jobstate.jobstate_submit_seq.desc()).limit(1)
            for rr in qq.all():
                if rr.state in success:
                    self.db.execute('UPDATE job_instance SET exitcode = 0 WHERE job_instance_id = %s' \
                        % r.job_instance_id )
                elif rr.state in failure:
                    self.db.execute('UPDATE job_instance SET exitcode = 256 WHERE job_instance_id = %s' \
                    % r.job_instance_id)
                else:
                    pass
        
        self.db.commit()
         
    def downgrade(self, force=False):
        """ Downgrade to this version will not be allowed."""
        pass
    
    def execute(self, query):
        try:
            self.db.execute(query)
        except (OperationalError, ProgrammingError):
            pass
        except Exception, e:
            self.db.rollback()
            raise DBAdminError(e)<commit_msg>Added condition to protect MySQL databases.<commit_after>__author__ = "<NAME>"

DB_VERSION = 0

import logging

from Pegasus.db.admin.admin_loader import *
from Pegasus.db.admin.versions.base_version import *
from Pegasus.db.schema import *
from sqlalchemy.exc import *

log = logging.getLogger(__name__)

class Version(BaseVersion):
    
    def __init__(self, connection):
        super(Version, self).__init__(connection)

    def update(self, force=False):
        log.debug("Updating to version %s" % DB_VERSION)
        query = "ALTER TABLE invocation ADD COLUMN remote_cpu_time NUMERIC(10,3) NULL"
        if self.db.connection().dialect.name != 'sqlite':
            query += ' AFTER remote_duration'
        self.execute(query)
        self.execute("ALTER TABLE job_instance ADD COLUMN multiplier_factor INT NOT NULL DEFAULT 1")
        self.execute("ALTER TABLE job_instance ADD COLUMN exitcode INT NULL")
        
        success = ['JOB_SUCCESS', 'POST_SCRIPT_SUCCESS']
        failure = ['PRE_SCRIPT_FAILED', 'SUBMIT_FAILED', 'JOB_FAILURE', 'POST_SCRIPT_FAILED']

        try:
            q = self.db.query(JobInstance.job_instance_id).order_by(JobInstance.job_instance_id)
            for r in q.all():
                qq = self.db.query(Jobstate.state)
                qq = qq.filter(Jobstate.job_instance_id == r.job_instance_id)
                qq = qq.order_by(Jobstate.jobstate_submit_seq.desc()).limit(1)
                for rr in qq.all():
                    if rr.state in success:
                        self.db.execute('UPDATE job_instance SET exitcode = 0 WHERE job_instance_id = %s' \
                            % r.job_instance_id )
                    elif rr.state in failure:
                        self.db.execute('UPDATE job_instance SET exitcode = 256 WHERE job_instance_id = %s' \
                        % r.job_instance_id)
                    else:
                        pass
        except (OperationalError, ProgrammingError):
            pass                
        
        self.db.commit()
         
    def downgrade(self, force=False):
        """ Downgrade to this version will not be allowed."""
        pass
    
    def execute(self, query):
        try:
            self.db.execute(query)
        except (OperationalError, ProgrammingError):
            pass
        except Exception, e:
            self.db.rollback()
            raise DBAdminError(e)
{'fraction_non_alphanumeric': 0.09501187648456057, 'fraction_numerical': 0.004318721658389117, 'mean_word_length': 2.10455764075067, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6196238', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1314, 'n_words': 311}