Changeset View
Changeset View
Standalone View
Standalone View
swh/core/cli/db.py
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | |||||
@click.argument("module", required=True) | @click.argument("module", required=True) | ||||
@click.option( | @click.option( | ||||
"--all/--no-all", | "--all/--no-all", | ||||
"show_all", | "show_all", | ||||
help="Show version history.", | help="Show version history.", | ||||
default=False, | default=False, | ||||
show_default=True, | show_default=True, | ||||
) | ) | ||||
@click.option("--module-config-key", help="Module config key to lookup.", default=None) | |||||
@click.pass_context | @click.pass_context | ||||
def db_version(ctx, module, show_all): | def db_version(ctx, module, show_all, module_config_key=None): | ||||
"""Print the database version for the Software Heritage. | """Print the database version for the Software Heritage. | ||||
Example:: | Example:: | ||||
swh db version -d swh-test | swh db version -d swh-test | ||||
swh db version scheduler | |||||
swh db version scrubber --module-config-key=scrubber_db | |||||
""" | """ | ||||
from swh.core.db.db_utils import get_database_info, import_swhmodule | from swh.core.db.db_utils import get_database_info, import_swhmodule | ||||
# use the db cnx from the config file; the expected config entry is the | # use the db cnx from the config file; the expected config entry is either the given | ||||
# given module name | # module_config_key or defaulting to the module name (if module_config_key is not | ||||
cfg = ctx.obj["config"].get(module, {}) | # provided) | ||||
cfg = ctx.obj["config"].get(module_config_key or module, {}) | |||||
dbname = get_dburl_from_config(cfg) | dbname = get_dburl_from_config(cfg) | ||||
if not dbname: | if not dbname: | ||||
raise click.BadParameter( | raise click.BadParameter( | ||||
"Missing the postgresql connection configuration. Either fix your " | "Missing the postgresql connection configuration. Either fix your " | ||||
"configuration file or use the --dbname option." | "configuration file or use the --dbname option." | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | @click.option( | ||||
metavar="VERSION", | metavar="VERSION", | ||||
default=None, | default=None, | ||||
) | ) | ||||
@click.option( | @click.option( | ||||
"--interactive/--non-interactive", | "--interactive/--non-interactive", | ||||
help="Do not ask questions (use default answer to all questions)", | help="Do not ask questions (use default answer to all questions)", | ||||
default=True, | default=True, | ||||
) | ) | ||||
@click.option( | |||||
"--module-config-key", help="Module configuration key to lookup.", default=None | |||||
) | |||||
@click.pass_context | @click.pass_context | ||||
def db_upgrade(ctx, module, to_version, interactive): | def db_upgrade(ctx, module, to_version, interactive, module_config_key): | ||||
"""Upgrade the database for given module (to a given version if specified). | """Upgrade the database for given module (to a given version if specified). | ||||
Examples:: | Examples:: | ||||
swh db upgrade storage | swh db upgrade storage | ||||
swh db upgrade scheduler --to-version=10 | swh db upgrade scheduler --to-version=10 | ||||
swh db upgrade scrubber --to-version=10 --module-config-key=scrubber_db | |||||
""" | """ | ||||
from swh.core.db.db_utils import ( | from swh.core.db.db_utils import ( | ||||
get_database_info, | get_database_info, | ||||
import_swhmodule, | import_swhmodule, | ||||
swh_db_upgrade, | swh_db_upgrade, | ||||
swh_set_db_module, | swh_set_db_module, | ||||
) | ) | ||||
# use the db cnx from the config file; the expected config entry is the | # use the db cnx from the config file; the expected config entry is either the given | ||||
# given module name | # module_config_key or defaulting to the module name (if module_config_key is not | ||||
cfg = ctx.obj["config"].get(module, {}) | # provided) | ||||
cfg = ctx.obj["config"].get(module_config_key or module, {}) | |||||
dbname = get_dburl_from_config(cfg) | dbname = get_dburl_from_config(cfg) | ||||
if not dbname: | if not dbname: | ||||
raise click.BadParameter( | raise click.BadParameter( | ||||
"Missing the postgresql connection configuration. Either fix your " | "Missing the postgresql connection configuration. Either fix your " | ||||
"configuration file or use the --dbname option." | "configuration file or use the --dbname option." | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |