Skip to content

Commit

Permalink
Check connection string is set in rcdb cli 'db' command
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Nov 22, 2023
1 parent 002de60 commit 5761d84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 0 additions & 1 deletion python/rcdb/rcdb_cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from rcdb.rcdb_cli.app import rcdb_cli

rcdb_cli(prog_name="rcdb")

3 changes: 3 additions & 0 deletions python/rcdb/rcdb_cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def rcdb_cli(ctx, user_config, connection, config, verbose):
# Create a rcdb_app_context object and remember it as the context object. From
# this point onwards other commands can refer to it by using the
# @pass_rcdb_context decorator.
if not connection:
print("(!)WARNING no connection provided! "
"Provide DB connection string via --connection/-c or RCDB_CONNECTION environment variable.")
ctx.obj = RcdbApplicationContext(os.path.abspath(user_config), connection)
ctx.obj.verbose = verbose
for key, value in config:
Expand Down
12 changes: 10 additions & 2 deletions python/rcdb/rcdb_cli/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ def db(ctx):
"""Database management commands."""
if ctx.invoked_subcommand is None:
connection_str = ctx.obj.connection_str
provider = RCDBProvider(connection_str, check_version=False)
schema_version, = provider.session.execute(select(SchemaVersion).order_by(SchemaVersion.version.desc())).first()

# We create provider manually and not using ctx.obj.db because we need check_version=False
# We separate class creation and connection because connection_str might be null
provider = RCDBProvider()
if not connection_str:
print("ERROR connection string is missing.")
exit(1)
provider.connect(connection_str, check_version=False)
query = select(SchemaVersion).order_by(SchemaVersion.version.desc())
schema_version, = provider.session.execute(query).first()
print("Schema version: {} - '{}'".format(schema_version.version, schema_version.comment))


Expand Down

0 comments on commit 5761d84

Please sign in to comment.