refactor(db)!: finalize pooled WNDB v2 migration
This commit is contained in:
@@ -6,6 +6,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 Junction(object):
|
||||
def as_dict(self) -> dict[str, Any]:
|
||||
return { 'type': self.type, 'id': self.id, 'x': self.x, 'y': self.y, 'elevation': self.elevation }
|
||||
|
||||
def _set_junction(name: str, cs: ChangeSet) -> DatabaseCommand:
|
||||
raw_new = get_junction(name, cs.operations[0]['id'])
|
||||
def _set_junction(
|
||||
name: str,
|
||||
cs: ChangeSet,
|
||||
current: dict[str, Any] | None = None,
|
||||
) -> DatabaseCommand:
|
||||
raw_new = current if current is not None else get_junction(name, cs.operations[0]['id'])
|
||||
|
||||
new_dict = cs.operations[0]
|
||||
schema = get_junction_schema(name)
|
||||
@@ -113,11 +118,15 @@ def _set_junction(name: str, cs: ChangeSet) -> DatabaseCommand:
|
||||
|
||||
|
||||
def set_junction(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_junction(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, _set_junction(name, cs))
|
||||
|
||||
def build_command() -> DatabaseCommand | None:
|
||||
current = get_junction(name, operation['id'])
|
||||
return None if current == {} else _set_junction(name, cs, current)
|
||||
|
||||
return execute_locked_command(name, build_command)
|
||||
|
||||
|
||||
def _add_junction(name: str, cs: ChangeSet) -> DatabaseCommand:
|
||||
|
||||
Reference in New Issue
Block a user