Doctrine/Migrations for Nette Framework.
Install package
composer require nettrine/migrations
Configure extension
extensions:
nettrine.migrations: Nettrine\Migrations\DI\MigrationsExtension
Take advantage of enpowering this package with 2 extra packages:
doctrine/orm
symfony/console
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.
This package relies on symfony/console
, use prepared contributte/console integration.
composer require contributte/console
extensions:
console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)
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
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
.
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))');
}
}
kdyby/doctrine
decorator:
Symfony\Component\Console\Command\Command:
tags: [kdyby.console.command]
Symfony\Component\Console\Helper\Helper:
tags: [kdyby.console.helper]
- https://github.com/contributte/playground (playground)
- https://contributte.org/examples.html (more examples)