# Nettrine Migrations

Doctrine/Migrations for Nette Framework.

# Content

# Setup

Install package

composer require nettrine/migrations
1

Configure extension

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

# 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 nettrine/orm integration. Doctrine ORM depends on Doctrine DBAL, use prepared nettrine/dbal integration

composer require nettrine/dbal
composer require nettrine/orm
1
2

Without these packages you can't process fixtures, because fixtures needs connection to database and information about entities. 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
1
extensions:
  console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)
1
2

# Configuration

Schema definition

nettrine.migrations:
  table: <string>
  column: <string>
  directory: <path>
  namespace: <string>
  versionsOrganization: <null|year|year_and_month>
  customTemplate: <null|path>
1
2
3
4
5
6
7

Under the hood

Minimal configuration:

nettrine.migrations:
  directory: %appDir%/migrations
1
2

# 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 gonna needed migrations:diff and migrations:migrate mostly.

# Migration

This is example of 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))');
  }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# 3rd party

kdyby/doctrine

decorator:
  Symfony\Component\Console\Command\Command:
    tags: [kdyby.console.command]
  Symfony\Component\Console\Helper\Helper:
    tags: [kdyby.console.helper]
1
2
3
4
5

# Examples

You can find more examples in planette playground repository.