flagsmith icon indicating copy to clipboard operation
flagsmith copied to clipboard

Spike: Investigate simplifying Segment diffing

Open khvn26 opened this issue 7 months ago • 2 comments

Currently, we store segment rules (including sub-rules) and conditions in separate tables, which makes validation / versioning code unnecessarily complex.

We need to investigate the following:

  • Versioning requirements for the individual rules are currently unclear. We'd like to go over the current approach, informed by FE need to know about specific rule/condition versions, and re-evaluate whether it's more correct, effective, and user-friendly to harness simple text-based diffs instead.
  • As a nice side effect, removal of SegmentCondition and SegmentRule models in favour of storing the whole segment data in a JSONField in the Segment model.

This spike should result in a PoC to give us an idea whether the change is feasible and/or beneficial in the long run.

Considerations:

  • We'd like to have the data in Edge API / engine compatible format.
  • This will require a data migration.

khvn26 avatar Jul 29 '25 13:07 khvn26

As an update, since this discussion we're already pursuing some of the goals described in this issue:

  • We've dismissed adding version_of to rules and conditions (https://github.com/Flagsmith/flagsmith/issues/5770), and made PKs irrelevant in API communication when rewriting segment serializers (https://github.com/Flagsmith/flagsmith/issues/5769).
  • On the frontend, there is relevant work in progress by @kyle-ssg: feat/segment-change-requests-simplified-diff.

We're prioritizing delivering segment change requests now, and will improve the data model towards a JSON approach later.

emyller avatar Aug 08 '25 13:08 emyller

Thanks @kyle-ssg! I'll reopen this issue because I think we still need to simplify things on the data model side, as per the description:

As a nice side effect, removal of SegmentCondition and SegmentRule models in favour of storing the whole segment data in a JSONField in the Segment model.

We'll discuss it (cc @khvn26) and perhaps move onto a separate issue then.

emyller avatar Sep 30 '25 13:09 emyller