2. Problem
• keep some necessary data in database up-to-date
• typically
• enumerations
• users like administrator or content manager
• using PhpStorm “refactor this” (or “find usages”) will not affect
the sql commands
• your sql files may stop working after you change some
insert/update sql commands after certain development is
done
3. Solution
• do it manually
• write your own doctrine:migrations (same
problems as manual inserts, plus a risk of
breaking table structure migrations)
• use Doctrine/fixtures (--append just duplicates
the content)
• any other ideas?
8. Doctrine DataApplier
• Repository: https://github.com/tuscanicz/doctrine-data-applier
• Symfony bundle
• Version: 0.9.1
• Tested in production
• MySQL
• Oracle
• Under development
9. What does it do?
• DataAppliers store your data using Doctrine
entities in your app
• detached
• no primary keys, just data
• see an example from our app
10. What does it do?
• running bin/console data:apply will synchronise
those entities with data in database
• won’t affect other data in same table (that were
inserted before or later by users or data imports)
• will insert new data, update them or even delete
(hope you backup regularly :-)
11. How does it work?
• Merges all the entities into one bundle and one
by one, compares them with database contents
and decides to persist new or merge or remove
the persisted entities.
• Cannot use primary keys, so you have to decide
what is your DataApplierIdentifier column (or
columns)
12. DataApplierIdentifier
• Annotation of Doctrine entity property
• We have no National ID number / ID card etc
id name surname city salary
1 Roman Tychka Brno 5000
2 Stojan Jakotych Podgorica 23000
3 Jane Brown London 3300
4 John Carter NY 1500
Primary key DataApplierIdentifier
13. DataApplierIdentifier
• DataApplierProcessor decides to take an action by
comparing these columns
id name surname city salary
1 Roman Tychka Brno 5000
2 Stojan Jakotych Podgorica 23000
3 Jane Brown London 3300
4 John Carter NY 1500
Primary key DataApplierIdentifier