root/galaxy-central/lib/galaxy/webapps/community/model/migrate/versions/0001_initial_tables.py

リビジョン 2, 6.6 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1"""
2Migration script to create initial tables.
3"""
4
5from sqlalchemy import *
6from migrate import *
7
8import datetime
9now = datetime.datetime.utcnow
10
11# Need our custom types, but don't import anything else from model
12from galaxy.model.custom_types import *
13
14import logging
15log = logging.getLogger( __name__ )
16
17metadata = MetaData( migrate_engine )
18
19User_table = Table( "galaxy_user", metadata,
20    Column( "id", Integer, primary_key=True),
21    Column( "create_time", DateTime, default=now ),
22    Column( "update_time", DateTime, default=now, onupdate=now ),
23    Column( "email", TrimmedString( 255 ), nullable=False ),
24    Column( "username", String( 255 ), index=True ),
25    Column( "password", TrimmedString( 40 ), nullable=False ),
26    Column( "external", Boolean, default=False ),
27    Column( "deleted", Boolean, index=True, default=False ),
28    Column( "purged", Boolean, index=True, default=False ) )
29
30Group_table = Table( "galaxy_group", metadata,
31    Column( "id", Integer, primary_key=True ),
32    Column( "create_time", DateTime, default=now ),
33    Column( "update_time", DateTime, default=now, onupdate=now ),
34    Column( "name", String( 255 ), index=True, unique=True ),
35    Column( "deleted", Boolean, index=True, default=False ) )
36
37Role_table = Table( "role", metadata,
38    Column( "id", Integer, primary_key=True ),
39    Column( "create_time", DateTime, default=now ),
40    Column( "update_time", DateTime, default=now, onupdate=now ),
41    Column( "name", String( 255 ), index=True, unique=True ),
42    Column( "description", TEXT ),
43    Column( "type", String( 40 ), index=True ),
44    Column( "deleted", Boolean, index=True, default=False ) )
45
46UserGroupAssociation_table = Table( "user_group_association", metadata,
47    Column( "id", Integer, primary_key=True ),
48    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
49    Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),
50    Column( "create_time", DateTime, default=now ),
51    Column( "update_time", DateTime, default=now, onupdate=now ) )
52
53UserRoleAssociation_table = Table( "user_role_association", metadata,
54    Column( "id", Integer, primary_key=True ),
55    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
56    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ),
57    Column( "create_time", DateTime, default=now ),
58    Column( "update_time", DateTime, default=now, onupdate=now ) )
59
60GroupRoleAssociation_table = Table( "group_role_association", metadata,
61    Column( "id", Integer, primary_key=True ),
62    Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),
63    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ),
64    Column( "create_time", DateTime, default=now ),
65    Column( "update_time", DateTime, default=now, onupdate=now ) )
66
67GalaxySession_table = Table( "galaxy_session", metadata,
68    Column( "id", Integer, primary_key=True ),
69    Column( "create_time", DateTime, default=now ),
70    Column( "update_time", DateTime, default=now, onupdate=now ),
71    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True ),
72    Column( "remote_host", String( 255 ) ),
73    Column( "remote_addr", String( 255 ) ),
74    Column( "referer", TEXT ),
75    Column( "session_key", TrimmedString( 255 ), index=True, unique=True ), # unique 128 bit random number coerced to a string
76    Column( "is_valid", Boolean, default=False ),
77    Column( "prev_session_id", Integer ) # saves a reference to the previous session so we have a way to chain them together
78    )
79
80Tool_table = Table( "tool", metadata,
81    Column( "id", Integer, primary_key=True ),
82    Column( "guid", TrimmedString( 255 ), index=True, unique=True ),
83    Column( "tool_id", TrimmedString( 255 ), index=True ),
84    Column( "create_time", DateTime, default=now ),
85    Column( "update_time", DateTime, default=now, onupdate=now ),
86    Column( "newer_version_id", Integer, ForeignKey( "tool.id" ), nullable=True ),
87    Column( "name", TrimmedString( 255 ), index=True ),
88    Column( "description" , TEXT ),
89    Column( "user_description" , TEXT ),
90    Column( "version", TrimmedString( 255 ) ),
91    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
92    Column( "external_filename" , TEXT ),
93    Column( "deleted", Boolean, index=True, default=False ) )
94
95Event_table = Table( 'event', metadata,
96    Column( "id", Integer, primary_key=True ),
97    Column( "create_time", DateTime, default=now ),
98    Column( "update_time", DateTime, default=now, onupdate=now ),
99    Column( "state", TrimmedString( 255 ), index=True ),
100    Column( "comment", TEXT ) )
101
102ToolEventAssociation_table = Table( "tool_event_association", metadata,
103    Column( "id", Integer, primary_key=True ),
104    Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
105    Column( "event_id", Integer, ForeignKey( "event.id" ), index=True ) )
106
107Category_table = Table( "category", metadata,
108    Column( "id", Integer, primary_key=True ),
109    Column( "create_time", DateTime, default=now ),
110    Column( "update_time", DateTime, default=now, onupdate=now ),
111    Column( "name", TrimmedString( 255 ), index=True, unique=True ),
112    Column( "description" , TEXT ),
113    Column( "deleted", Boolean, index=True, default=False ) )
114
115ToolCategoryAssociation_table = Table( "tool_category_association", metadata,
116    Column( "id", Integer, primary_key=True ),
117    Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
118    Column( "category_id", Integer, ForeignKey( "category.id" ), index=True ) )
119
120Tag_table = Table( "tag", metadata,
121    Column( "id", Integer, primary_key=True ),
122    Column( "type", Integer ),
123    Column( "parent_id", Integer, ForeignKey( "tag.id" ) ),
124    Column( "name", TrimmedString(255) ),
125    UniqueConstraint( "name" ) )
126
127ToolTagAssociation_table = Table( "tool_tag_association", metadata,
128    Column( "id", Integer, primary_key=True ),
129    Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
130    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
131    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
132    Column( "user_tname", TrimmedString(255), index=True),
133    Column( "value", TrimmedString(255), index=True),
134    Column( "user_value", TrimmedString(255), index=True) )
135
136ToolAnnotationAssociation_table = Table( "tool_annotation_association", metadata,
137    Column( "id", Integer, primary_key=True ),
138    Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
139    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
140    Column( "annotation", TEXT, index=True) )
141
142def upgrade():
143    print __doc__
144    metadata.create_all()
145
146def downgrade():
147    # Operations to reverse the above upgrade go here.
148    pass
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。