Implementation of Doctrine\Migrations to Nette.
Add to your composer.json
:
"require": {
"doctrine/migrations": "@dev",
"zenify/doctrine-migrations": "~2.0"
}
and run composer update
.
This is due to doctrine/migrations, that hasn't been tagged for a long time.
Register extensions in config.neon
(includes Kdyby/Doctrine configuration):
extensions:
- Kdyby\Annotations\DI\AnnotationsExtension
- Kdyby\Events\DI\EventsExtension
- Kdyby\Console\DI\ConsoleExtension
doctrine: Kdyby\Doctrine\DI\OrmExtension
migrations: Zenify\DoctrineMigrations\DI\MigrationsExtension
doctrine:
host: localhost
user: root
password:
dbname: database
config.neon
with default values
migrations:
table: doctrine_migrations # database table for applied migrations
dirs: # list of dirs to load migrations from
- %appDir%/../migrations # first dir is used for generating migrations
namespace: Migrations # namespace of migration classes
enabled: FALSE # cli based loading; set TRUE to force loading in non-cli
codingStandard: tabs # or "spaces", cs for generated classes
Open your CLI and run command:
php www/index.php
And then you should see all available commands:
And then you can run any command you need, e.g. migrate command:
php www/index.php migrations:migrate
If you get lost, just use -h
option for help:
php www/index.php migrations:migrate -h
For further use, please check docs in Symfony bundle.
In case you have plenty of migrations and you want to store them in another directory, just add them to dirs
.
Only the first one (here %appDir%/../migrations
) will be used to create migrations from command line.
migrations:
dirs:
- %appDir%/../migrations
- %appDir%/../migrations/2013
- %appDir%/../migrations/2012
namespace Migrations;
class Version20140801152432 extends AbstractMigration
{
/**
* @inject
* @var Doctrine\ORM\EntityManager
*/
public $em;
public function up(Schema $schema)
{
$product = new Product;
$product->setName('Chips without fish')
$this->em->persist(product);
$this->em->flush();
}
// ...
}