TP5 Migrate Database Migration Tool

Source: Internet
Author: User
Tags rollback

TP5 is quite different from tp3.2.

Migrate is one of the things that can be done by migrate programmers to create DATABASE modification rollback in PHP code

First download the Migrate extension, the command line to the current project directory execution

1 require topthink/think-migration

You can see if migrate downloaded successfully by using the PHP think command

Generate migrate file under database using Migrate:create Migrate file name (hump method with first capitalization)

It is possible to establish a failure prompt without any method generally composer gets the TP version too low, consider modifying the version of migrate in the Composer.json file to 1.* or ^1.0

Re-composer Update

Configure the database in the database.php under Application

The following is a copy of the contents of the Migrate file (after creation there is a default method change (), delete it)

1  UseThink\migration\migrator;2  UseThink\migration\db\column;3 4 classCreateusertableextendsMigrator5 {6     7     /**8 * Create user table9      */Ten      Public functionUp () { One         $table=$this->table (' user '); A         $table->addcolumn (' username ', ' string ', [' limit ' = = 30]) -->addcolumn (' Passwork ', ' string ', [' limit ' = = 32]) -->addcolumn (' email ', ' string ', [' limit ' = = 25]) the->addcolumn (' Lastlogin_ip ', ' string ', [' limit ' = = 15]) -->addtimestamps (' Create_time ', ' lastlogin_time ') -->addcolumn (' status ', ' Integer ', [' limit ' = = 1, ' default ' = + 1]) -->setid (' user_id ') +-save (); -     } +      A     /** at * Provides rollback of the Delete user table method -      */ -      Public functionDown () { -         $this->droptable (' user '); -     } -}

Some of the above methods, the official documents I did not see where, on the internet I read the little Teng explained

Using Migrate:run will perform all the migrate up methods

Migrate:rollback can roll back the previous executed migrate file (with the-T 0 parameter rollback ALL)

Migrate:status to view current migrate execution

The user table was successfully established after the Run method was executed

It's very convenient.

TP5 Migrate Database Migration Tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.