m150401_100610_create_table__shop_pay_system.php 2.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<?php
/**
 * @author Semenov Alexander <semenov@skeeks.com>
 * @link http://skeeks.com/
 * @copyright 2010 SkeekS (СкикС)
 * @date 01.04.2015
 */
use yii\db\Schema;
use yii\db\Migration;

class m150401_100610_create_table__shop_pay_system extends Migration
{
    public function safeUp()
    {
        $tableExist = $this->db->getTableSchema("{{%shop_pay_system}}", true);
        if ($tableExist)
        {
            return true;
        }

        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
        }

        $this->createTable("{{%shop_pay_system}}", [
            'id'                    => Schema::TYPE_PK,

            'created_by'            => Schema::TYPE_INTEGER . ' NULL',
            'updated_by'            => Schema::TYPE_INTEGER . ' NULL',

            'created_at'            => Schema::TYPE_INTEGER . ' NULL',
            'updated_at'            => Schema::TYPE_INTEGER . ' NULL',

            'currency'              => Schema::TYPE_STRING. '(3) DEFAULT "RUB"',

            'name'                  => Schema::TYPE_STRING . '(255) NOT NULL',
            'description'           => Schema::TYPE_TEXT . ' NULL',

40
            'active'                => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1',
41 42 43 44 45 46 47 48 49 50 51


        ], $tableOptions);

        $this->execute("ALTER TABLE {{%shop_pay_system}} ADD INDEX(updated_by);");
        $this->execute("ALTER TABLE {{%shop_pay_system}} ADD INDEX(created_by);");

        $this->execute("ALTER TABLE {{%shop_pay_system}} ADD INDEX(created_at);");
        $this->execute("ALTER TABLE {{%shop_pay_system}} ADD INDEX(updated_at);");

        $this->execute("ALTER TABLE {{%shop_pay_system}} ADD INDEX(currency);");
52
        $this->execute("ALTER TABLE {{%shop_pay_system}} ADD INDEX(active);");
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        $this->execute("ALTER TABLE {{%shop_pay_system}} ADD INDEX(name);");


        $this->execute("ALTER TABLE {{%shop_pay_system}} COMMENT = 'Платежные системы';");

        $this->addForeignKey(
            'shop_pay_system_created_by', "{{%shop_pay_system}}",
            'created_by', '{{%cms_user}}', 'id', 'SET NULL', 'SET NULL'
        );

        $this->addForeignKey(
            'shop_pay_system_updated_by', "{{%shop_pay_system}}",
            'updated_by', '{{%cms_user}}', 'id', 'SET NULL', 'SET NULL'
        );
    }

    public function safeDown()
    {
        $this->dropForeignKey("shop_pay_system_updated_by", "{{%shop_pay_system}}");
        $this->dropForeignKey("shop_pay_system_updated_by", "{{%shop_pay_system}}");

        $this->dropTable("{{%shop_pay_system}}");
    }
}