Best Python code snippet using localstack_python
0078_add_columns_for_disk_usage_accounting.py
Source:0078_add_columns_for_disk_usage_accounting.py
1"""2Migration script to add 'total_size' column to the dataset table, 'purged'3column to the HDA table, and 'disk_usage' column to the User and GalaxySession4tables.5"""6from sqlalchemy import *7from sqlalchemy.orm import *8from migrate import *9from migrate.changeset import *10import logging11log = logging.getLogger( __name__ )12metadata = MetaData( migrate_engine )13db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )14def upgrade():15 print __doc__16 metadata.reflect()17 try:18 Dataset_table = Table( "dataset", metadata, autoload=True )19 c = Column( 'total_size', Numeric( 15, 0 ) )20 c.create( Dataset_table )21 assert c is Dataset_table.c.total_size22 except Exception, e:23 print "Adding total_size column to dataset table failed: %s" % str( e )24 log.debug( "Adding total_size column to dataset table failed: %s" % str( e ) )25 try:26 HistoryDatasetAssociation_table = Table( "history_dataset_association", metadata, autoload=True )27 c = Column( "purged", Boolean, index=True, default=False )28 c.create( HistoryDatasetAssociation_table )29 assert c is HistoryDatasetAssociation_table.c.purged30 db_session.execute(HistoryDatasetAssociation_table.update().values(purged=False))31 except Exception, e:32 print "Adding purged column to history_dataset_association table failed: %s" % str( e )33 log.debug( "Adding purged column to history_dataset_association table failed: %s" % str( e ) )34 try:35 User_table = Table( "galaxy_user", metadata, autoload=True )36 c = Column( 'disk_usage', Numeric( 15, 0 ), index=True )37 c.create( User_table )38 assert c is User_table.c.disk_usage39 except Exception, e:40 print "Adding disk_usage column to galaxy_user table failed: %s" % str( e )41 log.debug( "Adding disk_usage column to galaxy_user table failed: %s" % str( e ) )42 try:43 GalaxySession_table = Table( "galaxy_session", metadata, autoload=True )44 c = Column( 'disk_usage', Numeric( 15, 0 ), index=True )45 c.create( GalaxySession_table )46 assert c is GalaxySession_table.c.disk_usage47 except Exception, e:48 print "Adding disk_usage column to galaxy_session table failed: %s" % str( e )49 log.debug( "Adding disk_usage column to galaxy_session table failed: %s" % str( e ) )50def downgrade():51 metadata.reflect()52 try:53 Dataset_table = Table( "dataset", metadata, autoload=True )54 Dataset_table.c.total_size.drop()55 except Exception, e:56 print "Dropping total_size column from dataset table failed: %s" % str( e )57 log.debug( "Dropping total_size column from dataset table failed: %s" % str( e ) )58 try:59 HistoryDatasetAssociation_table = Table( "history_dataset_association", metadata, autoload=True )60 HistoryDatasetAssociation_table.c.purged.drop()61 except Exception, e:62 print "Dropping purged column from history_dataset_association table failed: %s" % str( e )63 log.debug( "Dropping purged column from history_dataset_association table failed: %s" % str( e ) )64 try:65 User_table = Table( "galaxy_user", metadata, autoload=True )66 User_table.c.disk_usage.drop()67 except Exception, e:68 print "Dropping disk_usage column from galaxy_user table failed: %s" % str( e )69 log.debug( "Dropping disk_usage column from galaxy_user table failed: %s" % str( e ) )70 try:71 GalaxySession_table = Table( "galaxy_session", metadata, autoload=True )72 GalaxySession_table.c.disk_usage.drop()73 except Exception, e:74 print "Dropping disk_usage column from galaxy_session table failed: %s" % str( e )...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!