2012-03-09 14 views
29

Doctrine2 geçişlerini kullanıyorum. Ben bulmak canno, benim şüphe hakkında bazı cevaplara ihtiyacım documentationsDoctrine2 geçişleri aşağı taşınır ve tarayıcıdan taşınır ve komut satırı değil

kullandığım

iyi bir çözüm:

doctrine migrations:diff // generate migrations files 
    doctrine migrations:migrate // migrates up to new version 
  1. Nasıl aşağı taşıyabilir miyim? Önceki sürüm güncellemek için (hiçbir şey işe yaramadı belirterek fe doktrini göçler diyor: o

    Migrating up to Version20120211163332 from 20120309112058 
    
    [Doctrine\DBAL\Migrations\MigrationException] 
    Could not find any migrations to execute.  
    

    diyor Ama aşağı olmalıdır düşmez Version20120211163332 Taşınacak cevaben sürümlerinde de görebileceğiniz

  2. bazı DB güncelleme yapmak varsa, bu eklemeler bazı SQL sorguları eklemek (diğer ilgili bazı bilgileri değiştirebilir) mümkündür aşağı çalışmıyor çünkü ben hala denemedim: ((

  3. var mı uygulanıyor bir tarayıcı nutshell içinde göç komutu kullanmak için bir yol? yerine kopyalama ben bu özelliğe ihtiyaç yüzden dışarı konsol erişimi, teker teker sorgular: D phpMyAdmin

    yılında

cevap

20

Ben Symfony'nin web sitesinde bu dokümanı gördük: http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html#usage tek çalıştırmasına izin veriyor doctrine:migrations:execute yoktur

Göçmenlik sürümü elle yukarı veya aşağı ... ama asla denemediniz, üzgünüm. Bu yardımcı olur

Umut!

Bize mesaj atın.

+1

sayesinde, en azından denemiş, kabul edilen bir yanıt olarak tuttu !! Evet belgelerine (ayrıca önce soruyu yazma) okudum. Yukarı çıkmak sorun değil, ama aşağı bir kabus. Ayrıca, subversioning içeren bir ekipte çalışıyorsanız, taşıma klasörünün IGNORE'unu en iyi hale getirmek ve çalışma kopyasının her yenilendiğinde her seferinde göç komutu yapmak gerektiğini unutmayın. – giuseppe

+1

"doctrine: migrations: latest" en son sürümü almak için sürüm, "execute --down" komutundan önce. İşleri biraz kolaylaştırır. – targnation

69

Sen göç istediğiniz sürümü manuel isteğe bağlı belirtebilirsiniz:

php5 doctrine.php migrations:migrate YYYYMMDDHHMMSS 

veya Taşıma işlemini yürütmek/aşağı

php5 doctrine.php migrations:execute YYYYMMDDHHMMSS --down 
php5 doctrine.php migrations:execute YYYYMMDDHHMMSS --up 

kullanarak YYYYMMDDHHMMSS bulundu edebilirsiniz:

php5 doctrine.php migrations:status 
>> Current Version:   2012-12-20 23:38:47 (20121220233847) 
>> Latest Version:   2012-12-20 23:38:47 (20121220233847) 
+1

Burası açık. Diğerleri gibi zor değil, en zor şey, tarih damgasını dosya adından kopyalıyor! Symfony kullananlar için , sadece app/konsol doktrini çağırır: göçler: YYYYMMDDHHMMSS yürütmek --down –

7

Göçleri tarayıcıdan nasıl çalıştırabilirsiniz:

composer.json

{ 
    "require": { 
     "doctrine/dbal": "*", 
     "doctrine/migrations": "dev-master" 
    }, 
    "minimum-stability": "dev", 
    "autoload": { 
     "psr-0": {"": "src/"} 
    } 
} 

src/Acme/Taşıma/Version1.php

<?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->createTable('users'); 
     $users->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true)); 
     $users->addColumn('username', 'string', array('length' => 128)); 
     $users->addColumn('password', 'string', array('length' => 128)); 
     $users->setPrimaryKey(array('id')); 

     // You can also add any queries 
     // $this->addSql('CREATE TABLE addresses (id INT NOT NULL, street VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB'); 
    } 

    public function down(Schema $schema) 
    { 
     $schema->dropTable('users'); 

     //$this->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) {} 
} 

dizini.Şimdi php

<?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 : '<br>'; // 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]) && filter_var($arguments[$index], FILTER_VALIDATE_INT) ? intval($arguments[$index]) : null; 
#endregion 

#region Doctrine Connection 
// Silex: $app['db'] 
// Symfony controller: $this->get('database_connection') 
$db = DriverManager::getConnection(array(
    'dbname' => 'doctine_migrations', 
    'user' => 'root', 
    'password' => 'root', 
    'host' => 'localhost', 
    'driver' => 'pdo_mysql', 
    'charset' => 'utf8', 
    'driverOptions' => array(
     PDO::MYSQL_ATTR_INIT_COMMAND => '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->setName('My Migrations'); // Optional name for your migrations 
$config->setMigrationsTableName('version'); // Table name that will store migrations log (will be created automatically, default name is: doctrine_migration_versions) 
$config->setMigrationsNamespace('Acme\\Migrations'); // Namespace of your migration classes, do not forget escape slashes, do not add last slash 
$config->setMigrationsDirectory('src/Acme/Migrations'); // Directory where your migrations are located 
$config->registerMigrationsFromDirectory($config->getMigrationsDirectory()); // Load your migrations 
#endregion 

$migration = new Migration($config); // Create Migration based on provided configuration 

$versions = $migration->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 => $queries) { 
    echo 'VERSION: ' . $version . $nl; 
    echo '----------------------------------------------' . $nl . $nl; 

    foreach ($queries as $query) { 
     echo $query . $nl . $nl; 
    } 

    echo $nl . $nl; 
} 
#endregion 

try { 
    $migration->migrate($to); // Execute migration! 
    echo 'DONE' . $nl; 
} catch (Exception $ex) { 
    echo 'ERROR: ' . $ex->getMessage() . $nl; 
} 

yapabilirsiniz: konsoldan

Run it:

php index.php - lates sürüme olacak

php index.php 2 - güncel sürümü büyükse (sürüm 2 göç edecek - geçişi

Web tarayıcısından çalıştır:

http://localhost/index.php ve http://localhost/index.php?to=2 aynısını yapacağız. Cevabınız için

İlgili konular