[2] | 1 | """ |
---|
| 2 | Migration script to create tables for handling post-job actions. |
---|
| 3 | """ |
---|
| 4 | |
---|
| 5 | from sqlalchemy import * |
---|
| 6 | from sqlalchemy.orm import * |
---|
| 7 | from migrate import * |
---|
| 8 | from migrate.changeset import * |
---|
| 9 | |
---|
| 10 | import logging |
---|
| 11 | logging.basicConfig( level=logging.DEBUG ) |
---|
| 12 | log = logging.getLogger( __name__ ) |
---|
| 13 | |
---|
| 14 | # Need our custom types, but don't import anything else from model |
---|
| 15 | from galaxy.model.custom_types import * |
---|
| 16 | |
---|
| 17 | import datetime |
---|
| 18 | now = datetime.datetime.utcnow |
---|
| 19 | |
---|
| 20 | metadata = MetaData( migrate_engine ) |
---|
| 21 | db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) |
---|
| 22 | |
---|
| 23 | PostJobAction_table = Table("post_job_action", metadata, |
---|
| 24 | Column("id", Integer, primary_key=True), |
---|
| 25 | Column("workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True, nullable=False), |
---|
| 26 | Column("action_type", String(255), nullable=False), |
---|
| 27 | Column("output_name", String(255), nullable=True), |
---|
| 28 | Column("action_arguments", JSONType, nullable=True)) |
---|
| 29 | |
---|
| 30 | # PostJobActionAssociation_table = Table("post_job_action_association", metadata, |
---|
| 31 | # Column("id", Integer, primary_key=True), |
---|
| 32 | # Column("post_job_action_id", Integer, ForeignKey("post_job_action.id"), index=True, nullable=False), |
---|
| 33 | # Column("job_id", Integer, ForeignKey("job.id"), index=True, nullable=False)) |
---|
| 34 | |
---|
| 35 | tables = [PostJobAction_table]#, PostJobActionAssociation_table] |
---|
| 36 | |
---|
| 37 | def upgrade(): |
---|
| 38 | print __doc__ |
---|
| 39 | metadata.reflect() |
---|
| 40 | for table in tables: |
---|
| 41 | try: |
---|
| 42 | table.create() |
---|
| 43 | except: |
---|
| 44 | log.warn( "Failed to create table '%s', ignoring (might result in wrong schema)" % table.name ) |
---|
| 45 | |
---|
| 46 | def downgrade(): |
---|
| 47 | metadata.reflect() |
---|
| 48 | for table in tables: |
---|
| 49 | table.drop() |
---|