Skip to content

Validate that only one program exists per channel - #57

Merged
loevgaard merged 2 commits into
3.xfrom
fix-duplicate-channel-program
Aug 31, 2026
Merged

Validate that only one program exists per channel#57
loevgaard merged 2 commits into
3.xfrom
fix-duplicate-channel-program

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Fixes #52.

What changed

  • UniqueEntity on channel in config/validation/Program.xml (with errorPath: channel, in the plugin's validation group), so creating a second program for the same channel yields a form error on the channel field instead of a database constraint violation (500). English and Danish messages added.
  • Mapping: the channel join column is now explicitly nullable="false" (the form has always required a channel) and keeps its unique constraint; the standalone idx_enabled index on the boolean column is dropped — the only query filters on channel (already unique) and enabled, so it never helped.
  • Tests: new DB-backed ProgramValidationTest (functional suite, skipped without a database) covering the duplicate-channel rejection, a program on another channel being accepted, and the existing duplicate-program-id rule.

Upgrade notes

doctrine:migrations:diff will produce DROP INDEX idx_enabled and ALTER TABLE … CHANGE channel_id channel_id INT NOT NULL. The latter requires that no program row has a NULL channel — which the form has never allowed.

https://claude.ai/code/session_01Mt12J8vdGwwWg4V23uoEf9

The one-to-one mapping already gives the channel a unique constraint,
but without a matching UniqueEntity constraint the admin got a database
error instead of a form error when creating a second program for a
channel. The join column is now also explicitly not null (the form has
always required a channel), and the standalone index on the boolean
enabled column - which no query benefits from - is dropped.

The constraints are covered by a functional test against a real
database.

Fixes #52
Claude-Session: https://claude.ai/code/session_01Mt12J8vdGwwWg4V23uoEf9
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.79%. Comparing base (ec0d5b5) to head (a8bcbf2).

Additional details and impacted files
@@            Coverage Diff            @@
##                3.x      #57   +/-   ##
=========================================
  Coverage     84.79%   84.79%           
  Complexity      104      104           
=========================================
  Files            21       21           
  Lines           546      546           
=========================================
  Hits            463      463           
  Misses           83       83           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The functional-tests CI job loads the Sylius fixtures, which already
contain the en_US locale and the FASHION_WEB channel.

Claude-Session: https://claude.ai/code/session_01Mt12J8vdGwwWg4V23uoEf9
@loevgaard
loevgaard merged commit ed2e023 into 3.x Aug 31, 2026
94 checks passed
@loevgaard
loevgaard deleted the fix-duplicate-channel-program branch August 31, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Second program for the same channel causes a 500 instead of a form error (missing UniqueEntity on channel)

1 participant