Skip to content
Snippets Groups Projects
Commit 9d6aed30 authored by David Douard's avatar David Douard
Browse files

cli/db: do not attempt to create the DB by default

this is needed to prevent the command to depend on having pg's createdb
tool installed on the machine running the 'swh db-init' command.

In a normal deployment setup, this pg tool is not expected to be present
on every machine on which one want to be able to use this 'swh db-init'
command.
parent 3f4d9667
No related branches found
No related tags found
Loading
......@@ -19,9 +19,12 @@ logger = logging.getLogger(__name__)
@click.argument('module', nargs=-1, required=True)
@click.option('--db-name', '-d', help='Database name.',
default='softwareheritage-dev', show_default=True)
def db_init(module, db_name=None):
@click.option('--create-db/--no-create-db', '-C',
help='Attempt to create the database.',
default=False)
def db_init(module, db_name, create_db):
"""Initialise a database for the Software Heritage <module>. By
default, attempts to create the database first.
default, does not attempt to create the database.
Example:
......@@ -67,8 +70,9 @@ def db_init(module, db_name=None):
dump_files.extend(sorted(glob.glob(path.join(sqldir, '*.sql')),
key=sortkey))
# Create the db (or fail silently if already existing)
pg_createdb(db_name, check=False)
if create_db:
# Create the db (or fail silently if already existing)
pg_createdb(db_name, check=False)
# Try to retrieve the db version if any
db_version = swh_db_version(db_name)
if not db_version: # Initialize the db
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment