HOME > > > > >

Migrations

マイグレーションのライブラリはPhinxを利用している。 Phinxがサポートしているカラムの型は

  • biginteger
  • binary
  • boolean
  • date
  • datetime
  • decimal
  • float
  • double
  • integer
  • smallinteger
  • string
  • text
  • time
  • timestamp
  • uuid

MySQLの場合

  • enum
  • set
  • blob
  • bit
  • json

も利用可能。

既存のデータベースのマイグレーションファイルの作成

  1. bin/cake bake migration_snapshot Initial

サポート外のカラムの型も定義されるがmigrateを実行すると

  1. InvalidArgumentException: An invalid column type "tinyinteger"

とエラーになるので注意。

migrations create

migrations dump

migrations mark_migrated

migrations migrate

マイグレーション実行

  1. bin/cake bake migrations migrate
  2.  
  3. using migration paths
  4.  - /path_to_project/config/Migrations
  5. using seed paths
  6.  - /path_to_project/config/Seeds
  7. using environment default
  8. using adapter mysql
  9. using database database_name
  10. ordering by creation time
  11.  
  12.  == 20200320192309 Initial: migrating
  13.  == 20200320192309 Initial: migrated 0.2149s
  14.  
  15. All Done. Took 0.2211s
  16.  
  17. Dumps the current schema of the database to be used while baking a diff
  18.  
  19. using migration paths
  20.  - /path_to_project/config/Migrations
  21. using seed paths
  22.  - /path_to_project/config/Seeds
  23. Writing dump file `/path_to_project/config/Migrations/schema-dump-default.lock`...
  24. Dump file `/path_to_project/config/Migrations/schema-dump-default.lock` was successfully written
  25.  

マイグレーション実行管理用のテーブルとしてphinxlogテーブルが作成される。

migrations orm-cache-build

migrations orm-cache-clear

migrations rollback

migrations seed

migrations status