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 ' => ; ]->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