Skip to content

Stop using the SegmentRule and Condition models #7818

@khvn26

Description

@khvn26

Migrate the last segment rule/condition readers onto Segment.rules_data, stop writing rows, then retire the models.

Scope

  1. 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.
  2. 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.
  3. Make set_segment_rules stop writing rule and condition rows, and remove the row-writing code — no reader needs rows now.
  4. 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.
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiIssue related to the REST API

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions