Only optionally drop common db

This commit is contained in:
Xavier Bustamante Talavera 2019-02-04 13:38:46 +01:00
parent a89f557c41
commit 2cbaf14c45
3 changed files with 10 additions and 5 deletions

View File

@ -17,9 +17,10 @@ class SQLAlchemy(SchemaSQLAlchemy):
UUID = postgresql.UUID UUID = postgresql.UUID
CIText = citext.CIText 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.""" """A faster nuke-like option to drop everything."""
self.drop_schema() self.drop_schema()
if common_schema:
self.drop_schema(schema='common') self.drop_schema(schema='common')

View File

@ -77,7 +77,8 @@ class Devicehub(Teal):
help='The token provided by the tag provider. It is an UUID.') help='The token provided by the tag provider. It is an UUID.')
@click.option('--erase/--no-erase', @click.option('--erase/--no-erase',
default=False, 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', @click.option('--common/--no-common',
default=False, default=False,
help='Creates common databases. Only execute if the database is empty.') help='Creates common databases. Only execute if the database is empty.')
@ -93,7 +94,7 @@ class Devicehub(Teal):
print('Initializing database...'.ljust(30), end='') print('Initializing database...'.ljust(30), end='')
with click_spinner.spinner(): with click_spinner.spinner():
if erase: if erase:
self.db.drop_all() self.db.drop_all(common_schema=common)
exclude_schema = 'common' if not common else None exclude_schema = 'common' if not common else None
self._init_db(exclude_schema=exclude_schema) self._init_db(exclude_schema=exclude_schema)
InventoryDef.set_inventory_config(name, org_name, org_id, tag_url, tag_token) InventoryDef.set_inventory_config(name, org_name, org_id, tag_url, tag_token)

View File

@ -13,4 +13,7 @@ def test_create_existing_inventory():
@pytest.mark.xfail(reason='Test not developed') @pytest.mark.xfail(reason='Test not developed')
def test_delete_inventory(): 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).
"""