refactor(db)!: finalize pooled WNDB v2 migration

This commit is contained in:
2026-08-27 17:26:22 +08:00
parent fa188af0b1
commit b74799a39d
105 changed files with 4988 additions and 5565 deletions
+15 -6
View File
@@ -4,6 +4,7 @@ from ..core.database import (
ChangeSet,
DatabaseCommand,
execute_command,
execute_locked_command,
g_add_prefix,
g_delete_prefix,
g_update_prefix,
@@ -87,8 +88,12 @@ class Pump(object):
def as_dict(self) -> dict[str, Any]:
return { 'type': self.type, 'id': self.id, 'node1': self.node1, 'node2': self.node2, 'power': self.power, 'head': self.head, 'speed': self.speed, 'pattern': self.pattern }
def _set_pump(name: str, cs: ChangeSet) -> DatabaseCommand:
raw_new = get_pump(name, cs.operations[0]['id'])
def _set_pump(
name: str,
cs: ChangeSet,
current: dict[str, Any] | None = None,
) -> DatabaseCommand:
raw_new = current if current is not None else get_pump(name, cs.operations[0]['id'])
new_dict = cs.operations[0]
schema = get_pump_schema(name)
@@ -105,11 +110,15 @@ def _set_pump(name: str, cs: ChangeSet) -> DatabaseCommand:
def set_pump(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_pump(name, cs.operations[0]['id']) == {}:
return ChangeSet()
return execute_command(name, _set_pump(name, cs))
def build_command() -> DatabaseCommand | None:
current = get_pump(name, operation['id'])
return None if current == {} else _set_pump(name, cs, current)
return execute_locked_command(name, build_command)
def _add_pump(name: str, cs: ChangeSet) -> DatabaseCommand: