refactor(db)!: finalize pooled WNDB v2 migration
This commit is contained in:
@@ -4,6 +4,7 @@ from ..core.database import (
|
||||
ChangeSet,
|
||||
DatabaseCommand,
|
||||
execute_command,
|
||||
execute_locked_command,
|
||||
g_add_prefix,
|
||||
g_delete_prefix,
|
||||
g_update_prefix,
|
||||
@@ -94,8 +95,12 @@ class Valve(object):
|
||||
def as_dict(self) -> dict[str, Any]:
|
||||
return { 'type': self.type, 'id': self.id, 'node1': self.node1, 'node2': self.node2, 'diameter': self.diameter, 'v_type': self.v_type, 'setting': self.setting, 'minor_loss': self.minor_loss }
|
||||
|
||||
def _set_valve(name: str, cs: ChangeSet) -> DatabaseCommand:
|
||||
raw_new = get_valve(name, cs.operations[0]['id'])
|
||||
def _set_valve(
|
||||
name: str,
|
||||
cs: ChangeSet,
|
||||
current: dict[str, Any] | None = None,
|
||||
) -> DatabaseCommand:
|
||||
raw_new = current if current is not None else get_valve(name, cs.operations[0]['id'])
|
||||
|
||||
new_dict = cs.operations[0]
|
||||
schema = get_valve_schema(name)
|
||||
@@ -112,11 +117,15 @@ def _set_valve(name: str, cs: ChangeSet) -> DatabaseCommand:
|
||||
|
||||
|
||||
def set_valve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
operation = cs.operations[0]
|
||||
if 'id' not in operation:
|
||||
return ChangeSet()
|
||||
if get_valve(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, _set_valve(name, cs))
|
||||
|
||||
def build_command() -> DatabaseCommand | None:
|
||||
current = get_valve(name, operation['id'])
|
||||
return None if current == {} else _set_valve(name, cs, current)
|
||||
|
||||
return execute_locked_command(name, build_command)
|
||||
|
||||
|
||||
def _add_valve(name: str, cs: ChangeSet) -> DatabaseCommand:
|
||||
|
||||
Reference in New Issue
Block a user