diff --git a/docker-dev/seed/seed-clusters.sql b/docker-dev/seed/seed-clusters.sql index ce15c214..a4ce9d7e 100644 --- a/docker-dev/seed/seed-clusters.sql +++ b/docker-dev/seed/seed-clusters.sql @@ -157,23 +157,35 @@ IF NOT EXISTS (SELECT 1 FROM dbo.DriverInstance WHERE DriverInstanceId = 'MAIN-g -- Name to address the MXAccess item. The Galaxy driver subscribes via the -- "FolderPath.Name" MXAccess reference form; OPC UA browse path is the -- equivalent "FolderPath/Name" under the SystemPlatform namespace. +-- +-- Idempotency: each insert is guarded on the UX_Tag_FolderPath key +-- (DriverInstanceId, FolderPath, Name WHERE EquipmentId IS NULL), NOT TagId. +-- The Galaxy driver auto-materialises these same folder-path tags at runtime +-- under its own generated TagIds, so a TagId-only guard would pass on a re-run +-- and then collide on UX_Tag_FolderPath, making cluster-seed exit 1. ------------------------------------------------------------------------------ -IF NOT EXISTS (SELECT 1 FROM dbo.Tag WHERE TagId = 'MAIN-galaxy-TestMachine_001-TestAlarm001') +IF NOT EXISTS (SELECT 1 FROM dbo.Tag + WHERE DriverInstanceId = 'MAIN-galaxy-mxgw' AND FolderPath = 'TestMachine_001' + AND Name = 'TestAlarm001' AND EquipmentId IS NULL) INSERT INTO dbo.Tag (TagRowId, TagId, DriverInstanceId, DeviceId, EquipmentId, Name, FolderPath, DataType, AccessLevel, WriteIdempotent, PollGroupId, TagConfig) VALUES (NEWID(), 'MAIN-galaxy-TestMachine_001-TestAlarm001', 'MAIN-galaxy-mxgw', NULL, NULL, 'TestAlarm001', 'TestMachine_001', 'Boolean', 0, 0, NULL, N'{}'); -IF NOT EXISTS (SELECT 1 FROM dbo.Tag WHERE TagId = 'MAIN-galaxy-TestMachine_001-TestAlarm002') +IF NOT EXISTS (SELECT 1 FROM dbo.Tag + WHERE DriverInstanceId = 'MAIN-galaxy-mxgw' AND FolderPath = 'TestMachine_001' + AND Name = 'TestAlarm002' AND EquipmentId IS NULL) INSERT INTO dbo.Tag (TagRowId, TagId, DriverInstanceId, DeviceId, EquipmentId, Name, FolderPath, DataType, AccessLevel, WriteIdempotent, PollGroupId, TagConfig) VALUES (NEWID(), 'MAIN-galaxy-TestMachine_001-TestAlarm002', 'MAIN-galaxy-mxgw', NULL, NULL, 'TestAlarm002', 'TestMachine_001', 'Boolean', 0, 0, NULL, N'{}'); -IF NOT EXISTS (SELECT 1 FROM dbo.Tag WHERE TagId = 'MAIN-galaxy-TestMachine_001-TestAlarm003') +IF NOT EXISTS (SELECT 1 FROM dbo.Tag + WHERE DriverInstanceId = 'MAIN-galaxy-mxgw' AND FolderPath = 'TestMachine_001' + AND Name = 'TestAlarm003' AND EquipmentId IS NULL) INSERT INTO dbo.Tag (TagRowId, TagId, DriverInstanceId, DeviceId, EquipmentId, Name, FolderPath, DataType, AccessLevel, WriteIdempotent, PollGroupId, TagConfig) VALUES