How to add a new field in 8.3 and propagate default value in existing records?

I'm trying to add a new boolean field to a device config record. I'd like this field to have a default value of true for existing devices. When creating a new device, I'm not passing the device config record as a parameter, I'm passing an interface, which I've made my record implement, so I'm grabbing the value using a method like

boolean isEnabled() {

return category.newfield

}

If I'm creating a new device with this field, the new record gets created with newfield, there's no problem. Surprisingly, this returns a false for existing records, which makes a kind of sense, newfield doesn't exist in that record. Is there a way for me to detect whether newfield exists on an existing record without diving into the resource folder? For example, if I wanted to add a new column in a PersistentRecord in 8.1, I think I just needed to define the field with a default and that was it.

ExtensionPoints have a getSettingsUpgrader() method on them you could use for this.

e.g.

public record WidgetConfig(String name, int width, boolean enabled) {

    /**
     * Upgrade a WidgetConfig JSON object: existing records that predate the
     * "enabled" field should default to true.
     */
    public static JsonElement upgrade(JsonElement configJson) {
        if (configJson instanceof JsonObject obj && !obj.has("enabled")) {
            obj.addProperty("enabled", true);
        }
        return configJson;
    }
}

and in the ExtensionPoint:

@Override
public Optional<JsonSettingsUpgrader> getSettingsUpgrader() {
    return Optional.of(WidgetConfig::upgrade);
}

Keep the upgrade method idempotent since it runs on every load; introduce a configVersion field or something once the upgrade logic gets complex enough that idempotency is hard to guarantee.