-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Avoid Doctrine migrations mixing schema changes and data migrations
Problem
Some Symfony/Doctrine migrations mix schema changes and data migrations in the same migration file:
- schema changes (
ALTER TABLE,ADD COLUMN,DROP COLUMN,CHANGE COLUMN) - data migration (
SELECT,UPDATE,INSERT, JSON transformations, loops in PHP, etc.)
On MySQL this can break Doctrine's transaction handling because DDL statements trigger implicit commits. When this happens, Doctrine may still try to use internal savepoints that no longer exist.
Example error encountered:
SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT DOCTRINE_10 does not exist
Observed with migration:
RZ\EventsApiModelsBundle\Migrations\Version20240213143149
Why splitting migrations helps
Splitting migrations into multiple steps avoids conflicts between MySQL implicit commits and Doctrine transactions.
Recommended structure:
-
Schema migration
ADD COLUMNCHANGE COLUMNDROP COLUMN- index changes
-
Data migration
SELECTUPDATEINSERT- backfilling or transforming existing data
-
Cleanup migration (optional)
- remove old columns once data migration is validated
Expected guideline
Define a project convention:
- Do not mix DDL and complex data migrations in the same migration.
- Avoid manual
beginTransaction()when runningALTER TABLE. - Prefer small, focused migrations executed sequentially.
- Use a separate cleanup migration when dropping legacy columns after data migration.
Benefits
- More reliable migrations
- Fewer transaction / savepoint issues with MySQL
- Easier debugging and rollback
- Clearer migration history
- Safer data backfills

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working