# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User rc # Date 1286199759 14400 # Node ID 8774252ac0531343953428a44a5a2b07e6fe514e # Parent e32d77e1f47b1fc94b3e7511094e4b0d760f1e97 sample_tracking: migration script to modify the 'file_path' field type in 'sample_dataset' table to 'TEXT' so that it can support large file paths exceeding 255 characters --- /dev/null +++ b/lib/galaxy/model/migrate/versions/0059_sample_dataset_file_path.py @@ -0,0 +1,59 @@ +""" +Migration script to modify the 'file_path' field type in 'sample_dataset' table +to 'TEXT' so that it can support large file paths exceeding 255 characters +""" + +from sqlalchemy import * +from sqlalchemy.orm import * +from migrate import * +from migrate.changeset import * +from sqlalchemy.exc import * + +from galaxy.model.custom_types import * +from galaxy.util.json import from_json_string, to_json_string + +import datetime +now = datetime.datetime.utcnow + +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() + try: + SampleDataset_table = Table( "sample_dataset", metadata, autoload=True ) + except NoSuchTableError, e: + SampleDataset_table = None + log.debug( "Failed loading table 'sample_dataset'" ) + + if SampleDataset_table: + cmd = "SELECT id, file_path FROM sample_dataset" + result = db_session.execute( cmd ) + filepath_dict = {} + for r in result: + id = int(r[0]) + filepath_dict[id] = r[1] + # remove the 'file_path' column + try: + SampleDataset_table.c.file_path.drop() + except Exception, e: + log.debug( "Deleting column 'file_path' from the 'sample_dataset' table failed: %s" % ( str( e ) ) ) + # create the column again + try: + col = Column( "file_path", TEXT ) + col.create( SampleDataset_table ) + assert col is SampleDataset_table.c.file_path + except Exception, e: + log.debug( "Creating column 'file_path' in the 'sample_dataset' table failed: %s" % ( str( e ) ) ) + + for id, file_path in filepath_dict.items(): + cmd = "update sample_dataset set file_path='%s' where id=%i" % (file_path, id) + db_session.execute( cmd ) + +def downgrade(): + pass --- a/lib/galaxy/model/mapping.py +++ b/lib/galaxy/model/mapping.py @@ -620,7 +620,7 @@ SampleDataset.table = Table('sample_data Column( "update_time", DateTime, default=now, onupdate=now ), Column( "sample_id", Integer, ForeignKey( "sample.id" ), index=True ), Column( "name", TrimmedString( 255 ), nullable=False ), - Column( "file_path", TrimmedString( 255 ), nullable=False ), + Column( "file_path", TEXT ), Column( "status", TrimmedString( 255 ), nullable=False ), Column( "error_msg", TEXT ), Column( "size", TrimmedString( 255 ) ) )