commit/galaxy-central: rc: Backed out of changeset 5173:ac6b14ffc984
1 new changeset in galaxy-central: http://bitbucket.org/galaxy/galaxy-central/changeset/90aafa9e685b/ changeset: r5174:90aafa9e685b user: rc date: 2011-03-04 15:59:06 summary: Backed out of changeset 5173:ac6b14ffc984 affected #: 1 file (0 bytes) --- a/lib/galaxy/model/migrate/versions/0076_fix_form_values_data_corruption.py Fri Mar 04 07:28:23 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -''' -This migrate script fixes the data corruption caused in the form_values -table (content json field) by migrate script 65. -''' -from sqlalchemy import * -from sqlalchemy.orm import * -from migrate import * -from migrate.changeset import * -from sqlalchemy.exc import * - -from galaxy.util.json import from_json_string, to_json_string - -import logging -log = logging.getLogger( __name__ ) - -metadata = MetaData( migrate_engine ) -db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) - - -def upgrade(): - print __doc__ - metadata.reflect() - - cmd = "SELECT form_values.id as id, form_values.content as values, form_definition.fields as fields " \ - + " FROM form_definition, form_values " \ - + " WHERE form_values.form_definition_id=form_definition.id " \ - + " ORDER BY form_values.id" - result = db_session.execute( cmd ) - for row in result: - # first check if loading the dict from the json succeeds - # if that fails, it means that the content field is corrupted. - try: - values_dict = from_json_string( str( row['values'] ) ) - except: - fields_list = from_json_string( str( row['fields'] ) ) - values_str = str( row['values'] ) - values_dict = {} - # look for each field name in the values and extract its value (string) - for index in range( len(fields_list) ): - field = fields_list[index] - key = '"%s": "' % field['name'] - field_index = values_str.find( key ) - # check if this is the last field - if index == len( fields_list )-1: - # since this is the last field, the value string lies between the - # field name and the '"}' string at the end, hence len(values_str)-2 - value = values_str[ field_index+len( key ):len( values_str )-2 ] - else: - # if this is not the last field then the value string lies between - # this field name and the next field name - next_field = fields_list[index+1] - next_field_index = values_str.find( '", "%s": "' % next_field['name'] ) - value = values_str[ field_index+len(key):next_field_index ] - # clean up the value string, escape the required quoutes and newline characters - value = value.replace( "'", "\''" )\ - .replace( '"', '\\\\"' )\ - .replace( '\r', "\\\\r" )\ - .replace( '\n', "\\\\n" )\ - .replace( '\t', "\\\\t" ) - # add to the new values dict - values_dict[ field['name'] ] = value - # update the db - json_values = to_json_string(values_dict) - cmd = "UPDATE form_values SET content='%s' WHERE id=%i" %( json_values, int( row['id'] ) ) - db_session.execute( cmd ) - -def downgrade(): - pass \ No newline at end of file Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket