diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index feb214ccb7d..ab425af7937 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -895,6 +895,7 @@ class Dataset( object ): self.external_filename = external_filename self._extra_files_path = extra_files_path self.file_size = file_size + self.uuid = None def get_file_name( self ): if not self.external_filename: diff --git a/lib/galaxy/model/custom_types.py b/lib/galaxy/model/custom_types.py index 3ff071e77af..3f7f9b38d31 100644 --- a/lib/galaxy/model/custom_types.py +++ b/lib/galaxy/model/custom_types.py @@ -1,9 +1,11 @@ from sqlalchemy.types import * + import pkg_resources pkg_resources.require("simplejson") import simplejson import pickle import copy +import uuid import binascii from galaxy.util.bunch import Bunch from galaxy.util.aliaspickler import AliasPickleModule @@ -84,6 +86,39 @@ class MetadataType( JSONType ): ret = None return ret + + +class UUIDType(TypeDecorator): + """ + Platform-independent UUID type. + + Based on http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#backend-agnostic-guid-type + Changed to remove sqlalchemy 0.8 specific code + + CHAR(32), storing as stringified hex values. + """ + impl = CHAR + + def load_dialect_impl(self, dialect): + return dialect.type_descriptor(CHAR(32)) + + def process_bind_param(self, value, dialect): + if value is None: + return value + else: + if not isinstance(value, uuid.UUID): + return "%.32x" % uuid.UUID(value) + else: + # hexstring + return "%.32x" % value + + def process_result_value(self, value, dialect): + if value is None: + return value + else: + return uuid.UUID(value) + + class TrimmedString( TypeDecorator ): impl = String def process_bind_param( self, value, dialect ): diff --git a/lib/galaxy/model/mapping.py b/lib/galaxy/model/mapping.py index f3b1ff8c6a1..ff58bf7e37d 100644 --- a/lib/galaxy/model/mapping.py +++ b/lib/galaxy/model/mapping.py @@ -135,7 +135,8 @@ Dataset.table = Table( "dataset", metadata, Column( "external_filename" , TEXT ), Column( "_extra_files_path", TEXT ), Column( 'file_size', Numeric( 15, 0 ) ), - Column( 'total_size', Numeric( 15, 0 ) ) ) + Column( 'total_size', Numeric( 15, 0 ) ), + Column( 'uuid', UUIDType() ) ) HistoryDatasetAssociationDisplayAtAuthorization.table = Table( "history_dataset_association_display_at_authorization", metadata, Column( "id", Integer, primary_key=True ), diff --git a/lib/galaxy/model/migrate/versions/0110_add_dataset_uuid.py b/lib/galaxy/model/migrate/versions/0110_add_dataset_uuid.py new file mode 100644 index 00000000000..5ecdd2c5dd2 --- /dev/null +++ b/lib/galaxy/model/migrate/versions/0110_add_dataset_uuid.py @@ -0,0 +1,50 @@ +""" +Add UUID column to dataset table +""" + +from sqlalchemy import * +from sqlalchemy.orm import * +from migrate import * +from migrate.changeset import * +from galaxy.model.custom_types import UUIDType + +import logging +log = logging.getLogger( __name__ ) + +metadata = MetaData( migrate_engine ) +#db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) + +dataset_uuid_column = Column( "uuid", UUIDType, nullable=True ) + + +def display_migration_details(): + print "" + print "This migration adds uuid column to dataset table" + +def upgrade(): + print __doc__ + metadata.reflect() + + # Add the uuid colum to the dataset table + try: + dataset_table = Table( "dataset", metadata, autoload=True ) + dataset_uuid_column.create( dataset_table ) + assert dataset_uuid_column is dataset_table.c.uuid + except Exception, e: + print str(e) + log.error( "Adding column 'uuid' to dataset table failed: %s" % str( e ) ) + return + + +def downgrade(): + metadata.reflect() + + # Drop the Job table's exit_code column. + try: + dataset_table = Table( "dataset", metadata, autoload=True ) + dataset_uuid = dataset_table.c.uuid + dataset_uuid.drop() + except Exception, e: + log.debug( "Dropping 'uuid' column from dataset table failed: %s" % ( str( e ) ) ) + +