Skip to content

Commit

Permalink
Add create/migrate scripts for tool shed
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Mar 9, 2022
1 parent a961939 commit ad2f223
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
16 changes: 16 additions & 0 deletions create_toolshed_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

#######
# Use this script to verify the state of the Tool Shed database.
# If the database does not exist or is empty, it will be created
# and initialized.
# (For Galaxy and Tool Shed Install databases, use create_db.sh).
#######

cd "$(dirname "$0")"

. ./scripts/common_startup_functions.sh

setup_python

python ./scripts/create_toolshed_db.py "$@" tool_shed
18 changes: 18 additions & 0 deletions migrate_toolshed_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

#######
# Use this script to manage Tool Shed migrations.
# (Use migrate_db.sh to manage Galaxy and Tool Shed Install migrations.)
#
# To downgrade to a specific version, use something like:
# sh manage_toolshed_db.sh downgrade --version=3 tool_shed
#######

cd `dirname $0`

. ./scripts/common_startup_functions.sh

setup_python

find lib/galaxy/model/migrate/versions -name '*.pyc' -delete
python ./scripts/migrate_toolshed_db.py $@
29 changes: 29 additions & 0 deletions scripts/create_toolshed_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Creates the initial tool shed database schema using the settings defined in config/tool_shed.yml.
Note: pass '-c /location/to/your_config.yml' for non-standard ini file locations.
Note: if no database_connection is set in tool_shed.yml, the default, sqlite database will be constructed.
This script is also wrapped by create_ts_db.sh.
"""
import logging
import os.path
import sys

sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'lib')))

from galaxy.model.orm.scripts import get_config
from tool_shed.webapp.model.migrate.check import create_or_verify_database as create_tool_shed_db

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)


def invoke_create():
config = get_config(sys.argv)
create_tool_shed_db(config['db_url'])


if __name__ == "__main__":
invoke_create()
31 changes: 31 additions & 0 deletions scripts/migrate_toolshed_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
This script parses the Tool Shed config file for database connection
and then delegates to sqlalchemy_migrate shell main function in
migrate.versioning.shell.
It is wrapped by migrate_toolshed_db.sh (see that file for usage).
"""
import logging
import os.path
import sys

from migrate.versioning.shell import main

sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'lib')))

from galaxy.model.orm.scripts import get_config

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)


def invoke_migrate_main():
# Migrate has its own args, so cannot use argparse
config = get_config(sys.argv, use_argparse=False, cwd=os.getcwd())
db_url = config['db_url']
repo = config['repo']

main(repository=repo, url=db_url)


if __name__ == "__main__":
invoke_migrate_main()

0 comments on commit ad2f223

Please sign in to comment.