Skip to content

Migrating Data

Flynn Duniho edited this page May 30, 2024 · 5 revisions

Migrating Data

See PR #285

server-database.js will now "migrate" graph data as it opens the project file. It uses parameters defined in the template to determine if migration is necessary and can automatically define missing fields and set default values. It currently does not do more sophisticated migration (e.g. change a property from one name to another), but these can be easily added.

Currently this is primarily being used to add the "Weight" to any project that has "Weight" defined as set as "isRequired" and has a defaultValue defined.

The basic check is this:
1. If the TEMPLATE property `isRequired`
2. ...and the TEMPLATE propert has `defaultValue` defined
2. ...and the node/edge property is currently undefined or ``
3. ...then we set the property to the defaultValue

The key parameters:
  `property.isRequired`
  `property.defaultValue`

If `isRequired` or `defaultValue` is not defined on the property, we skip migration..

You can use this technique to auto-populate data on a project. Just add isRequired and defaultValue to the projects' *.template.toml file. e.g. this will set all node types to Person if the node type was not previously set when the project is opened:

[nodeDefs.type]
...
isRequired = true
defaultValue = "Person"

[[nodeDefs.type.options]]
color = "#eeeeee"
label = ""
[[nodeDefs.type.options]]
color = "#ff0000"
label = "Person"

NOTES:

  • the migration does NOT save the changes until you do something to modify the database and trigger an autosave.
  • if you modify the project template file, you need to reload the project to trigger migration -- a dev hot-reload will not do it.
Clone this wiki locally