Skip to content

Commit

Permalink
Minor updates to dev_servers.py and tests/postgresql_fixture.py to al…
Browse files Browse the repository at this point in the history
…low parsing sqlalchemy.url in the ini file (e.g. development.ini) for the postgres port and temporary directory path
  • Loading branch information
dmichaels-harvard committed Jul 30, 2024
1 parent ec6aaed commit 9ee730f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicsnovault"
version = "11.21.0.1b3" # TODO: To become 11.21.1
version = "11.21.0.1b4" # TODO: To become 11.21.1
description = "Storage support for 4DN Data Portals."
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
14 changes: 12 additions & 2 deletions snovault/dev_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


EPILOG = __doc__
DEFAULT_DATA_DIR = "/tmp/snovault"

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -127,8 +128,15 @@ def run(app_name, config_uri, datadir, clear=False, init=False, load=False, inge
config = get_appsettings(config_uri, app_name)

if sqlalchemy_url := config.get("sqlalchemy.url", None):
# Handle sqlalchemy.url defined in development.ini that looks something like this:
# sqlalchemy.url = postgresql://postgres@localhost:5442/postgres?host=/tmp/snovaultcgap/pgdata
# New as of 2024-07-30 (dmichaels).
# Handle sqlalchemy.url property defined in development.ini that looks something like this:
# sqlalchemy.url = postgresql://postgres@localhost:5442/postgres?host=/tmp/snovault/pgdata
# This allows us to get the temporary data directory (from the URL host query-string, for both
# Postgres and ElasticSearch, e.g. /tmp/snovault) and the Postgres port (from the URL port),
# so that we can easily change where Postgres is running to support (for example) running
# both smaht-portal and cgap-portal locally simultaneously. This also obviates the need
# in the portal makefiles to parse out the port from this (sqlalchemy.url) property to
# set the SNOVAULT_DB_TEST_PORT environment variable as was currently done.
sqlalchemy_url_parsed = url_parse(sqlalchemy_url)
sqlalchemy_url_port = sqlalchemy_url_parsed.port
sqlalchemy_url_query = url_parse_query(sqlalchemy_url_parsed.query)
Expand All @@ -139,6 +147,8 @@ def run(app_name, config_uri, datadir, clear=False, init=False, load=False, inge
datadir = sqlalchemy_url_host
if (os.environ.get("SNOVAULT_DB_TEST_PORT", None) is None) and sqlalchemy_url_port:
os.environ["SNOVAULT_DB_TEST_PORT"] = str(sqlalchemy_url_port)
if not datadir:
datadir = DEFAULT_DATA_DIR

datadir = os.path.abspath(datadir)
pgdata = os.path.join(datadir, 'pgdata')
Expand Down

0 comments on commit 9ee730f

Please sign in to comment.