1. Go to this page and download the library: Download nobuhiko/ec-cube2-migration library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nobuhiko / ec-cube2-migration example snippets
use Eccube2\Migration\Migration;
use Eccube2\Migration\Schema\Table;
class Version20260130000001_CreateLoginAttemptTable extends Migration
{
public function up(): void
{
$this->create('dtb_login_attempt', function (Table $table) {
// serial() は自動的に login_attempt_id を PRIMARY KEY として作成
$table->serial();
$table->text('login_id')->notNull();
$table->text('ip_address')->nullable();
$table->smallint('result')->notNull();
$table->timestamp('create_date')->default('CURRENT_TIMESTAMP');
$table->index(['login_id', 'create_date']);
});
}
public function down(): void
{
$this->drop('dtb_login_attempt');
}
}
public function up(): void
{
$this->table('dtb_customer', function (Table $table) {
// カラム追加
$table->addColumn('reset_token', 'text')->nullable();
$table->addColumn('reset_token_expire', 'timestamp')->nullable();
// インデックス追加
$table->addIndex(['reset_token']);
});
}
public function down(): void
{
$this->table('dtb_customer', function (Table $table) {
$table->dropIndex('idx_dtb_customer_reset_token');
$table->dropColumn('reset_token_expire');
$table->dropColumn('reset_token');
});
}
public function up(): void
{
// 全DBで同じSQL
$this->sql("UPDATE dtb_baseinfo SET shop_name = 'New Name'");
// DB別に異なるSQL
$this->sql(
"SELECT DATE_ADD(NOW(), INTERVAL 1 DAY)", // MySQL
"SELECT NOW() + INTERVAL '1 day'", // PostgreSQL
"SELECT datetime('now', '+1 day')" // SQLite
);
}
$this->create('dtb_customer', function (Table $table) {
$table->serial(); // customer_id が自動作成される
});
$this->create('dtb_login_attempt', function (Table $table) {
$table->serial(); // login_attempt_id が自動作成される
});