From ad7f7f9268fe44b7b00b67fee2504caaa0ae4124 Mon Sep 17 00:00:00 2001 From: John Davis Date: Wed, 14 Sep 2022 22:22:45 -0400 Subject: [PATCH] Remove run_alembic.sh from root; user scripts/run_alembic.py instead. Rationale: move developer-focused scripts out of galaxy root. --- run_alembic.sh | 54 ------------------------------------------ scripts/run_alembic.py | 53 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 57 deletions(-) delete mode 100755 run_alembic.sh mode change 100644 => 100755 scripts/run_alembic.py diff --git a/run_alembic.sh b/run_alembic.sh deleted file mode 100755 index 3c0172e5045..00000000000 --- a/run_alembic.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh - -####### -# Use this script if you need to run migration operations on the Tool Shed -# Install data model (the *tsi* migration branch), or if you need access to the -# full scope of command line options provided by Alembic. For regular migration -# tasks, uses the db.sh script. -# -# We use branch labels to distinguish between the galaxy and the tool_shed_install models, -# so in most cases you'll need to identify the branch to which your command should be applied. -# Use these identifiers: `gxy` for galaxy, and `tsi` for tool_shed_install. -# -# To create a revision for galaxy: -# ./run_alembic.sh revision --head=gxy@head -m "your description" -# -# To create a revision for tool_shed_install: -# ./run_alembic.sh revision --head=tsi@head -m "your description" -# -# To upgrade: -# ./run_alembic.sh upgrade gxy@head # upgrade gxy to head revision -# ./run_alembic.sh upgrade gxy@+1 # upgrade gxy to 1 revision above current -# ./run_alembic.sh upgrade [revision identifier] # upgrade gxy to a specific revision -# ./run_alembic.sh upgrade [revision identifier]+1 # upgrade gxy to 1 revision above specific revision -# ./run_alembic.sh upgrade heads # upgrade gxy and tsi to head revisions -# -# To downgrade: -# ./run_alembic.sh downgrade gxy@base # downgrade gxy to base (database with empty alembic table) -# ./run_alembic.sh downgrade gxy@-1 # downgrade gxy to 1 revision below current -# ./run_alembic.sh downgrade [revision identifier] # downgrade gxy to a specific revision -# ./run_alembic.sh downgrade [revision identifier]-1 # downgrade gxy to 1 revision below specific revision -# -# To pass a galaxy config file, use `--galaxy-config` -# -# You may also override the galaxy database url and/or the -# tool shed install database url, as well as the database_template -# and database_encoding configuration options with env vars: -# GALAXY_CONFIG_OVERRIDE_DATABASE_CONNECTION=my-db-url ./run_alembic.sh ... -# GALAXY_INSTALL_CONFIG_OVERRIDE_DATABASE_CONNECTION=my-other-db-url ./run_alembic.sh ... -# -# Further information: -# Galaxy migration documentation: lib/galaxy/model/migrations/README.md -# Alembic documentation: https://alembic.sqlalchemy.org -####### - -ALEMBIC_CONFIG='lib/galaxy/model/migrations/alembic.ini' - -cd "$(dirname "$0")" || exit - -. ./scripts/common_startup_functions.sh - -setup_python - -find lib/galaxy/model/migrations/alembic -name '*.pyc' -delete -python ./scripts/run_alembic.py --config "$ALEMBIC_CONFIG" "$@" diff --git a/scripts/run_alembic.py b/scripts/run_alembic.py old mode 100644 new mode 100755 index 78f976ff158..b642c84e0c7 --- a/scripts/run_alembic.py +++ b/scripts/run_alembic.py @@ -1,8 +1,51 @@ +#!/usr/bin/env python + """ -This script retrieves relevant configuration values and invokes -the Alembic console runner. -It is wrapped by run_alembic.sh (see that file for usage). +Retrieves relevant configuration values and invokes the Alembic console runner. + +Must be executed from Galaxy's root directory. + +Use this script if you need to run migration operations on the Tool Shed +Install data model (the *tsi* migration branch), or if you need access to the +full scope of command line options provided by Alembic. For regular migration +tasks, uses the db.sh script. + +We use branch labels to distinguish between the galaxy and the tool_shed_install models, +so in most cases you'll need to identify the branch to which your command should be applied. +Use these identifiers: `gxy` for galaxy, and `tsi` for tool_shed_install. + +To create a revision for galaxy: +./scripts/run_alembic.py revision --head=gxy@head -m "your description" + +To create a revision for tool_shed_install: +./scripts/run_alembic.py revision --head=tsi@head -m "your description" + +To upgrade: +./scripts/run_alembic.py upgrade gxy@head # upgrade gxy to head revision +./scripts/run_alembic.py upgrade gxy@+1 # upgrade gxy to 1 revision above current +./scripts/run_alembic.py upgrade [revision identifier] # upgrade gxy to a specific revision +./scripts/run_alembic.py upgrade [revision identifier]+1 # upgrade gxy to 1 revision above specific revision +./scripts/run_alembic.py upgrade heads # upgrade gxy and tsi to head revisions + +To downgrade: +./scripts/run_alembic.py downgrade gxy@base # downgrade gxy to base (database with empty alembic table) +./scripts/run_alembic.py downgrade gxy@-1 # downgrade gxy to 1 revision below current +./scripts/run_alembic.py downgrade [revision identifier] # downgrade gxy to a specific revision +./scripts/run_alembic.py downgrade [revision identifier]-1 # downgrade gxy to 1 revision below specific revision + +To pass a galaxy config file, use `--galaxy-config` + +You may also override the galaxy database url and/or the +tool shed install database url, as well as the database_template +and database_encoding configuration options with env vars: +GALAXY_CONFIG_OVERRIDE_DATABASE_CONNECTION=my-db-url ./scripts/run_alembic.py ... +GALAXY_INSTALL_CONFIG_OVERRIDE_DATABASE_CONNECTION=my-other-db-url ./scripts/run_alembic.py ... + +Further information: +Galaxy migration documentation: lib/galaxy/model/migrations/README.md +Alembic documentation: https://alembic.sqlalchemy.org """ + import logging import os.path import sys @@ -18,8 +61,12 @@ from galaxy.model.migrations.scripts import ( logging.basicConfig(level=logging.DEBUG) log = logging.getLogger(__name__) +ALEMBIC_CONFIG = "lib/galaxy/model/migrations/alembic.ini" + def run(): + sys.argv.insert(1, "--config") + sys.argv.insert(2, ALEMBIC_CONFIG) gxy_config, tsi_config, _ = get_configuration(sys.argv, os.getcwd()) add_db_urls_to_command_arguments(sys.argv, gxy_config.url, tsi_config.url) invoke_alembic()