Skip to content

🐛 Make LoadReservedNameData fixture idempotent#1295

Open
t2d wants to merge 1 commit into
mainfrom
fix/reserved-name-fixture-idempotent
Open

🐛 Make LoadReservedNameData fixture idempotent#1295
t2d wants to merge 1 commit into
mainfrom
fix/reserved-name-fixture-idempotent

Conversation

@t2d

@t2d t2d commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

make fixtures fails on any migrated database:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'postmaster' for key 'UNIQ_E40F23B05E237E06'

Migration Version20260418120000 ("Migrate postmaster aliases to settings and ensure reserved names exist") seeds the postmaster and abuse reserved names. LoadReservedNameData (group basic) inserts admin, root, postmaster, abuse, webmaster. Since make fixtures loads with --append (no purge), the overlapping names collide → duplicate-key crash.

Fix

LoadReservedNameData::load now skips names already present before persisting, keeping the fixture idempotent under --append.

Verification

  • doctrine:fixtures:load --group=basic --append succeeds against a DB already seeded by the migration
  • reserved_names ends with exactly one row per name (admin, root, postmaster, abuse, webmaster)
  • composer cs-fix (no changes), composer psalm (no errors), composer rector-check (OK)

Found while setting up local env for #1293; unrelated to that change.

🤖 Generated with Claude Code

Migration Version20260418120000 seeds the `postmaster` and `abuse`
reserved names. The basic fixtures (loaded with --append by `make
fixtures`) re-insert the same names, causing a duplicate-key violation on
`reserved_names` and breaking local environment setup on any migrated DB.

Skip reserved names that already exist before persisting.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@t2d t2d marked this pull request as ready for review June 11, 2026 04:27
@sonarqubecloud

Copy link
Copy Markdown

@0x46616c6b

Copy link
Copy Markdown
Member

Fixtures must not be idempotent. The idea is to prefill the system with a fixed set of data. If you need to reapply, you need to purge the database and start fresh.

@t2d

t2d commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

The docs say I should do

make dev
....
Started container environment.
Services:
  Userli:      http://localhost:8000
  Mailcatcher: http://localhost:1080
  Webhook:     http://localhost:9000

Run 'make fixtures' to load example user data and start mail containers

➜  userli git:(main) ✗ make fixtures
podman compose up -d
>>>> Executing external compose provider "/opt/homebrew/bin/podman-compose". Please see podman-compose(1) for how to disable this message. <<<<

9ee72e991289a7f2828fd51754295cbd01f650fbbb348a8bd5d136727b63ed6a
83061a2ede9c49fe106adbf19ab61bea1b728ae9610eae61617edaf4d687b1b5
0fd3f3671fc78e098e2ade936e2bb5033f630029c25303e58b322a0212b51bbc
b5864e906bafacf0cb6cec8ebf24e472e2e462300dd6d6f4d4ea33c9a63bb31e
80dd823f4d2bf93dd5e418a0ae2817319a1ba279953e234082e54a5a18306223
27d7617621f894b3aa8d11fde8a7ae53ed089ba8d651dc7c5ff4f524c1e5ad1e
Waiting for MariaDB to be ready...
podman compose exec userli bin/console doctrine:migrations:migrate --no-interaction --quiet
>>>> Executing external compose provider "/opt/homebrew/bin/podman-compose". Please see podman-compose(1) for how to disable this message. <<<<


Warning: Failed loading Zend extension 'xdebug' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug.so: No such file or directory)) in Unknown on line 0
podman compose exec userli bin/console doctrine:fixtures:load --group=basic --append --no-interaction --no-debug --quiet
>>>> Executing external compose provider "/opt/homebrew/bin/podman-compose". Please see podman-compose(1) for how to disable this message. <<<<


Warning: Failed loading Zend extension 'xdebug' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug.so: No such file or directory)) in Unknown on line 0

In ExceptionConverter.php line 60:

  An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'postmaster
  ' for key 'UNIQ_E40F23B05E237E06'


In Exception.php line 24:

  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'postmaster' for key 'UNIQ_E40F23B05E237E06'


In Statement.php line 55:

  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'postmaster' for key 'UNIQ_E40F23B05E237E06'


doctrine:fixtures:load [--append] [--dry-run] [--group GROUP] [--em EM] [--purger PURGER] [--purge-exclusions PURGE-EXCLUSIONS] [--purge-with-truncate]

Error: executing /opt/homebrew/bin/podman-compose exec userli bin/console doctrine:fixtures:load --group=basic --append --no-interaction --no-debug --quiet: exit status 255
make: *** [fixtures] Error 255


That's what this is fixing. Or should we remove `postmaster`from fixtures?

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.

2 participants