Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123070
D4374.id15477.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D4374.id15477.diff
View Options
diff --git a/swh/core/cli/db.py b/swh/core/cli/db.py
--- a/swh/core/cli/db.py
+++ b/swh/core/cli/db.py
@@ -83,6 +83,44 @@
create_database_for_package(module, db_name, template)
+@db.command(name="init-admin", context_settings=CONTEXT_SETTINGS)
+@click.argument("module", required=True)
+@click.option(
+ "--db-name",
+ "-d",
+ help="Database name.",
+ default="softwareheritage-dev",
+ show_default=True,
+)
+def db_init_admin(module: str, db_name: str) -> None:
+ """Execute superuser-level initialization steps (e.g pg extensions , admin functions,
+ ...)
+
+ Example:
+
+ PGPASSWORD=... swh db init-admin -d swh-test scheduler
+
+ If you want to specify non-default postgresql connection parameters, please
+ provide them using standard environment variables or by the mean of a
+ properly crafted libpq connection URI. See psql(1) man page (section
+ ENVIRONMENTS) for details.
+
+ Note: this command requires a postgresql connection with superuser permissions (e.g
+ postgres, swh-admin, ...)
+
+ Example:
+
+ PGPORT=5434 swh db init-admin scheduler
+ swh db init-admin -d postgresql://superuser:passwd@pghost:5433/swh-scheduler \
+ scheduler
+
+ """
+ logger.debug("db_init_admin %s dn_name=%s", module, db_name)
+
+ logger.debug("db_init_admin db_name=%s", db_name)
+ init_admin_extensions(module, db_name)
+
+
@db.command(name="init", context_settings=CONTEXT_SETTINGS)
@click.argument("module", required=True)
@click.option(
@@ -207,6 +245,16 @@
return _parse_dsn(f"dbname={dsn_or_dbname}")
+def init_admin_extensions(modname: str, conninfo: str) -> None:
+ """The remaining initialization process -- running -superuser- SQL files -- is done
+ using the given conninfo, thus connecting to the newly created database
+
+ """
+ sqlfiles = get_sql_for_package(modname)
+ sqlfiles = [fname for fname in sqlfiles if "-superuser-" in fname]
+ execute_sqlfiles(sqlfiles, conninfo)
+
+
def create_database_for_package(
modname: str, conninfo: str, template: str = "template1"
):
@@ -243,13 +291,7 @@
f'CREATE DATABASE "{db_name}"',
]
)
-
- # the remaining initialization process -- running -superuser- SQL files --
- # is done using the given conninfo, thus connecting to the newly created
- # database
- sqlfiles = get_sql_for_package(modname)
- sqlfiles = [fname for fname in sqlfiles if "-superuser-" in fname]
- execute_sqlfiles(sqlfiles, conninfo)
+ init_admin_extensions(modname, conninfo)
def execute_sqlfiles(
diff --git a/swh/core/db/tests/test_cli.py b/swh/core/db/tests/test_cli.py
--- a/swh/core/db/tests/test_cli.py
+++ b/swh/core/db/tests/test_cli.py
@@ -44,9 +44,10 @@
-h, --help Show this message and exit.
Commands:
- create Create a database for the Software Heritage <module>.
- init Initialize a database for the Software Heritage <module>.
-"""
+ create Create a database for the Software Heritage <module>.
+ init Initialize a database for the Software Heritage <module>.
+ init-admin Execute superuser-level initialization steps (e.g pg extensions...
+""" # noqa
def test_swh_db_help(swhmain):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 17, 7:21 PM (2 d, 22 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3230347
Attached To
D4374: cli.db: Open init-admin subcmd to initialize superuser-level scripts
Event Timeline
Log In to Comment