* @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', 'active' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1', ], $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);"); $this->execute("ALTER TABLE {{%shop_pay_system}} ADD INDEX(active);"); $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}}"); } }