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,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):

View File

@ -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)

View File

@ -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).
"""