「Php/phpmig」の版間の差分
ナビゲーションに移動
検索に移動
| 87行目: | 87行目: | ||
==中身の書き方== | ==中身の書き方== | ||
公式:https://github.com/davedevelopment/phpmig | 公式:https://github.com/davedevelopment/phpmig | ||
==ステータス確認== | |||
<pre> | |||
$ vendor/bin/phpmig status | |||
Status Migration ID Migration Name | |||
----------------------------------------- | |||
</pre> | |||
2024年10月21日 (月) 07:24時点における版
phpmigインストール(composer)
composer require davedevelopment/phpmig composer require pimple/pimple
参考:https://qiita.com/hideiwa1/items/98f74d95806f8d43cef9
composer.jsonから作成の場合
composer.json
{
"require": {
"davedevelopment/phpmig": "^1.7",
"pimple/pimple": "^3.5"
}
}
$ composer update
phpmig初期設定
% vendor/bin/phpmig init +d ./migrations Place your migration files in here +f ./phpmig.php Create services in here
migrationsディレクトリと、phpmig.phpファイルができる。
phpmig.php
<?php
use \Phpmig\Adapter;
$container = new ArrayObject();
// replace this with a better Phpmig\Adapter\AdapterInterface
$container['phpmig.adapter'] = new Adapter\File\Flat(__DIR__ . DIRECTORY_SEPARATOR . 'migrations/.migrations.log');
$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';
// You can also provide an array of migration files
// $container['phpmig.migrations'] = array_merge(
// glob('migrations_1/*.php'),
// glob('migrations_2/*.php')
// );
return $container;
中身を以下参考ページを見ながら、接続できるように修正。
参考:https://qiita.com/hideiwa1/items/98f74d95806f8d43cef9
db設定
config/database/の下にファイルを作成
マイグレーション実行
% vendor/bin/phpmig generate AddTests +f ./migrations/20241021162822_AddTests.php
以下ファイルだけが、作成される(これ以外の更新はない)
migrations/20241021162822_AddTests.php
use Phpmig\Migration\Migration;
class AddTests extends Migration
{
/**
* Do the migration
*/
public function up()
{
}
/**
* Undo the migration
*/
public function down()
{
}
}
中身の書き方
公式:https://github.com/davedevelopment/phpmig
ステータス確認
$ vendor/bin/phpmig status Status Migration ID Migration Name -----------------------------------------