Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how you can run migrations from browser:</p> <p><strong>composer.json</strong></p> <pre><code>{ "require": { "doctrine/dbal": "*", "doctrine/migrations": "dev-master" }, "minimum-stability": "dev", "autoload": { "psr-0": {"": "src/"} } } </code></pre> <p><strong>src/Acme/Migrations/Version1.php</strong></p> <pre><code>&lt;?php # src/Acme/Migrations/Version1.php namespace Acme\Migrations; use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Schema\Schema; /** * Class Version1 * * Notice that file and class names MUST be Version*.php * * @package Acme\Migrations */ class Version1 extends AbstractMigration { public function up(Schema $schema) { $users = $schema-&gt;createTable('users'); $users-&gt;addColumn('id', 'integer', array('unsigned' =&gt; true, 'autoincrement' =&gt; true)); $users-&gt;addColumn('username', 'string', array('length' =&gt; 128)); $users-&gt;addColumn('password', 'string', array('length' =&gt; 128)); $users-&gt;setPrimaryKey(array('id')); // You can also add any queries // $this-&gt;addSql('CREATE TABLE addresses (id INT NOT NULL, street VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB'); } public function down(Schema $schema) { $schema-&gt;dropTable('users'); //$this-&gt;addSql('DROP TABLE addresses'); } // Use this functions to prepare your migrations //public function preUp(Schema $schema) {} //public function postUp(Schema $schema) {} //public function preDown(Schema $schema) {} //public function postDown(Schema $schema) {} } </code></pre> <p><strong>index.php</strong></p> <pre><code>&lt;?php # index.php use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Migrations\Configuration\Configuration; use Doctrine\DBAL\Migrations\Migration; use Doctrine\DBAL\Migrations\OutputWriter; require_once 'vendor/autoload.php'; $nl = PHP_SAPI == 'cli' ? PHP_EOL : '&lt;br&gt;'; // Optional will be used for output $to = null; // Optional integer - migrate to version, if null - will migrate to latest available version #region Optional get argument $index = PHP_SAPI == 'cli' ? 1 : 'to'; $arguments = PHP_SAPI == 'cli' ? $argv : $_REQUEST; $to = isset($arguments[$index]) &amp;&amp; filter_var($arguments[$index], FILTER_VALIDATE_INT) ? intval($arguments[$index]) : null; #endregion #region Doctrine Connection // Silex: $app['db'] // Symfony controller: $this-&gt;get('database_connection') $db = DriverManager::getConnection(array( 'dbname' =&gt; 'doctine_migrations', 'user' =&gt; 'root', 'password' =&gt; 'root', 'host' =&gt; 'localhost', 'driver' =&gt; 'pdo_mysql', 'charset' =&gt; 'utf8', 'driverOptions' =&gt; array( PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES utf8' ) )); #endregion #region Config $config = new Configuration($db /*, new OutputWriter(function ($message) { echo $message . PHP_EOL; })*/); // OutputWriter is optional and by default do nothing, accepts closure for writing logs //$config-&gt;setName('My Migrations'); // Optional name for your migrations $config-&gt;setMigrationsTableName('version'); // Table name that will store migrations log (will be created automatically, default name is: doctrine_migration_versions) $config-&gt;setMigrationsNamespace('Acme\\Migrations'); // Namespace of your migration classes, do not forget escape slashes, do not add last slash $config-&gt;setMigrationsDirectory('src/Acme/Migrations'); // Directory where your migrations are located $config-&gt;registerMigrationsFromDirectory($config-&gt;getMigrationsDirectory()); // Load your migrations #endregion $migration = new Migration($config); // Create Migration based on provided configuration $versions = $migration-&gt;getSql($to); // Retrieve SQL queries that should be run to migrate you schema to $to version, if $to == null - schema will be migrated to latest version #region Some dummy output foreach ($versions as $version =&gt; $queries) { echo 'VERSION: ' . $version . $nl; echo '----------------------------------------------' . $nl . $nl; foreach ($queries as $query) { echo $query . $nl . $nl; } echo $nl . $nl; } #endregion try { $migration-&gt;migrate($to); // Execute migration! echo 'DONE' . $nl; } catch (Exception $ex) { echo 'ERROR: ' . $ex-&gt;getMessage() . $nl; } </code></pre> <p>Now you can:</p> <p>Run it from console:</p> <p><code>php index.php</code> - will migrate to lates version</p> <p><code>php index.php 2</code> - will migrate to version 2 (if current version is bigger - it will migrate down</p> <p>Run from web browser:</p> <p><code>http://localhost/index.php</code> and <code>http://localhost/index.php?to=2</code> will do the same.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload