from one database and replaying them on another database to keep their structures in sync. • Example: Add a new column on development server, production database now is out of date. • Until we migrate.
to fill in. • Scripts can: ◦ Attempt to automanage Change()s ◦ Specific Push changes Up() ◦ Specific Roll changes Down() • Execute Phinx, changes happen.
project root. • Create a phinx.yml file in your project root. Tell Phinx where to store its scripts, and where to track its current state in the database. paths: migrations: %%PHINX_CONFIG_DIR%%/phinx environments: default_migration_table: phinxlog
well. This will allow you to build migrations against dev database, and then either push finished migrations to production, or let production pull migrations itself. environments: default_migration_table: phinxlog default_database: dev dev: adapter: mysql host: localhost name: DevelDatabase user: DevelUsername pass: DevelPassword port: 3306 prod: adapter: mysql host: db1 name: ProductionDatabase user: ProductionUsername pass: ProductionPassword port: 3306
template to use for the auto generated scripting, you can also define that in the phinx.yml file. templates: file: %%PHINX_CONFIG_DIR%%/phinx/Template.txt
migration script is the Up() method. This method will be executed when Phinx is told to update the database with the latest changes. The second component of a migration script is the Down() method. This method will be executed when Phinx is told to undo changes. The third component of a migration script is an optional mix: Change(). Using the Abstract API that Phinx provides it can attempt to automatically handle upgrades and downgrades without you having to write the specifics. If you define an Up() and Down(), you cannot define a Change().
an auto incrementing integer column called "id". • You can either rename it, or disable it, if you elect to. • (I think you should elect to. Its default type kinda sucks.)
any time you are unsure if a command was committed to the database or not. You use it within your Up() and Down() methods. Create() and Update() are shortcut methods which tell Phinx what is happening - you are creating a table, or you are updating a table. You use them within Change() so that Phinx can automatically generate the steps to undo what you just did on rollback.
last. You cannot cherry pick migrations. You can however stop at a certain point in time. Phinx tracks the most recent migration in the `phinxlog` table. This way it knows where it left off, if you are multiple migration scripts behind it will execute only the ones you are missing. $ php vendor/bin/phinx migrate
are iterative. To successfully rollback you must have used proper Change() methods or written both your Up() an Down(). Data loss due to a change is data lost. Like if you change an INT size, you may be S.O.L.
pulled onto production. Production defines environment var: PHINX_ENVIRONMENT cat ~/.bash_profile export PHINX_ENVIRONMENT="prod" Then your build system when pulling the latest source will also run phinx migrate locally.
run them for yourself to build the database exactly how I had it at the end of tonight. Like, that was the entire point, a portadatabase. https://github.com/bobmagicii/dallasphp-201611-phinx These Slides. Because slides. https://speakerdeck.com/bobmajdakjr/phinx Dallas PHP - Nov 2016 - @bobmagicii