Migrate the last segment rule/condition readers onto Segment.rules_data, stop writing rows, then retire the models.
Scope
- Change the release-pipeline percentage read in
features/release_pipelines/core/models.py from rollout_segment.rules.first().conditions.first() to the equivalent value in rules_data.
- Update the org import/export entity configuration in
import_export/export.py to stop exporting SegmentRule and Condition as separate entities; the Segment.rules_data field carries them on round-trip.
- Make
set_segment_rules stop writing rule and condition rows, and remove the row-writing code — no reader needs rows now.
- Remove the unused models and surrounding code:
SegmentRule
Condition
- their
Historical* records
RulesInline / ConditionsInline admin
SegmentRuleAdmin
ConfiguredOrderManager
SegmentRuleManager / SegmentConditionManager
SEGMENT_RULES_EXPLICIT_ORDERING_ENABLED / SEGMENT_CONDITIONS_EXPLICIT_ORDERING_ENABLED settings
SegmentRuleTypeEnum entry in the drf-spectacular ENUM_NAME_OVERRIDES setting that points at SegmentRule.RULE_TYPES — use flag_engine RuleType instead.
- Add a final migration that retires the models from Django state with
SeparateDatabaseAndState and truncates the rule, condition, and history tables. We never drop tables, so the physical tables remain, empty.
Acceptance criteria (write as tests first)
- After this change, creating or updating a segment writes no
SegmentRule or Condition rows.
- The release-pipeline phased-rollout percentage is read correctly from
rules_data for flat and nested segments.
- An organisation export then import reproduces segments with identical rules, with no reference to the retired entities.
- The codebase has no references to
SegmentRule or Condition outside the retiring migration.
- The migration removes the models from Django state and truncates
segments_segmentrule, segments_condition, and their history tables, leaving the tables in place.
- Admin loads without the removed inlines; the OpenAPI schema generates without the
ENUM_NAME_OVERRIDES reference to SegmentRule.RULE_TYPES.
- The ordering settings are gone and no test depends on them.
Migrate the last segment rule/condition readers onto
Segment.rules_data, stop writing rows, then retire the models.Scope
features/release_pipelines/core/models.pyfromrollout_segment.rules.first().conditions.first()to the equivalent value inrules_data.import_export/export.pyto stop exportingSegmentRuleandConditionas separate entities; theSegment.rules_datafield carries them on round-trip.set_segment_rulesstop writing rule and condition rows, and remove the row-writing code — no reader needs rows now.SegmentRuleConditionHistorical*recordsRulesInline/ConditionsInlineadminSegmentRuleAdminConfiguredOrderManagerSegmentRuleManager/SegmentConditionManagerSEGMENT_RULES_EXPLICIT_ORDERING_ENABLED/SEGMENT_CONDITIONS_EXPLICIT_ORDERING_ENABLEDsettingsSegmentRuleTypeEnumentry in the drf-spectacularENUM_NAME_OVERRIDESsetting that points atSegmentRule.RULE_TYPES— useflag_engineRuleTypeinstead.SeparateDatabaseAndStateand truncates the rule, condition, and history tables. We never drop tables, so the physical tables remain, empty.Acceptance criteria (write as tests first)
SegmentRuleorConditionrows.rules_datafor flat and nested segments.SegmentRuleorConditionoutside the retiring migration.segments_segmentrule,segments_condition, and their history tables, leaving the tables in place.ENUM_NAME_OVERRIDESreference toSegmentRule.RULE_TYPES.