PHP code example of demmonico / yii2-migration

1. Go to this page and download the library: Download demmonico/yii2-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/ */

    

demmonico / yii2-migration example snippets


class m000000_000000_tbl_country extends Migration
{
    // common table's info
    protected $tableName = '{{%country}}';
    //
    //
    // structure table's info
    protected $columns = [
        'code'                      => 'CHAR(2) NOT NULL PRIMARY KEY comment "ISO 3166-1 alpha-2"',
        self::COLUMN_NAME           => 'VARCHAR(255) NOT NULL',
        'phone_country'             => 'VARCHAR(10) NOT NULL',
        'language'                  => 'CHAR(2) DEFAULT NULL comment "ISO 639-1"',
        'currency'                  => 'CHAR(3) DEFAULT NULL comment "ISO 4217"',
        self::COLUMN_ISACTIVE       => 'TINYINT(1) UNSIGNED NOT NULL DEFAULT '.self::BOOL_ON,
        self::COLUMN_ORDER          => 'INT(11) UNSIGNED NOT NULL DEFAULT 1000',
        self::COLUMN_CREATED        => 'DATETIME NOT NULL',
        self::COLUMN_UPDATED        => 'DATETIME DEFAULT NULL',
    ];
    //
    protected $indexKeys = [self::COLUMN_ISACTIVE, self::COLUMN_ORDER, 'phone_country', 'currency'];
    //
    protected $foreignKeys = [
        'language' => [
            'refTable' => self::TABLE_LANGUAGE,
            'refColumn'=>'code',
        ],
    ];
    //
    //
    // common table's info
    protected $insertColumns = [
        'code',
        self::COLUMN_NAME,
        'phone_country',
        'language',
        'currency',
        self::COLUMN_CREATED,
        self::COLUMN_UPDATED,
    ];
    //
    protected $insertRows = [
        ['UK',  'United Kingdom',   '44',   'EN', 'GBP'],
        ['USA', 'United States',    '1',    'EN', 'USD'],
        ['UA',  'Ukraine',          '380',  'RU', 'UAH'],
    ];

}

class m000000_000000_tbl_country extends Migration implements DbMapInterface
{
    // common table's info
    protected $tableName = self::TABLE_COUNTRY;
}