fix(scada): align native device writes
This commit is contained in:
@@ -136,18 +136,20 @@ def execute_undo(name: str, discard: bool = False) -> ChangeSet:
|
||||
|
||||
write(name, row['undo'])
|
||||
|
||||
parent = row['parent'] if row['parent'] != None else 0
|
||||
|
||||
# update foreign key
|
||||
write(name, f"update current_operation set id = {row['parent']} where id = {row['id']}")
|
||||
write(name, f"update current_operation set id = {parent} where id = {row['id']}")
|
||||
|
||||
if discard:
|
||||
# update foreign key
|
||||
write(name, f"update operation set redo_child = null where id = {row['parent']}")
|
||||
write(name, f"update operation set redo_child = null where id = {parent}")
|
||||
# on delete cascade => child & snapshot
|
||||
write(name, f"delete from operation where id = {row['id']}")
|
||||
else:
|
||||
write(name, f"update operation set redo_child = {row['id']} where id = {row['parent']}")
|
||||
write(name, f"update operation set redo_child = {row['id']} where id = {parent}")
|
||||
|
||||
e = eval(row['undo_cs'])
|
||||
e = eval(row['undo_cs']) if row['undo_cs'] not in [None, ''] else []
|
||||
return ChangeSet.from_list(e)
|
||||
|
||||
|
||||
@@ -159,9 +161,10 @@ def execute_redo(name: str) -> ChangeSet:
|
||||
row = read(name, f"select * from operation where id = {row['redo_child']}")
|
||||
write(name, row['redo'])
|
||||
|
||||
write(name, f"update current_operation set id = {row['id']} where id = {row['parent']}")
|
||||
parent = row['parent'] if row['parent'] != None else 0
|
||||
write(name, f"update current_operation set id = {row['id']} where id = {parent}")
|
||||
|
||||
e = eval(row['redo_cs'])
|
||||
e = eval(row['redo_cs']) if row['redo_cs'] not in [None, ''] else []
|
||||
return ChangeSet.from_list(e)
|
||||
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ def _set_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if get_scada_device(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, _set_scada_device(name, cs), False)
|
||||
return execute_command(name, _set_scada_device(name, cs))
|
||||
|
||||
|
||||
def _add_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
@@ -90,7 +90,7 @@ def _add_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def add_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if get_scada_device(name, cs.operations[0]['id']) != {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, _add_scada_device(name, cs), False)
|
||||
return execute_command(name, _add_scada_device(name, cs))
|
||||
|
||||
|
||||
def _delete_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
@@ -108,7 +108,7 @@ def _delete_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def delete_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if get_scada_device(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, _delete_scada_device(name, cs), False)
|
||||
return execute_command(name, _delete_scada_device(name, cs))
|
||||
|
||||
|
||||
def get_all_scada_device_ids(name: str) -> list[str]:
|
||||
|
||||
@@ -45,7 +45,7 @@ def _set_scada_device_data(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_scada_device_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, _set_scada_device_data(name, cs), False)
|
||||
return execute_command(name, _set_scada_device_data(name, cs))
|
||||
|
||||
|
||||
def _add_scada_device_data(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
@@ -66,7 +66,7 @@ def add_scada_device_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
row = try_read(name, f"select * from scada_device_data where device_id = '{cs.operations[0]['device_id']}' and time = '{cs.operations[0]['time']}'")
|
||||
if row != None:
|
||||
return ChangeSet()
|
||||
return execute_command(name, _add_scada_device_data(name, cs), False)
|
||||
return execute_command(name, _add_scada_device_data(name, cs))
|
||||
|
||||
|
||||
def _delete_scada_device_data(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
@@ -87,4 +87,4 @@ def delete_scada_device_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
row = try_read(name, f"select * from scada_device_data where device_id = '{cs.operations[0]['device_id']}' and time = '{cs.operations[0]['time']}'")
|
||||
if row == None:
|
||||
return ChangeSet()
|
||||
return execute_command(name, _delete_scada_device_data(name, cs), False)
|
||||
return execute_command(name, _delete_scada_device_data(name, cs))
|
||||
|
||||
Reference in New Issue
Block a user