m160217_092739_currency_table.php 1.79 KB
<?php

    use yii\db\Migration;

    class m160217_092739_currency_table extends Migration
    {

        public function up()
        {
            $this->createTable('{{%currency}}', [
                'currency_id' => $this->primaryKey(),
                'name'        => $this->string(),
                'symbol'      => $this->string(),
                'code'        => $this->string(3),
                'rate'        => $this->float(4),
                'date_update' => $this->timestamp()->defaultExpression('NOW()')
                                      ->notNull(),
                'is_default' => $this->smallInteger(),
            ]);
            $this->batchInsert('{{%currency}}', [
                'currency_id',
                'name',
                'symbol',
                'code',
                'rate',
                'is_default',
            ], [
                [
                    1,
                    'Доллар США',
                    '$',
                    'USD',
                    27.31,
                    0,
                ],
                [
                    2,
                    'Евро',
                    '€',
                    'EUR',
                    30.28,
                    0
                ],
                [
                    3,
                    'Украинская гривна',
                    '₴',
                    'UAH',
                    1,
                    1,
                ],
                [
                    4,
                    'Российский рубль',
                    '₽',
                    'RUB',
                    0.34,
                    0,
                ],
            ]);
        }

        public function down()
        {
            $this->dropTable('{{%currency}}');
        }
    }