How to use Phinx for data migration and table building in PHP projects

Source: Internet
Author: User

Build table

Phinx\bin\phinx.bat MIGRATE-E Production

Building PHINX.YML Documents

Paths:    migrations:%%phinx_config_dir%%\database\migrations    Seeds:%%phinx_config_dir%%\database\ Seedsenvironments:    default_migration_table:phinxlog    default_database:development    production:        Adapter:mysql        host:localhost        name:jitamin2        user:root        Pass: "        port:3306        charset:utf8< C12/>development:        adapter:mysql        host:localhost        name:development_db        user:root        Pass: "        port:3306        Charset:utf8    testing:        adapter:mysql        host:localhost        name:testing_db        user:root        Pass: '        port:3306        Charset:utf8

%%phinx_config_dir%%\database\migrations The following file example 20161222061456_create_users_table.php is as follows:
<?php/* * This file was part of Jitamin.  * Copyright (C) jitamin Team * For the full Copyright and license information, please view the license * file is Distributed with this source code.     */use phinx\migration\abstractmigration;class createuserstable extends abstractmigration{/** * Change Method.        */Public Function change () {$table = $this->table (' users '); $table->addcolumn (' username ', ' string ', [' limit ' =>50])->addcolumn (' Password ', ' string ', [' null ' =&G T True])->addcolumn (' Is_ldap_user ', ' Boolean ', [' null ' = = True, ' default ' = = False])-&G T;addcolumn (' name ', ' string ', [' null ' = True])->addcolumn (' Email ', ' string ')->addcol Umn (' google_id ', ' string ', [' null ' = = True, ' limit ' = ' = ') ')->addcolumn (' github_id ', ' string ', [' null ' = = True, ' limit ' = ' = '])->addcolumn (' notifications_enabled ', ' Boolean ', [' Null ' = = True, ' default ' = ' = False])->addcolumn (' TimeZone ', ' string ', [' null '] = True, ' limit ' =&gt ; ]->addcolumn (' Language ', ' string ', [' null ' = = True, ' limit ' = + 5])->addcolumn (' Disable_login_form ', ' Boolean ', [' null ' = True, ' default ' = = False])->addcolumn (' Twofactor_activat Ed ', ' Boolean ', [' null ' = True, ' default ' = = False])->addcolumn (' Twofactor_secret ', ' string ', [' Nu              ll ' = = true, ' limit ' = + +])->addcolumn (' token ', ' string ', [' null ' = = True, ' default ' = = ']) ->addcolumn (' Notifications_filter ', ' Integer ', [' null ' = True, ' default ' = 4])->a Ddcolumn (' Nb_failed_login ', ' Integer ', [' null ' = True, ' default ' = 0])->addcolumn (' Lock_expiratio              N_date ', ' BigInteger ', [' null ' = True]]->addcolumn (' gitlab_id ', ' Integer ', [' null ' = True]) ->addcolumn(' Role ', ' string ', [' limit ' = ' = ', ' default ' = ' App-user '])->addcolumn (' Is_active ', ' Boolean ', [' N              Ull ' = True, ' default ' = ' = True]->addcolumn (' Avatar_path ', ' string ', [' null ' = True]) ->addcolumn (' Skin ', ' string ', [' null ' = = True, ' limit ' =>15])->addindex ([' username '], [' Uniq    UE ' = True])->addindex ([' Email '], [' unique ' = True])->create (); }}

  

The Data Migration command is as follows:

Phinx\bin\phinx.bat SEED:RUN-E Production
%%phinx_config_dir%%\database\seeds The following file example creategroupstable.php is as follows:
<?php/* * This file was part of Jitamin.  * Copyright (C) jitamin Team * For the full Copyright and license information, please view the license * file is Distributed with this source code. */use jitamin\foundation\security\role;use phinx\seed\abstractseed;class Userseeder extends AbstractSeed{    /**     * Run Method.     *    /Public Function run ()    {        $data = [' username ' = '    admin ',              ' password '    = Bcrypt (' admin '),              ' email '       = ' [email protected] ',              ' role '        = Role::app_admin,          ],        ];        $users = $this->table (' users ');        $users->insert ($data)              ->save ();}    }

  

How to use Phinx for data migration and table building in PHP projects

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.