Skip to content

Update migration script to transform device metrics to nested format #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025

Conversation

AlexGodbehere
Copy link
Contributor

@AlexGodbehere AlexGodbehere commented May 7, 2025

This PR updates the migration script in acs-service-setup/lib/manager-devices.js to transform device metrics from the old flat array format to the new nested object structure required by the OriginMapEditor component in the admin interface.

Changes Made

  • Added a new transformOriginMap() function that converts the flat array of metrics into a nested object structure
  • Implemented field name mapping from lowercase to Title_Case_With_Underscores format
  • Added special handling for Schema_UUID and Instance_UUID at both root and nested levels
  • Ensured proper handling of value properties in the nested structure
  • Added debugging logs to track the transformation process

Before

Previously, the migration script would create device configurations with a flat array of metrics:

{
  "originMap": [
    {
      "Name": "Double/Sine/Schema_UUID",
      "docs": "A reference to the schema used for this object.",
      "type": "UUID",
      "value": "9cb27c21-3b99-4c3f-95b5-bb77e92f0351",
      "method": "GET",
      "recordToDB": true
    },
    {
      "Name": "Double/Sine/Value",
      "docs": "",
      "path": "0",
      "type": "DoubleLE",
      "method": "GET",
      "address": "sin:10000:30:ld",
      "recordToDB": true
    }
  ]
}

After

Now, the script creates device configurations with a nested object structure:

{
  "originMap": {
    "Double": {
      "Sine": {
        "Value": {
          "Path": "0",
          "Method": "GET",
          "Address": "sin:10000:30:ld",
          "Documentation": "",
          "Sparkplug_Type": "DoubleLE",
          "Record_To_Historian": true
        },
        "Schema_UUID": "9cb27c21-3b99-4c3f-95b5-bb77e92f0351"
      }
    },
    "Schema_UUID": "214b7fe8-6a92-4743-b782-4230458ccdde"
  }
}

- Add transformOriginMap function to convert flat array of metrics to nested object structure
- Implement field name mapping from lowercase to Title_Case_With_Underscores format
- Add special handling for Schema_UUID and Instance_UUID at both root and nested levels
- Ensure proper handling of value properties in the nested structure
- Add debugging logs to track the transformation process
@AlexGodbehere AlexGodbehere force-pushed the fix-device-migration branch from aee2760 to 184d1f1 Compare May 7, 2025 08:49
@AlexGodbehere AlexGodbehere merged commit 34a6bc3 into main May 7, 2025
1 check passed
@AlexGodbehere AlexGodbehere deleted the fix-device-migration branch May 7, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant