Giter VIP home page Giter VIP logo

phpcr-migrations's Introduction

PHPCR Migrations

Build Status

Migrations library for PHPCR influenced by Doctrine migrations.

For integration with Symfony see the PHPCR Migrations Bundle.

Usage

<?php

use Symfony\Component\Console\Output\NullOutput;
use PHPCR\Migrations\VersionStorage;
use PHPCR\Migrations\VersionFinder;
use PHPCR\Migrations\Migrator;

$storage = new VersionStorage($phpcrSession);
$finder = new VersionFinder(array('/path/to/migrations'));

$versions = $finder->getVersionCollection();
$migrator = new Migrator($session, $versionCollection, $storage);

$to = '201504241744';
$output = new NullOutput();
$migrator->migrate($to, $output);

You may also create a factory class (useful when you use dependency injection):

<?php

$factory = new MigratorFactory($storage, $finder, $session);
$migrator = $factory->getMigrator();

Initializing

When you install a project for the first time you need to initialize the versions:

<?php

$migrator->initialize();

This should be part of your build process and it will add all the versions to the migration version node in the content repository.

Migrating

$migrator->migrate('201501011200', $output); // migrate to a specific version
$migrator->migrate('up', $output); // migrate up a version
$migrator->migrate('down', $output); // migrate down a version
$migrator->migrate('top', $output); // migrate to the latest version
$migrator->migrate('bottom', $output); // revert all versions

Listing versions

You can access information about available versions from the VersionCollection object:

$versionCollection->getAllVersions();

Determining the current version

You can determine the current version from the VersionStorage object:

$versionStroage->getCurrentVersion();

Version classes

Version classes contain up and down methods. The class is quite simple:

<?php

use PHPCR\Migrations\VersionInterface;

class Version201504241200 implements VersionInterface
{
    public function up(SessionInterface $session)
    {
        $session->doSomething();
    }

    public function down(SessionInterface $session)
    {
        $session->undoSomething();
    }
}

They must be named VersionYYYMMDDHHMM. If they are not so named, then they will not be detected.

The down method should revert any changes made in the up method. Always check that revcerting your migration works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.