Skip to content
This repository has been archived by the owner on Apr 12, 2018. It is now read-only.

How to use migration?

yi-FLS edited this page Jun 19, 2015 · 15 revisions

Installation & Setup

add dependency into your project

"flagshipcompany/silex-helpers": "@dev",
  1. run composer update
  2. create a console file within your project's directory
  3. 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();
  1. 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;

Usage

  • 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';
Clone this wiki locally