Fully initialize empty databaseses if GALAXY_TEST_DBURI is set and DB doesn't exist

This commit is contained in:
mvdbeek
2019-03-29 21:46:18 +01:00
parent 34eb9468d4
commit 7b4cf5b61d
2 changed files with 15 additions and 0 deletions
+14
View File
@@ -25,9 +25,15 @@ from six.moves import (
shlex_quote
)
from six.moves.urllib.parse import urlparse
from sqlalchemy_utils import (
create_database,
database_exists,
)
from galaxy.app import UniverseApplication as GalaxyUniverseApplication
from galaxy.config import LOGGING_CONFIG_DEFAULT
from galaxy.model import mapping
from galaxy.model.tool_shed_install import mapping as toolshed_mapping
from galaxy.tools.verify.interactor import GalaxyInteractorApi, verify_tool
from galaxy.util import asbool, download_to_file
from galaxy.util.properties import load_app_properties
@@ -311,6 +317,7 @@ def copy_database_template(source, db_path):
def database_conf(db_path, prefix="GALAXY", prefer_template_database=False):
"""Find (and populate if needed) Galaxy database connection."""
database_auto_migrate = False
check_migrate_databases = True
dburi_var = "%s_TEST_DBURI" % prefix
template_name = None
if dburi_var in os.environ:
@@ -323,6 +330,12 @@ def database_conf(db_path, prefix="GALAXY", prefer_template_database=False):
actual_db = "gxtest" + ''.join(random.choice(string.ascii_uppercase) for _ in range(10))
actual_database_parsed = database_template_parsed._replace(path="/%s" % actual_db)
database_connection = actual_database_parsed.geturl()
if not database_exists(database_connection):
# We pass by migrations and instantiate the current table
create_database(database_connection)
mapping.init('/tmp', database_connection, create_tables=True, map_install_models=True)
toolshed_mapping.init(database_connection, create_tables=True)
check_migrate_databases = False
else:
default_db_filename = "%s.sqlite" % prefix.lower()
template_var = "%s_TEST_DB_TEMPLATE" % prefix
@@ -337,6 +350,7 @@ def database_conf(db_path, prefix="GALAXY", prefer_template_database=False):
database_auto_migrate = True
database_connection = 'sqlite:///%s' % db_path
config = {
"check_migrate_databases": check_migrate_databases,
"database_connection": database_connection,
"database_auto_migrate": database_auto_migrate
}