database: skip invalid values when migrating namespaces
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
c9581205d3
commit
5332eab258
|
@ -96,6 +96,8 @@ class UserSqlDefinition(SqlTableDefinition):
|
||||||
users: Dict[str, Dict[str, Any]]
|
users: Dict[str, Dict[str, Any]]
|
||||||
users = db_provider.get_namespace("authorized_users")
|
users = db_provider.get_namespace("authorized_users")
|
||||||
api_user = users.pop(API_USER, {})
|
api_user = users.pop(API_USER, {})
|
||||||
|
if not isinstance(api_user, dict):
|
||||||
|
api_user = {}
|
||||||
user_vals: List[Tuple[Any, ...]] = [
|
user_vals: List[Tuple[Any, ...]] = [
|
||||||
UserInfo(
|
UserInfo(
|
||||||
username=API_USER,
|
username=API_USER,
|
||||||
|
@ -103,7 +105,12 @@ class UserSqlDefinition(SqlTableDefinition):
|
||||||
created_on=api_user.get("created_on", time.time())
|
created_on=api_user.get("created_on", time.time())
|
||||||
).as_tuple()
|
).as_tuple()
|
||||||
]
|
]
|
||||||
for user in users.values():
|
for key, user in users.items():
|
||||||
|
if not isinstance(user, dict):
|
||||||
|
logging.info(
|
||||||
|
f"Auth migration, skipping invalid value: {key} {user}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
user_vals.append(UserInfo(**user).as_tuple())
|
user_vals.append(UserInfo(**user).as_tuple())
|
||||||
placeholders = ",".join("?" * len(user_vals[0]))
|
placeholders = ",".join("?" * len(user_vals[0]))
|
||||||
conn = db_provider.connection
|
conn = db_provider.connection
|
||||||
|
|
|
@ -65,6 +65,8 @@ def _create_totals_list(
|
||||||
maximum = value if total is None else None
|
maximum = value if total is None else None
|
||||||
totals_list.append(("history", key, maximum, total, instance))
|
totals_list.append(("history", key, maximum, total, instance))
|
||||||
for item in aux_totals:
|
for item in aux_totals:
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
continue
|
||||||
totals_list.append(
|
totals_list.append(
|
||||||
(
|
(
|
||||||
item["provider"],
|
item["provider"],
|
||||||
|
@ -99,6 +101,10 @@ class TotalsSqlDefinition(SqlTableDefinition):
|
||||||
hist_ns: Dict[str, Any] = db_provider.get_item("moonraker", "history", {})
|
hist_ns: Dict[str, Any] = db_provider.get_item("moonraker", "history", {})
|
||||||
job_totals: Dict[str, Any] = hist_ns.get("job_totals", BASE_TOTALS)
|
job_totals: Dict[str, Any] = hist_ns.get("job_totals", BASE_TOTALS)
|
||||||
aux_totals: List[Dict[str, Any]] = hist_ns.get("aux_totals", [])
|
aux_totals: List[Dict[str, Any]] = hist_ns.get("aux_totals", [])
|
||||||
|
if not isinstance(job_totals, dict):
|
||||||
|
job_totals = dict(BASE_TOTALS)
|
||||||
|
if not isinstance(aux_totals, list):
|
||||||
|
aux_totals = []
|
||||||
totals_list = _create_totals_list(job_totals, aux_totals)
|
totals_list = _create_totals_list(job_totals, aux_totals)
|
||||||
sql_conn = db_provider.connection
|
sql_conn = db_provider.connection
|
||||||
with sql_conn:
|
with sql_conn:
|
||||||
|
@ -139,7 +145,12 @@ class HistorySqlDefinition(SqlTableDefinition):
|
||||||
for batch in db_provider.iter_namespace("history", 1000):
|
for batch in db_provider.iter_namespace("history", 1000):
|
||||||
conv_vals: List[Tuple[Any, ...]] = []
|
conv_vals: List[Tuple[Any, ...]] = []
|
||||||
entry: Dict[str, Any]
|
entry: Dict[str, Any]
|
||||||
for entry in batch.values():
|
for key, entry in batch.items():
|
||||||
|
if not isinstance(entry, dict):
|
||||||
|
logging.info(
|
||||||
|
f"History migration, skipping invalid value: {key} {entry}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
conv_vals.append(
|
conv_vals.append(
|
||||||
(
|
(
|
||||||
|
|
Loading…
Reference in New Issue