lorenwest / node-red-contrib-state

Node-RED shared logical state with persistence, notification, and history
MIT License
7 stars 6 forks source link

How to delete states? #19

Closed youzer-name closed 3 weeks ago

youzer-name commented 3 weeks ago

I've renamed some states and deleted some states, and while the old values are gone from the drop-down lists in the Set State and Get State nodes, the values are still listed when I output the value of global.state[] to a debug node.

The states also still appear in the auto-fill/type-ahead in Node Red. For example, I no longer have "MY_presence" listed in the state drop-downs, but it is auto-filling in the switch node:

image

Is there a way to clear out the unused states?

lorenwest commented 3 weeks ago

Yes all state is stored on disk in the following directory (usually ./shared-state from the working directory of the app)

https://github.com/lorenwest/node-red-contrib-state/blob/61e3964a03d92a0527c7ea353b6f17c8f610e23b/lib/state.js#L78

You can directly edit files in that directory. Probably best to shut down the NodeRED process before making edits to make sure your changes are reflected when you start it back up.

youzer-name commented 3 weeks ago

I only found a file for one of my states there, and it looked like it was out of date. I'm assuming that's because I have all of them set to retain zero items of history, and I might have accidentally had that one set up to retain history at first.

In any case, I had success with using an inject node to trigger a function node with this code:

global.set("state.MY_presence", undefined)

I've used this method before to clean up flow and global variables I had created but no longer needed, and it worked to remove the obsolete states.