diff --git a/bigchaindb/commands/bigchain.py b/bigchaindb/commands/bigchain.py index 3d7a0825..52c2c7f7 100644 --- a/bigchaindb/commands/bigchain.py +++ b/bigchaindb/commands/bigchain.py @@ -64,7 +64,14 @@ def run_configure(args, skip_if_exists=False): def run_init(args): """Initialize the database""" bigchaindb.config_utils.file_config(args.config) - db.init() + # TODO Provide mechanism to: + # 1. prompt the user to inquire whether they wish to drop the db + # 2. force the init, (e.g., via -f flag) + try: + db.init() + except DatabaseAlreadyExists: + print('The database already exists.') + print('If you wish to re-initialize it, first drop it.') def run_drop(args): diff --git a/tests/test_commands.py b/tests/test_commands.py index 6cc542d4..fc5db73e 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -53,3 +53,9 @@ def test_bigchain_show_config(capsys, mock_file_config): pprint(config) expected_outout_config, _ = capsys.readouterr() assert output_config == expected_outout_config + + +def test_bigchain_run_init_when_db_exists(mock_file_config, mock_db_init_with_existing_db): + from bigchaindb.commands.bigchain import run_init + args = Namespace(config=None) + run_init(args)