loader: equipment is driver-less (drop Modbus placeholder, NULL DriverInstanceId)
This commit is contained in:
@@ -83,12 +83,6 @@ LOAD_PLAN = os.path.join(os.path.dirname(__file__), "load-plan.json")
|
|||||||
# overlay carries live VALUES (scope doc WS-3), not just structure.
|
# overlay carries live VALUES (scope doc WS-3), not just structure.
|
||||||
EQ_CLUSTER = os.environ.get("OTOPCUA_EQ_CLUSTER", "MAIN")
|
EQ_CLUSTER = os.environ.get("OTOPCUA_EQ_CLUSTER", "MAIN")
|
||||||
EQ_NS = "nw-uns"
|
EQ_NS = "nw-uns"
|
||||||
# A placeholder non-Galaxy driver kept ONLY to satisfy "an Equipment namespace has a
|
|
||||||
# driver" expectations; it streams nothing and no Tag binds to it (the company signals
|
|
||||||
# are VirtualTags, which need no driver — they link to Equipment + a Script). Its
|
|
||||||
# DriverType is non-GalaxyMxGateway so DraftValidator.ValidateDriverNamespaceCompatibility
|
|
||||||
# accepts it in the Equipment-kind namespace.
|
|
||||||
EQ_DRIVER = "nw-uns-modbus"
|
|
||||||
EQ_ID_PREFIX = "nweq-" # VirtualTag/Script logical-id prefix (cleanup by prefix scan)
|
EQ_ID_PREFIX = "nweq-" # VirtualTag/Script logical-id prefix (cleanup by prefix scan)
|
||||||
|
|
||||||
# galaxy dataTypeName / gen_uns dtype → valid OtOpcUa DriverDataType
|
# galaxy dataTypeName / gen_uns dtype → valid OtOpcUa DriverDataType
|
||||||
@@ -252,30 +246,20 @@ def cmd_populate_equipment(args):
|
|||||||
conn, cur = connect(args.mssql)
|
conn, cur = connect(args.mssql)
|
||||||
|
|
||||||
# Drop any prior overlay (child rows first), then recreate. VirtualTag/Script go
|
# Drop any prior overlay (child rows first), then recreate. VirtualTag/Script go
|
||||||
# before Equipment (VirtualTag.EquipmentId logical-FKs Equipment); the stub driver
|
# before Equipment (VirtualTag.EquipmentId logical-FKs Equipment). Equipment is
|
||||||
# keeps no Tags so the Tag delete is just defensive for older overlays. Equipment is
|
|
||||||
# scoped by its overlay UnsLine ('nw-line-%') — NOT by the EquipmentId, which is now the
|
# scoped by its overlay UnsLine ('nw-line-%') — NOT by the EquipmentId, which is now the
|
||||||
# canonical 'EQ-'+uuid form (see DraftValidator) and no longer carries an 'nw-' prefix.
|
# canonical 'EQ-'+uuid form (see DraftValidator) and no longer carries an 'nw-' prefix.
|
||||||
cur.execute("DELETE FROM dbo.VirtualTag WHERE VirtualTagId LIKE %s", (EQ_ID_PREFIX + "%",))
|
cur.execute("DELETE FROM dbo.VirtualTag WHERE VirtualTagId LIKE %s", (EQ_ID_PREFIX + "%",))
|
||||||
cur.execute("DELETE FROM dbo.Script WHERE ScriptId LIKE %s", (EQ_ID_PREFIX + "%",))
|
cur.execute("DELETE FROM dbo.Script WHERE ScriptId LIKE %s", (EQ_ID_PREFIX + "%",))
|
||||||
cur.execute("DELETE FROM dbo.Tag WHERE DriverInstanceId=%s", (EQ_DRIVER,))
|
|
||||||
cur.execute("DELETE FROM dbo.Equipment WHERE UnsLineId LIKE 'nw-line-%'")
|
cur.execute("DELETE FROM dbo.Equipment WHERE UnsLineId LIKE 'nw-line-%'")
|
||||||
cur.execute("DELETE FROM dbo.UnsLine WHERE UnsLineId LIKE 'nw-line-%'")
|
cur.execute("DELETE FROM dbo.UnsLine WHERE UnsLineId LIKE 'nw-line-%'")
|
||||||
cur.execute("DELETE FROM dbo.UnsArea WHERE UnsAreaId LIKE 'nw-area-%'")
|
cur.execute("DELETE FROM dbo.UnsArea WHERE UnsAreaId LIKE 'nw-area-%'")
|
||||||
cur.execute("DELETE FROM dbo.DriverInstance WHERE DriverInstanceId=%s", (EQ_DRIVER,))
|
|
||||||
cur.execute("DELETE FROM dbo.Namespace WHERE NamespaceId=%s", (EQ_NS,))
|
cur.execute("DELETE FROM dbo.Namespace WHERE NamespaceId=%s", (EQ_NS,))
|
||||||
|
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO dbo.Namespace (NamespaceRowId, NamespaceId, ClusterId, Kind, NamespaceUri, Enabled) "
|
"INSERT INTO dbo.Namespace (NamespaceRowId, NamespaceId, ClusterId, Kind, NamespaceUri, Enabled) "
|
||||||
"VALUES (NEWID(), %s, %s, 'Equipment', %s, 1)",
|
"VALUES (NEWID(), %s, %s, 'Equipment', %s, 1)",
|
||||||
(EQ_NS, EQ_CLUSTER, doc.get("namespace", {}).get("namespaceUri", "urn:northwind:birmingham:uns")))
|
(EQ_NS, EQ_CLUSTER, doc.get("namespace", {}).get("namespaceUri", "urn:northwind:birmingham:uns")))
|
||||||
# Placeholder driver kept only to satisfy "Equipment namespace has a driver"; NO Tag
|
|
||||||
# binds to it — the company signals are VirtualTags (driverless). DriverType must be
|
|
||||||
# non-GalaxyMxGateway for DraftValidator to accept it in an Equipment-kind namespace.
|
|
||||||
cur.execute(
|
|
||||||
"INSERT INTO dbo.DriverInstance (DriverInstanceRowId, DriverInstanceId, ClusterId, NamespaceId, "
|
|
||||||
"Name, DriverType, Enabled, DriverConfig) VALUES (NEWID(), %s, %s, %s, 'Northwind UNS placeholder', 'Modbus', 1, '{}')",
|
|
||||||
(EQ_DRIVER, EQ_CLUSTER, EQ_NS))
|
|
||||||
|
|
||||||
for a in u["unsAreas"]:
|
for a in u["unsAreas"]:
|
||||||
cur.execute("INSERT INTO dbo.UnsArea (UnsAreaRowId, UnsAreaId, ClusterId, Name) VALUES (NEWID(), %s, %s, %s)",
|
cur.execute("INSERT INTO dbo.UnsArea (UnsAreaRowId, UnsAreaId, ClusterId, Name) VALUES (NEWID(), %s, %s, %s)",
|
||||||
@@ -293,9 +277,9 @@ def cmd_populate_equipment(args):
|
|||||||
eq_id = "EQ-" + eq_uuid.hex[:12].lower()
|
eq_id = "EQ-" + eq_uuid.hex[:12].lower()
|
||||||
eq_uuid = str(eq_uuid)
|
eq_uuid = str(eq_uuid)
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO dbo.Equipment (EquipmentRowId, EquipmentId, EquipmentUuid, DriverInstanceId, UnsLineId, "
|
"INSERT INTO dbo.Equipment (EquipmentRowId, EquipmentId, EquipmentUuid, UnsLineId, "
|
||||||
"Name, MachineCode, Manufacturer, Model, Enabled) VALUES (NEWID(), %s, %s, %s, %s, %s, %s, %s, %s, 1)",
|
"Name, MachineCode, Manufacturer, Model, Enabled) VALUES (NEWID(), %s, %s, %s, %s, %s, %s, %s, 1)",
|
||||||
(eq_id, eq_uuid, EQ_DRIVER, "nw-" + e["unsLineId"], e["name"], e["machineCode"],
|
(eq_id, eq_uuid, "nw-" + e["unsLineId"], e["name"], e["machineCode"],
|
||||||
e.get("manufacturer"), e.get("model")))
|
e.get("manufacturer"), e.get("model")))
|
||||||
eq_n += 1
|
eq_n += 1
|
||||||
for t in e["tags"]:
|
for t in e["tags"]:
|
||||||
@@ -336,16 +320,14 @@ def cmd_clean(args):
|
|||||||
cur.execute("DELETE FROM dbo.Tag WHERE TagId LIKE %s", (ID_PREFIX + "%",))
|
cur.execute("DELETE FROM dbo.Tag WHERE TagId LIKE %s", (ID_PREFIX + "%",))
|
||||||
n = cur.rowcount
|
n = cur.rowcount
|
||||||
# Also drop the company-shape Equipment overlay (child rows first): VirtualTag and
|
# Also drop the company-shape Equipment overlay (child rows first): VirtualTag and
|
||||||
# Script (both nweq-*) before Equipment, then any stub-driver Tag, then the rest.
|
# Script (both nweq-*) before Equipment, then the rest.
|
||||||
# Equipment is scoped by its overlay UnsLine ('nw-line-%') — NOT by the EquipmentId,
|
# Equipment is scoped by its overlay UnsLine ('nw-line-%') — NOT by the EquipmentId,
|
||||||
# which is now the canonical 'EQ-'+uuid form (see DraftValidator) with no 'nw-' prefix.
|
# which is now the canonical 'EQ-'+uuid form (see DraftValidator) with no 'nw-' prefix.
|
||||||
cur.execute("DELETE FROM dbo.VirtualTag WHERE VirtualTagId LIKE %s", (EQ_ID_PREFIX + "%",))
|
cur.execute("DELETE FROM dbo.VirtualTag WHERE VirtualTagId LIKE %s", (EQ_ID_PREFIX + "%",))
|
||||||
cur.execute("DELETE FROM dbo.Script WHERE ScriptId LIKE %s", (EQ_ID_PREFIX + "%",))
|
cur.execute("DELETE FROM dbo.Script WHERE ScriptId LIKE %s", (EQ_ID_PREFIX + "%",))
|
||||||
cur.execute("DELETE FROM dbo.Tag WHERE DriverInstanceId=%s", (EQ_DRIVER,))
|
|
||||||
cur.execute("DELETE FROM dbo.Equipment WHERE UnsLineId LIKE 'nw-line-%'")
|
cur.execute("DELETE FROM dbo.Equipment WHERE UnsLineId LIKE 'nw-line-%'")
|
||||||
cur.execute("DELETE FROM dbo.UnsLine WHERE UnsLineId LIKE 'nw-line-%'")
|
cur.execute("DELETE FROM dbo.UnsLine WHERE UnsLineId LIKE 'nw-line-%'")
|
||||||
cur.execute("DELETE FROM dbo.UnsArea WHERE UnsAreaId LIKE 'nw-area-%'")
|
cur.execute("DELETE FROM dbo.UnsArea WHERE UnsAreaId LIKE 'nw-area-%'")
|
||||||
cur.execute("DELETE FROM dbo.DriverInstance WHERE DriverInstanceId=%s", (EQ_DRIVER,))
|
|
||||||
cur.execute("DELETE FROM dbo.Namespace WHERE NamespaceId=%s", (EQ_NS,))
|
cur.execute("DELETE FROM dbo.Namespace WHERE NamespaceId=%s", (EQ_NS,))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user