Database MigrationUsing Phinx to Automate Database Migrations |
Summary
Adding PhinxA PHP library to automate the implementation of database changes. to the project to automate database change migration as part of a deployment pipeline.
Overview
Purpose | To use PhinxA PHP library to automate the implementation of database changes. to automate database change migration as part of a DevOps deployment process. |
Goals |
|
Technology | PhinxA PHP library to automate the implementation of database changes. |
Resources | Primarily the phinx.org website. |
Implementation
-
Install PhinxA PHP library to automate the implementation of database changes.
This was done in a Terminal window in the Document Root using ComposerUsed to manage the installation of third-party PHP libraries.:
composer require robmorgan/phinx
-
Initialize and Configure PhinxA PHP library to automate the implementation of database changes.
-
In a Terminal window, type the below to initialize PhinxA PHP library to automate the implementation of database changes.:
vendor/bin/phinx init
-
This creates a phinx.yml in the Document Root. This file was edited to reflect the connection information of the development and testing databases as well as the directory to hold the migration classes.
-
-
Create a PhinxA PHP library to automate the implementation of database changes. Migration
In the terminal window the below was executed which creates a PHPServer-side scripting language for web development. class file in the directory defined in the phinx.yml file:
php vendor/bin/phinx create Project004
-
Write Migration Code
The class created by PhinxA PHP library to automate the implementation of database changes. was modified to add the implementation of all database objects used by the site so far. During this process a number of tables were restructured to address issues.
-
Create Link to MySQLRelational database used to hold website content and search data. Socket
Initial runs of PhinxA PHP library to automate the implementation of database changes. failed on my Macbook, as PhinxA PHP library to automate the implementation of database changes. was not able to find the MySql executables. Following a recommendation on a discussion board the below link was created which resolved the issue:
cd /var
sudo mkdir mysql
cd mysql
sudo ln -s /Applications/MAMPPersonal webserver stack to allow PHP and MySQL development on MacOS./tmp/mysql/mysql.sock -
Execute Migration
The migration was then run against the development and testing environments:
vendor/bin/phinx migrate -e development
vendor/bin/phinx migrate -e testingNote: Adding the option -vvv to the commands turns on verbose messaging which can be helpful if the migration fails.