[Symfony2.8] Doctrine migartion

[symfony2.8] Doctrine migartion

  • 安裝 doctrine migration 
    • composer require doctrine/doctrine-migrations-bundle "^1.0"
  • 加入到 app/AppKernel.php
    • // app/AppKernel.php
      public function registerBundles()
      {
          $bundles = array(
              //...
              new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
          );
      }
      

       

  • 設定設定檔:
    • # app/config/config.yml
      doctrine_migrations:
          dir_name: "%kernel.root_dir%/DoctrineMigrations"
          namespace: Application\Migrations
          table_name: migration_versions
          name: Application Migrations
          organize_migrations: false # Version >=1.2 Possible values are: "BY_YEAR", "BY_YEAR_AND_MONTH", false
      

       

  • 指令:
    • php app/console doctrine:migrations:status 查看目前版本狀態
    • php app/console doctrine:migrations:diff 自動產生 migrations 檔案
    • php app/console doctrine:migrations:migrate 執行migrations