Created
October 1, 2020 01:43
-
-
Save jdavcs/07a83c740aab4aa0196432253514a39a to your computer and use it in GitHub Desktop.
Compare db indexes defined in mapping.py to those in the database. Call check_model.sh from galaxy root.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'lib'))) | |
from sqlalchemy import create_engine, MetaData | |
from galaxy.model import mapping | |
from galaxy.model.orm.scripts import get_config | |
def check_indexes(): | |
""" | |
Check for missing/extra db indexes defined in mapping.py and/or the database. | |
Note: pass '-c /path/to/galaxy.yml' to use the database_connection set in galaxy.yml. | |
Otherwise the default sqlite database will be used. | |
""" | |
config = get_config(sys.argv) | |
# metadata loaded from mapping.py | |
md1 = mapping.metadata | |
ix1 = set() | |
for t in md1.tables.values(): | |
ix1 |= t.indexes | |
# create EMPTY metadata, then load from db | |
md2 = MetaData(bind=create_engine(config['db_url'])) | |
md2.reflect() | |
ix2 = set() | |
for t in md2.tables.values(): | |
ix2 |= t.indexes | |
inames1 = {i.name for i in ix1} # indexes in mapping | |
inames2 = {i.name for i in ix2} # indexes in db | |
inames1m2 = inames1 - inames2 # indexes in mapping and not in db | |
inames2m1 = inames2 - inames1 # indexes in db and not in mapping | |
# print summary | |
print('db_url: %s' % config['db_url']) | |
print('in mapping.py: %d' % len(inames1)) | |
print('in db: %d' % len(inames2)) | |
print('in mapping.py, not in db: %d' % len(inames1m2)) | |
print('in db, not in mapping.py: %d' % len(inames2m1)) | |
# print indexes | |
names = inames1 | |
# names = ianmes2 | |
# names = ianmes1m2 | |
# names = ianmes2m1 | |
for i in names: | |
print(i) | |
# sanity check | |
# benchmark = 'ix_workflow_invocation_step_implicit_collection_jobs_id' | |
# assert benchmark in inames1 | |
# assert benchmark not in inames2 | |
# assert benchmark in inames1m2 | |
if __name__ == '__main__': | |
check_indexes() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cd "$(dirname "$0")" | |
. ./scripts/common_startup_functions.sh | |
setup_python | |
python ./scripts/check_model.py "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment