Skip to content

Latest commit

 

History

History

.docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Contributte Doctrine Migrations

Doctrine/Migrations for Nette Framework.

Content

Setup

Install package

composer require nettrine/migrations

Configure extension

extensions:
    nettrine.migrations: Nettrine\Migrations\DI\MigrationsExtension

Relying

Take advantage of enpowering this package with 2 extra packages:

  • doctrine/orm
  • symfony/console

doctrine/orm

This package relies on doctrine/orm, use prepared contributte/doctrine-orm integration. Doctrine ORM depends on Doctrine DBAL, use prepared contributte/doctrine-dbal integration

composer require nettrine/dbal
composer require nettrine/orm

Without these packages the migrations can't be processed, because they need a database connection and entities information. Don't forget to configure Doctrine DBAL & ORM properly with console bridge. Some commands need special treatment.

symfony/console

This package relies on symfony/console, use prepared contributte/console integration.

composer require contributte/console
extensions:
  console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)

Configuration

Schema definition

nettrine.migrations:
  table: <string>
  column: <string>
  directories: <array>
  versionsOrganization: <null|year|year_and_month>
  customTemplate: <null|path>

Under the hood

Minimal configuration:

nettrine.migrations:
  directories:
    App\Migrations: %appDir%/migrations

Usage

Type bin/console in your terminal and there should be a migrations command group.

  • migrations:diff
  • migrations:execute
  • migrations:generate
  • migrations:latest
  • migrations:migrate
  • migrations:status
  • migrations:up-to-date
  • migrations:version

Console Commands

You are mostly going to need migrations:diff and migrations:migrate.

Migration

This is an example of a migration class.

You can count on Nette Dependency Injection. Injecting into properties or via inject<> method is also supported.

<?php declare(strict_types = 1);

namespace App\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200000000001 extends AbstractMigration
{

  /**
   * @var MyCrypto
   * @inject
   */
  public $crypto;

  public function up(Schema $schema): void
  {
    $this->addSql('CREATE TABLE happy (id INT NOT NULL, coding INT NOT NULL, PRIMARY KEY(id))');
  }

}

3rd party

kdyby/doctrine

decorator:
  Symfony\Component\Console\Command\Command:
    tags: [kdyby.console.command]
  Symfony\Component\Console\Helper\Helper:
    tags: [kdyby.console.helper]

Examples