Contributte Doctrine-migrations
Doctrine/Migrations (opens new window) for Nette Framework.
# Content
# Setup
Install package
composer require nettrine/migrations
Configure extension
extensions:
nettrine.migrations: Nettrine\Migrations\DI\MigrationsExtension
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 contributte/doctrine-orm (opens new window) integration.
Doctrine ORM depends on Doctrine DBAL, use prepared contributte/doctrine-dbal (opens new window) integration
composer require nettrine/dbal
composer require nettrine/orm
2
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 (opens new window). Some commands need special treatment.
# symfony/console
This package relies on symfony/console
, use prepared contributte/console (opens new window) integration.
composer require contributte/console
extensions:
console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)
2
# Configuration
Schema definition
nettrine.migrations:
table: <string>
column: <string>
directory: <path>
namespace: <string>
versionsOrganization: <null|year|year_and_month>
customTemplate: <null|path>
2
3
4
5
6
7
Under the hood
Minimal configuration:
nettrine.migrations:
directory: %appDir%/migrations
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
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 (opens new window).
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))');
}
}
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]
2
3
4
5
# Examples
- https://github.com/contributte/playground (opens new window) (playground)
- https://contributte.org/examples.html (opens new window) (more examples)