phpcr / phpcr-migrations-bundle
PHPCR migrations bundle
Installs: 51 405
Dependents: 10
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: ^8.1
- doctrine/phpcr-bundle: ^2.2 || ^3.0
- phpcr/phpcr-implementation: ^2.1
- phpcr/phpcr-migrations: ^1.1
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/console: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- doctrine/annotations: ^1.14 || ^2.0
- doctrine/doctrine-bundle: ^1.8 || ^2.5
- doctrine/phpcr-odm: ^1.4 || ^2.0
- jackalope/jackalope-doctrine-dbal: ^1.4 || ^2.0
- symfony-cmf/testing: ^4.5.0
- symfony/form: ^5.4 || ^6.0 || ^7.0
- symfony/monolog-bundle: ^3.0
- symfony/phpunit-bridge: ^7.0.6
- symfony/property-access: ^5.4 || ^6.0 || ^7.0
- symfony/security-bundle: ^5.4 || ^6.0 || ^7.0
- symfony/translation: ^5.4 || ^6.0 || ^7.0
- symfony/twig-bundle: ^5.4 || ^6.0 || ^7.0
- symfony/validator: ^5.4 || ^6.0 || ^7.0
- symfony/yaml: ^5.4 || ^6.0 || ^7.0
README
This library provides a Symfony integration for the PHPCR migrations library.
It has initially been created by Daniel Leech as dantleech/phpcr-migrations-bundle
and was then
donated to the PHPCR organization.
Configuration
Configure the path to your migrations:
# config/packages/phpcr-migrations.yaml phpcr_migrations: paths: [%kernel.project_dir%/phpcr-migrations]
And the bundle will automatically pick up any migrations in the
Resources/phpcr-migrations
folder in any bundles registered in the kernel.
Creating migrations
First create two new migration files:
<?php // phpcr-migrations/Version201501011200.php use PHPCR\SessionInterface; use PHPCR\Migrations\VersionInterface; class Version201501011200 implements VersionInterface { public function up(SessionInterface $session): void { $session->getRootNode()->addNode('hello'); } public function down(SessionInterface $session): void { $session->getRootNode()->getNode('hello')->remove(); } }
and
<?php // app/phpcr-migrations/Version201501011212.php use PHPCR\SessionInterface; use PHPCR\Migrations\VersionInterface; class Version201501011212 implements VersionInterface { public function up(SessionInterface $session): void { $session->getNode('/hello')->addNode('world'); } public function down(SessionInterface $session): void { $session->getNode('/hello')->getNode('world')->remove(); } }
Migration status
Note that migration MUST be named as follows: VersionYYYMMDDHHSS
. If they
are not so-named, they will not be detected. The timestamp SHOULD be the
current date (in this example 2015/01/01 12:00
).
Now execute the phpcr:migrations:status
command:
$ php app/console phpcr:migrations:status +--+---------------+------------------+----------+----------------------------------------------+ | | Version | Date | Migrated | Path | +--+---------------+------------------+----------+----------------------------------------------+ | | 201501011200 | 2015-01-01 12:00 | NO | app/phpcr-migrations/Version201501011200.php | | | 201501011212 | 2015-01-01 12:12 | NO | app/phpcr-migrations/Version201501011212.php | +--+---------------+------------------+----------+----------------------------------------------+ No migrations have been executed
Executing migrations
Now we can run the migrations:
$ php app/console phpcr:migrations:migrate Upgrading 2 version(s): + [1/2]: 201501011200 + [2/2]: 201501011212
This should run the two migrations.
Reverting
You can now revert back to the first version as follows:
$ php app/console phpcr:migrations:migrate 201501011200 Reverting 1 version(s): - [1/4]: V201501011212
Actions
In addition to specifying versions you can specify actions:
$ php app/console phpcr:migrations:migrate up Upgrading 1 version(s): - [1/4]: V201501011212
Actions are:
up
: Upgrade one versiondown
: Revert one versiontop
: Migrate to the latest versionbottom
: Revert all migrations