Skip to content

make:migration

Generates a migration class for creating a custom database table.

Signature

bash
php nikogin make:migration {ClassName}

Convention

Class names follow the Create{TableName}Table pattern. The table name is auto-derived by stripping Create and Table.

Class nameTable nameFull table name
CreateOrdersTableorderswp_ng_orders
CreatePostMetaTablepost_metawp_ng_post_meta

Example

bash
php nikogin make:migration CreateOrdersTable

Generated output

php
class CreateOrdersTable extends Migration
{
    public function getTableName(): string
    {
        return 'orders';
    }

    public function getSchema(): string
    {
        $table = $this->getFullTableName();

        return "CREATE TABLE {$table} (
            id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
            created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
            PRIMARY KEY (id)
        ) {$this->charsetCollate};";
    }
}

Add your columns to getSchema() and create the matching Repository with --type=db.

Nikogin Framework — WordPress plugin development made simple.