LoginSignup
7
7

More than 5 years have passed since last update.

Phinxを使ってみる

Posted at

Phinxを使ってみる

インストール方法
http://qiita.com/MasatoYoshioka@github/items/ca42ec7d2c1197a54941

phinxの初期化

$cd migration/path
$vender/path/bin/phinx init .

phinx.ymlが作成される

migrationファイル用のディレクトリを作成

$mkdir migrations

phinx.ymlの編集

phinx.yml
paths:
    migrations: %%PHINX_CONFIG_DIR%%/migrations

environments:
    default_migration_table: phinxlog
    default_database: development
    production:
        adapter: mysql
        host: localhost
        name: production_db
        user: root
        pass: ''
        port: 3306

    development:
        adapter: mysql
        host: localhost
        name: development_db
        user: root
        pass: ''
        port: 3306

    testing:
        adapter: mysql
        host: localhost
        name: testing_db
        user: root
        pass: ''
        port: 3306

Migrationファイルの作成

$vender/path/bin/phinx create MyTestMigration
Phinx by Rob Morgan. version 0.2.9

using config file ./phinx.yml
using config parser yaml
using migration path /migration/path/migrations
created ./migrations/20140122150816_my_test_migration.php

作成されたmigrationファイルの中身

/migrations/20140122150816_my_test_migration.php

<?php

use Phinx\Migration\AbstractMigration;

class MyTestMigration extends AbstractMigration
{
    /**
     * Change Method.
     *
     * More information on this method is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-change-method
     *
     * Uncomment this method if you would like to use it.
     *
    public function change()
    {
    }
    */

    /**
     * Migrate Up.
     */
    public function up()
    {

    }

    /**
     * Migrate Down.
     */
    public function down()
    {

    }
}

migration実行

$ ../vendor/path/bin/phinx migrate
Phinx by Rob Morgan. version 0.2.9

using config file ./phinx.yml
using config parser yaml
using migration path /migration/path/migrations
warning no environment specified, defaulting to: development
using adapter mysql
using database depelopment_db

 == 20140122150816 MyTestMigration: migrating
 == 20140122150816 MyTestMigration: migrated 0.0198s

All Done. Took 0.0295s

phinxへのPathは通した方が楽だと思う。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7