PageRenderTime 30ms CodeModel.GetById 22ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0021_user_prefs.py

https://bitbucket.org/h_morita_dbcls/galaxy-central
Python | 45 lines | 37 code | 5 blank | 3 comment | 0 complexity | 050d439decdf9b9b452852bcb5c1db19 MD5 | raw file
 1"""
 2This migration script adds a user preferences table to Galaxy.
 3"""
 4
 5from sqlalchemy import *
 6from migrate import *
 7
 8import datetime
 9now = datetime.datetime.utcnow
10
11import logging
12log = logging.getLogger( __name__ )
13
14metadata = MetaData( migrate_engine )
15
16def display_migration_details():
17    print ""
18    print "This migration script adds a user preferences table to Galaxy."
19    print ""
20
21
22# New table to support user preferences.
23
24UserPreference_table = Table( "user_preference", metadata,
25    Column( "id", Integer, primary_key=True ),
26    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
27    Column( "name", Unicode( 255 ), index=True),
28    Column( "value", Unicode( 1024 ) ) )
29
30def upgrade():
31    display_migration_details()
32    metadata.reflect()
33    try:
34        UserPreference_table.create()
35    except Exception, e:
36        print str(e)
37        log.debug( "Creating user_preference table failed: %s" % str( e ) )
38
39def downgrade():
40    metadata.reflect()
41    try:
42        UserPreference_table.drop()
43    except Exception, e:
44        print str(e)
45        log.debug( "Dropping user_preference table failed: %s" % str( e ) )