PageRenderTime 37ms CodeModel.GetById 12ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0026_cloud_tables.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 158 lines | 135 code | 20 blank | 3 comment | 0 complexity | d263c6306459aafa5d9ba4632151c0cb MD5 | raw file
  1from sqlalchemy import *
  2from migrate import *
  3
  4import datetime
  5now = datetime.datetime.utcnow
  6
  7# Need our custom types, but don't import anything else from model
  8from galaxy.model.custom_types import *
  9
 10import logging
 11log = logging.getLogger( __name__ )
 12
 13metadata = MetaData()
 14
 15def display_migration_details():
 16    print
 17    print "========================================"
 18    print "This script adds tables needed for Galaxy cloud functionality."
 19    print "========================================"
 20
 21CloudImage_table = Table( "cloud_image", metadata,
 22    Column( "id", Integer, primary_key=True ),
 23    Column( "create_time", DateTime, default=now ),
 24    Column( "update_time", DateTime, default=now, onupdate=now ),
 25    Column( "provider_type", TEXT ),
 26    Column( "image_id", TEXT, nullable=False ),
 27    Column( "manifest", TEXT ),
 28    Column( "state", TEXT ),
 29    Column( "architecture", TEXT ),
 30    Column( "deleted", Boolean, default=False ) )
 31
 32""" UserConfiguredInstance (UCI) table """
 33UCI_table = Table( "cloud_uci", metadata,
 34    Column( "id", Integer, primary_key=True ),
 35    Column( "create_time", DateTime, default=now ),
 36    Column( "update_time", DateTime, default=now, onupdate=now ),
 37    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
 38    Column( "credentials_id", Integer, ForeignKey( "cloud_user_credentials.id" ), index=True ),
 39    Column( "key_pair_name", TEXT ),
 40    Column( "key_pair_material", TEXT ),
 41    Column( "name", TEXT ),
 42    Column( "state", TEXT ),
 43    Column( "error", TEXT ),
 44    Column( "total_size", Integer ),
 45    Column( "launch_time", DateTime ),
 46    Column( "deleted", Boolean, default=False ) )
 47
 48CloudInstance_table = Table( "cloud_instance", metadata,
 49    Column( "id", Integer, primary_key=True ),
 50    Column( "create_time", DateTime, default=now ),
 51    Column( "update_time", DateTime, default=now, onupdate=now ),
 52    Column( "launch_time", DateTime ),
 53    Column( "stop_time", DateTime ),
 54    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
 55    Column( "uci_id", Integer, ForeignKey( "cloud_uci.id" ), index=True ),
 56    Column( "type", TEXT ),
 57    Column( "reservation_id", TEXT ),
 58    Column( "instance_id", TEXT ),
 59    Column( "mi_id", Integer, ForeignKey( "cloud_image.id" ), index=True ),
 60    Column( "state", TEXT ),
 61    Column( "error", TEXT ),
 62    Column( "public_dns", TEXT ),
 63    Column( "private_dns", TEXT ),
 64    Column( "security_group", TEXT ),
 65    Column( "availability_zone", TEXT ) )
 66
 67CloudStore_table = Table( "cloud_store", 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( "attach_time", DateTime ),
 72    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
 73    Column( "uci_id", Integer, ForeignKey( "cloud_uci.id" ), index=True, nullable=False ),
 74    Column( "volume_id", TEXT ),
 75    Column( "size", Integer, nullable=False ),
 76    Column( "availability_zone", TEXT ),
 77    Column( "inst_id", Integer, ForeignKey( "cloud_instance.id" ) ),
 78    Column( "status", TEXT ),
 79    Column( "device", TEXT ),
 80    Column( "space_consumed", Integer ),
 81    Column( "error", TEXT ),
 82    Column( "deleted", Boolean, default=False ) )
 83
 84CloudSnapshot_table = Table( "cloud_snapshot", metadata,
 85    Column( "id", Integer, primary_key=True ),
 86    Column( "create_time", DateTime, default=now ),
 87    Column( "update_time", DateTime, default=now, onupdate=now ),
 88    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
 89    Column( "uci_id", Integer, ForeignKey( "cloud_uci.id" ), index=True ),
 90    Column( "store_id", Integer, ForeignKey( "cloud_store.id" ), index=True, nullable=False ),
 91    Column( "snapshot_id", TEXT ),
 92    Column( "status", TEXT ),
 93    Column( "description", TEXT ),
 94    Column( "error", TEXT ),
 95    Column( "deleted", Boolean, default=False ) )
 96
 97CloudUserCredentials_table = Table( "cloud_user_credentials", metadata,
 98    Column( "id", Integer, primary_key=True ),
 99    Column( "create_time", DateTime, default=now ),
100    Column( "update_time", DateTime, default=now, onupdate=now ),
101    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
102    Column( "provider_id", Integer, ForeignKey( "cloud_provider.id" ), index=True, nullable=False ),
103    Column( "name", TEXT ),
104    Column( "access_key", TEXT ),
105    Column( "secret_key", TEXT ),
106    Column( "deleted", Boolean, default=False ) )
107
108CloudProvider_table = Table( "cloud_provider", metadata,
109    Column( "id", Integer, primary_key=True ),
110    Column( "create_time", DateTime, default=now ),
111    Column( "update_time", DateTime, default=now, onupdate=now ),
112    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
113    Column( "type", TEXT, nullable=False ),
114    Column( "name", TEXT ),
115    Column( "region_connection", TEXT ),
116    Column( "region_name", TEXT ),
117    Column( "region_endpoint", TEXT ),
118    Column( "is_secure", Boolean ),
119    Column( "host", TEXT ),
120    Column( "port", Integer ),
121    Column( "proxy", TEXT ),
122    Column( "proxy_port", TEXT ),
123    Column( "proxy_user", TEXT ),
124    Column( "proxy_pass", TEXT ),
125    Column( "debug", Integer ),
126    Column( "https_connection_factory", TEXT ),
127    Column( "path", TEXT ),
128    Column( "deleted", Boolean, default=False ) )
129
130def upgrade(migrate_engine):
131    metadata.bind = migrate_engine
132    display_migration_details()
133    # Load existing tables
134    metadata.reflect()
135
136    CloudProvider_table.create()
137    CloudUserCredentials_table.create()
138
139    CloudImage_table.create()
140    UCI_table.create()
141
142    CloudInstance_table.create()
143    CloudStore_table.create()
144    CloudSnapshot_table.create()
145
146def downgrade(migrate_engine):
147    metadata.bind = migrate_engine
148    metadata.reflect()
149
150    CloudInstance_table.drop()
151    CloudSnapshot_table.drop()
152    CloudStore_table.drop()
153
154    UCI_table.drop()
155    CloudImage_table.drop()
156
157    CloudUserCredentials_table.drop()
158    CloudProvider_table.drop()