This document is for an old release of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

Source code for tool_shed.webapp.model.migrate.versions.0020_add_repository_type_column

"""Migration script to add the type column to the repository table."""

import logging
import sys

from sqlalchemy import (

# Need our custom types, but don't import anything else from model
from galaxy.model.custom_types import TrimmedString

log = logging.getLogger(__name__)
handler = logging.StreamHandler(sys.stdout)
format = "%(name)s %(levelname)s %(asctime)s %(message)s"
formatter = logging.Formatter(format)

metadata = MetaData()

[docs]def upgrade(migrate_engine): print(__doc__) metadata.bind = migrate_engine metadata.reflect() Repository_table = Table("repository", metadata, autoload=True) c = Column("type", TrimmedString(255), index=True) try: # Create c.create(Repository_table, index_name="ix_repository_type") assert c is Repository_table.c.type except Exception: log.exception("Adding type column to the repository table failed.") # Update the type column to have the default unrestricted value. cmd = "UPDATE repository SET type = 'unrestricted'" migrate_engine.execute(cmd)
[docs]def downgrade(migrate_engine): metadata.bind = migrate_engine metadata.reflect() # Drop type column from repository table. Repository_table = Table("repository", metadata, autoload=True) try: Repository_table.c.type.drop() except Exception: log.exception("Dropping column type from the repository table failed.")