Skip to content

Latest commit

 

History

History

.docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Contributte Doctrine Migrations

Integration of Doctrine Migrations for Nette Framework.

Content

Installation

Install package using composer.

composer require nettrine/migrations

Register prepared compiler extension in your config.neon file.

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

Note

This is just Migrations, for ORM use nettrine/orm or DBAL use nettrine/dbal.

Configuration

Minimal configuration

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

Advanced configuration

Here is the list of all available options with their types.

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

  migrationFactory: <service>
  logger: <service>
  connection: <string>
  manager: <string>

Multiple databases

$this->configurator->addDynamicParameters([
	'env' => getenv(),
]);
nettrine.migrations:
  directories:
    App\Migrations: %appDir%/migrations
  connection: %env.DATABASE_CONNECTION%

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

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

Migration

You can create a new migration by running the following command.

bin/console migrations:generate

In the migration file, you can use 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;
use Nette\DI\Attributes\Inject;

final class Version20200000000001 extends AbstractMigration
{

  #[Inject]
  public DummyService $dummy;

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

}

DBAL & ORM

Tip

Doctrine Migrations needs a database connection and entities information. Take a look at nettrine/dbal and nettrine/orm.

composer require nettrine/dbal
composer require nettrine/orm

Console

Tip

Doctrine DBAL needs Symfony Console to work. You can use symfony/console or contributte/console.

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

  nettrine.dbal: Nettrine\DBAL\DI\DbalExtension

Since this moment when you type bin/console, there'll be registered commands from Doctrine DBAL.

Console Commands

Examples

Tip

Take a look at more examples in contributte/doctrine.