diff --git a/ereuse_devicehub/db.py b/ereuse_devicehub/db.py index c8b4e9ca..ac06c9d6 100644 --- a/ereuse_devicehub/db.py +++ b/ereuse_devicehub/db.py @@ -17,10 +17,11 @@ class SQLAlchemy(SchemaSQLAlchemy): UUID = postgresql.UUID CIText = citext.CIText - def drop_all(self, bind='__all__', app=None): + def drop_all(self, bind='__all__', app=None, common_schema=True): """A faster nuke-like option to drop everything.""" self.drop_schema() - self.drop_schema(schema='common') + if common_schema: + self.drop_schema(schema='common') def create_view(name, selectable): diff --git a/ereuse_devicehub/devicehub.py b/ereuse_devicehub/devicehub.py index 99dca4e0..097a538c 100644 --- a/ereuse_devicehub/devicehub.py +++ b/ereuse_devicehub/devicehub.py @@ -77,7 +77,8 @@ class Devicehub(Teal): help='The token provided by the tag provider. It is an UUID.') @click.option('--erase/--no-erase', default=False, - help='Delete the full database before? Including all schemas and users.') + help='Delete the schema before? ' + 'If --common is set this includes the common database.') @click.option('--common/--no-common', default=False, help='Creates common databases. Only execute if the database is empty.') @@ -93,7 +94,7 @@ class Devicehub(Teal): print('Initializing database...'.ljust(30), end='') with click_spinner.spinner(): if erase: - self.db.drop_all() + self.db.drop_all(common_schema=common) exclude_schema = 'common' if not common else None self._init_db(exclude_schema=exclude_schema) InventoryDef.set_inventory_config(name, org_name, org_id, tag_url, tag_token) diff --git a/tests/test_inventory.py b/tests/test_inventory.py index 28e6c6d8..b1c60f5c 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -13,4 +13,7 @@ def test_create_existing_inventory(): @pytest.mark.xfail(reason='Test not developed') def test_delete_inventory(): - pass + """Tests deleting an inventory without + disturbing other inventories (ex. keeping commmon db), and + removing its traces in common (no inventory row in inventory table). + """