1 | """ |
---|
2 | Migration script to add the api_keys table. |
---|
3 | """ |
---|
4 | |
---|
5 | from sqlalchemy import * |
---|
6 | from migrate import * |
---|
7 | from migrate.changeset import * |
---|
8 | from galaxy.model.custom_types import * |
---|
9 | |
---|
10 | import datetime |
---|
11 | now = datetime.datetime.utcnow |
---|
12 | |
---|
13 | import logging |
---|
14 | log = logging.getLogger( __name__ ) |
---|
15 | |
---|
16 | metadata = MetaData( migrate_engine ) |
---|
17 | |
---|
18 | APIKeys_table = Table( "api_keys", metadata, |
---|
19 | Column( "id", Integer, primary_key=True ), |
---|
20 | Column( "create_time", DateTime, default=now ), |
---|
21 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
22 | Column( "key", TrimmedString( 32 ), index=True, unique=True ) ) |
---|
23 | |
---|
24 | def upgrade(): |
---|
25 | print __doc__ |
---|
26 | metadata.reflect() |
---|
27 | try: |
---|
28 | APIKeys_table.create() |
---|
29 | except Exception, e: |
---|
30 | log.debug( "Creating api_keys table failed: %s" % str( e ) ) |
---|
31 | |
---|
32 | def downgrade(): |
---|
33 | # Load existing tables |
---|
34 | metadata.reflect() |
---|
35 | try: |
---|
36 | APIKeys_table.drop() |
---|
37 | except Exception, e: |
---|
38 | log.debug( "Dropping api_keys table failed: %s" % str( e ) ) |
---|