マイグレーションのライブラリはPhinxを利用している。
Phinxがサポートしているカラムの型は
- biginteger
- binary
- boolean
- date
- datetime
- decimal
- float
- double
- integer
- smallinteger
- string
- text
- time
- timestamp
- uuid
MySQLの場合
も利用可能。
既存のデータベースのマイグレーションファイルの作成
bin/cake bake migration_snapshot Initial
サポート外のカラムの型も定義されるがmigrateを実行すると
InvalidArgumentException: An invalid column type "tinyinteger"
とエラーになるので注意。
migrations create
migrations dump
migrations mark_migrated
migrations migrate
マイグレーション実行
bin/cake bake migrations migrate
using migration paths
- /path_to_project/config/Migrations
using seed paths
- /path_to_project/config/Seeds
using environment default
using adapter mysql
using database database_name
ordering by creation time
== 20200320192309 Initial: migrating
== 20200320192309 Initial: migrated 0.2149s
All Done. Took 0.2211s
Dumps the current schema of the database to be used while baking a diff
using migration paths
- /path_to_project/config/Migrations
using seed paths
- /path_to_project/config/Seeds
Writing dump file `/path_to_project/config/Migrations/schema-dump-default.lock`...
Dump file `/path_to_project/config/Migrations/schema-dump-default.lock` was successfully written
マイグレーション実行管理用のテーブルとしてphinxlogテーブルが作成される。
migrations orm-cache-build
migrations orm-cache-clear
migrations rollback
migrations seed
migrations status