Skip to content

Commit 419dcd0

Browse files
authored
Add inventory_database name check (#275)
Check that database name is a word, loop until correct.
1 parent ae59e49 commit 419dcd0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/databricks/labs/ucx/install.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
TAG_STEP = "step"
2626
TAG_APP = "App"
27+
NUM_USER_ATTEMPTS = 10 # number of attempts user gets at answering a question
2728

2829
DEBUG_NOTEBOOK = """
2930
# Databricks notebook source
@@ -179,7 +180,17 @@ def _configure(self):
179180
raise err
180181

181182
logger.info("Please answer a couple of questions to configure Unity Catalog migration")
182-
inventory_database = self._question("Inventory Database", default="ucx")
183+
counter = 0
184+
while True:
185+
inventory_database = self._question("Inventory Database stored in hive_metastore", default="ucx")
186+
if re.match(r"^\w+$", inventory_database):
187+
break
188+
else:
189+
print(f"{inventory_database} is not a valid database name")
190+
counter = counter + 1
191+
if counter > NUM_USER_ATTEMPTS:
192+
msg = "Exceeded max tries to get a valid database name, try again later."
193+
raise SystemExit(msg)
183194

184195
pro_warehouses = {"[Create new PRO SQL warehouse]": "create_new"} | {
185196
f"{_.name} ({_.id}, {_.warehouse_type.value}, {_.state.value})": _.id

0 commit comments

Comments
 (0)