This repository has been archived by the owner on Apr 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
How to use migration?
yi-FLS edited this page Jun 19, 2015
·
15 revisions
"flagshipcompany/silex-helpers": "@dev",
- run composer update
- create a console file within your project's directory
- your console file (within
./bin
folder) may contain statements like the following:
#!/usr/bin/env php
<?php
require_once __DIR__.'/../vendor/autoload.php';
set_time_limit(0);
use Symfony\Component\Console\Input\ArgvInput;
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$app = require __DIR__.'/../src/app.php';
require __DIR__.'/../config/'.$env.'.php';
$console = require __DIR__.'/../src/console.php';
$console->run();
- your console.php (
./src/console.php
) may looks like the following:
<?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Flagship\Components\Helpers\Database\Commands\Migrations\MigrateCommand;
use Flagship\Components\Helpers\Database\Commands\Migrations\MigrateMakeCommand;
$console = new Application('My Silex Application', 'n/a');
$console->add(new MigrateCommand($app));
$console->add(new MigrateMakeCommand($app));
return $console;
- Scaffolding for new migration file:
php console migrate:make create_table_entity_XXXX
- Once you define your migration SQL statement, run migrate up
php console migrate or php console migrate up
- To migrate down, simply:
php console migrate down
- options & parameters:
option | description | default | example |
---|---|---|---|
--env | environment | dev | dev/test/prod |
--path | path to migration files directory | PROJECT_ROOT/var/migrations | |
--db | Doctrine DBAL Connection name | 'db_XXX' (retrieve internally as $app['dbs']['db_XXX']) |
- define options through your injected $app
$app['migrations.path'] = '/PATH/TO/MIGRATIONS';