Migration Database Migration Tool Phinx
Description
Phinx allows developers to easily modify and maintain databases. It avoids the need for manually written SQL statements and uses a powerful PHP API to manage database migrations. Developers can utilize version control to manage their database migrations. Phinx conveniently facilitates data migration between different databases. It also keeps track of which migration scripts have been executed, allowing developers to focus more on writing better systems without worrying about the state of the database.
Project Address
https://github.com/cakephp/phinx
Installation
composer require robmorgan/phinx
Official Chinese Documentation Address
For detailed usage, you can check the official Chinese documentation. Here we only discuss how to configure and use it in webman.
https://tsy12321.gitbooks.io/phinx-doc/content/
Migration File Directory Structure
.
├── app Application directory
│ ├── controller Controller directory
│ │ └── Index.php Controller
│ ├── model Model directory
......
├── database Database files
│ ├── migrations Migration files
│ │ └── 20180426073606_create_user_table.php
│ ├── seeds Test data
│ │ └── UserSeeder.php
......
phinx.php Configuration
Create a phinx.php
file in the project root directory.
<?php
return [
"paths" => [
"migrations" => "database/migrations",
"seeds" => "database/seeds"
],
"environments" => [
"default_migration_table" => "phinxlog",
"default_database" => "dev",
"default_environment" => "dev",
"dev" => [
"adapter" => "DB_CONNECTION",
"host" => "DB_HOST",
"name" => "DB_DATABASE",
"user" => "DB_USERNAME",
"pass" => "DB_PASSWORD",
"port" => "DB_PORT",
"charset" => "utf8"
]
]
];
Usage Recommendations
Once migration files are merged, they should not be modified again. If issues arise, new modification or deletion operation files must be created to handle the situation.
Naming Rule for Table Creation Operation Files
{time(auto create)}_create_{table name in lowercase}
Naming Rule for Table Modification Operation Files
{time(auto create)}_modify_{table name in lowercase + specific modification in lowercase}
Naming Rule for Table Deletion Operation Files
{time(auto create)}_delete_{table name in lowercase + specific modification in lowercase}
Naming Rule for Data Filling Files
{time(auto create)}_fill_{table name in lowercase + specific modification in lowercase}