Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ MySQL migration tool used in the production environment     - Interesting example of Linux Sort command (Linux)

- Try debugfs restore the deleted files ext3 file system (Linux)

- iOS developers - a simple factory pattern and OC reflection (Programming)

- Linux System Getting Started Learning: DeVeDe installed on Linux to create a video DVD (Linux)

- Linux performance optimization tools perf top (Linux)

- Linux /var/spool/ insufficient clientmqueue space solutions (Linux)

- impdp error ORA-31631, ORA-39122 (Database)

- Installation of Ubuntu Make under Ubuntu 15.10 (Linux)

- Build Golang development environment configuration on Ubuntu 14.04 (Linux)

- Linux System Getting Started Tutorial: Using the Linux common commands (Linux)

- CentOS7 management of systemd (Linux)

- MyCAT log analysis (Database)

- PostgreSQL query lock and kill the process (Database)

- Java implementation chain store binary tree (Programming)

- Fedora 21 setting boot script (Linux)

- How to adjust the system time CentOS (Linux)

- Linux folder and extract the differential file comparison techniques -rsync Magical (Linux)

- Talking about the shortcomings and deficiencies of the firewall (Linux)

- The Linux role of each directory contents (Linux)

- Oracle 12C with multi-column index (Database)

 
         
  MySQL migration tool used in the production environment
     
  Add Date : 2018-11-21      
         
         
         
  Product release in iterative development process, due to the increase in business demand, inevitably there will be a database of structural adjustment and other operations.
How each version of each controlled release process server-side programs and consistent version of the database, and the database upgrade, rollback and other operations.
The Bowen House birds will recommend you a mysql database migration tool mysql-php-migrations
Depending on the specific needs, according to their own house Bird's situation will mysql-php-migrations made some changes to full application!

Bird House to modify the program after mysql migration program has the following directories:



config configuration file
dbscript sql scripts directory
lib migration program library
migrate.php migration command entry


Execute php migrate.php
We can see the following results

We can see that there are many commands migrate.php
php migrate.php add test
result:
      __ __ __ __
| / | (_ / | __ | __) | __ || __) __ | / |. _ _ _ |. _ _ _ _
| | / __) _ / | __ | | || | || (_) | (_ || _ | (_) |) _)
  / _ /
************************************************** ****************** v2.0.1 ***


New migration created: file
/var/www/mysqlMigrations/dbscript/2013_12_18_14_50_45_test.php


************************************************** *****************************
cd dbscript
total 16
-rw-r - r-- 1 www-data www-data 4837 Sep 29 09:21 2013_06_18_17_14_16_v1.php
-rw-r - r-- 1 www-data www-data 802 Sep 29 13:29 2013_09_29_12_00_12_v1.php
-rw-r - r-- 1 root www-data 240 Dec 18 14:50 2013_12_18_14_50_45_test.php
At this point add a new directory already dbscript 2013_12_18_14_50_45_test.php file, change the file format is as follows:
class Migration_2013_12_18_14_50_45 extends MpmMysqliMigration
{
      public function up (ExceptionalMysqli & $ mysqli)
      {
              $ Mysqli-> exec ( "DO 0");
      }
      public function down (ExceptionalMysqli & $ mysqli)
      {
              $ Mysqli-> exec ( "DO 0");
      }


}
?>

The need to modify the database script written up function:
The changes made to modify the corresponding rollback uninstallation down function

Note: It is recommended only up Change database in a production environment, not down operations, to avoid loss of data useful to the user.

Execute php migrate.php list returns the result:
WARNING: Migration numbers may not be in order due to interleaving.


    # Timestamp
  ================================================== ======================
    version createtime active current note
    1371546856 2013-06-18 17:14:16 1 0 v1
    1380427212 2013-09-29 12:00:12 1 1 v1
    1387349445 2013-12-18 14:50:45 0 0 test
  Page 1 of 1, 3 migrations in all.

 


cd config directory
cat db_config.php
$ Db_config = (object) array ();

$ Db_config-> host = '127.0.0.1';
$ Db_config-> port = '3306';
$ Db_config-> user = 'dbuser';
$ Db_config-> pass = 'dbpasswd';
$ Db_config-> name = 'dbname';
$ Db_config-> db_path = 'var / www / mysqlMigrations / dbscript /';
$ Db_config-> method = 2; // 1 pdo, 2 mysqli
?>

 

Once you understand the basic structure of the program, we started to look at it:
cd mysqlMigrations
php migrate.php add test2

2013_12_18_15_06_14_test2.php generated at dbscript


Run: php migrate.php list
You can see the version Results:

# Timestamp
  ================================================== ======================
    version createtime active current note
    1371546856 2013-06-18 17:14:16 1 0 v1
    1380427212 2013-09-29 12:00:12 1 1 v1
    1387349445 2013-12-18 14:50:45 0 0 test
    1387350374 2013-12-18 15:06:14 0 0 test2


  Page 1 of 1, 4 migrations in all.


Explanation:
  version version number of each migration

  createtime Created
  Whether active has been activated to take effect
  The current version of the database where the current flag
  Note Migration note

 

Run: php migrate.php up 1387349445 1380427212 from the version of the data can be migrated to 1387349445
# Timestamp
  ================================================== ======================
    version createtime active current note
    1371546856 2013-06-18 17:14:16 1 0 v1
    1380427212 2013-09-29 12:00:12 1 0 v1
1387349445 2013-12-18 14:50:45 1 1 test
    1387350374 2013-12-18 15:06:14 0 0 test2


  Page 1 of 1, 4 migrations in all.

 


Run: php migrate.php down 1380427212 1387349445 from the version of the data can be rolled back to 1380427212
Execute php migrate.php list to view the database version rollback results
 # Timestamp
  ================================================== ======================
    version createtime active current note
    1371546856 2013-06-18 17:14:16 1 0 v1
    1380427212 2013-09-29 12:00:12 1 1 v1
    1387349445 2013-12-18 14:50:45 0 0 test
    1387350374 2013-12-18 15:06:14 0 0 test2


  Page 1 of 1, 4 migrations in all.


If you want to migrate to the largest database version can execute the following command:
php migrate.php up max_version
Return:
Migrating to 2013-12-18 15:06:14 (ID 1387350374) ...
      Performing UP migration 2013-12-18 14:50:45 (ID 1387349445) ... done.
      Performing UP migration 2013-12-18 15:06:14 (ID 1387350374) ... done.


************************************************** *****************************
See php migrate.php list
# Timestamp
  ================================================== ======================
    version createtime active current note
    1371546856 2013-06-18 17:14:16 1 0 v1
    1380427212 2013-09-29 12:00:12 1 0 v1
    1387349445 2013-12-18 14:50:45 1 0 test
1387350374 2013-12-18 15:06:14 1 1 test2


  Page 1 of 1, 4 migrations in all.


Rollback:
php migrate.php down 1380427212
Back at the results:
Migrating to 2013-09-29 12:00:12 (ID 1380427212) ...
      Performing DOWN migration 2013-12-18 15:06:14 (ID 1387350374) ... done.
      Performing DOWN migration 2013-12-18 14:50:45 (ID 1387349445) ... done.


  # Timestamp
  ================================================== ======================
    version createtime active current note
    1371546856 2013-06-18 17:14:16 1 0 v1
    1380427212 2013-09-29 12:00:12 1 1 v1
    1387349445 2013-12-18 14:50:45 0 0 test
    1387350374 2013-12-18 15:06:14 0 0 test2


  Page 1 of 1, 4 migrations in all.


By performing the operation about to view the data in the database changes
     
         
         
         
  More:      
 
- Ubuntu install Tonido private cloud services (Server)
- Compare Swift achieve rapid sorting and sorted Methods (Programming)
- ADSL router to defend their own network security methods (Linux)
- Ubuntu 14.04 next upgrade to GNOME 3.12 (Linux)
- Five useful commands to manage file types and system time in linux (Linux)
- Linux learning portal: CentOS 6.4 system kernel upgrade (Linux)
- Oracle how to maintain the consistency of read? (Database)
- Specifies the open ports of the SUSE firewall settings (Linux)
- Shell Scripting Basics (Linux)
- Depth Java Singleton (Programming)
- MySQL loose index scan (Database)
- Red Hat Linux security settings document (Linux)
- KVM virtualization of nested virtualization (Linux)
- VMware virtual machine to install CentOS 7 (Linux)
- Teach you how to synchronize Microsoft OneDrive in Linux (Linux)
- RHEL6.4 one key installation Redmine (Linux)
- Ubuntu under Spark development environment to build (Server)
- Docker knowledge base (Server)
- Simple configuration shell scripts virtual machine environment experiment (Linux)
- iOS used in the development --UITabBarController tag controller (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.