Supersedes #6946.
Migrate off the SegmentRule and Condition tables to a single JSON field on Segment. The goal is to simplify all segment writes, streamline segment versioning, and make segment reads lighter, and more correct.
Segment rules and conditions are stored today across two tables joined by foreign keys: SegmentRule, with a self-FK for nesting and an FK to Segment, and Condition, FK to SegmentRule. Every read for evaluation reconstructs this tree through a three-level prefetch_related chain. Living with it showed that there's no value in having these relations stored, and maintaining them bears burden on all code paths interacting with segments. We want to store segment rule data as readily available JSON.
We add a JSON field Segment.rules_data holding the list of top-level rules in the API-compatible shape:
[
{
"type": "ALL",
"conditions": [],
"rules": [
{
"type": "ANY",
"conditions": [
{
"operator": "EQUAL",
"property": "country",
"value": "UK",
"description": null
}
],
"rules": []
}
]
}
]
After that, we gradually migrate all segment read paths to read from it, and retire the existing models.
Supersedes #6946.
Migrate off the
SegmentRuleandConditiontables to a single JSON field onSegment. The goal is to simplify all segment writes, streamline segment versioning, and make segment reads lighter, and more correct.Segment rules and conditions are stored today across two tables joined by foreign keys:
SegmentRule, with a self-FK for nesting and an FK toSegment, andCondition, FK toSegmentRule. Every read for evaluation reconstructs this tree through a three-levelprefetch_relatedchain. Living with it showed that there's no value in having these relations stored, and maintaining them bears burden on all code paths interacting with segments. We want to store segment rule data as readily available JSON.We add a JSON field
Segment.rules_dataholding the list of top-level rules in the API-compatible shape:[ { "type": "ALL", "conditions": [], "rules": [ { "type": "ANY", "conditions": [ { "operator": "EQUAL", "property": "country", "value": "UK", "description": null } ], "rules": [] } ] } ]After that, we gradually migrate all segment read paths to read from it, and retire the existing models.