Merged in kellrott/galaxy-central (pull request #105)

Adding UUIDType to data model and uuid column to dataset table.
This commit is contained in:
Dannon Baker
2013-01-28 13:56:01 -05:00
4 changed files with 88 additions and 1 deletions
+1
View File
@@ -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:
+35
View File
@@ -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 ):
+2 -1
View File
@@ -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 ),
@@ -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 ) ) )