* @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 01.04.2015 */ use yii\db\Schema; use yii\db\Migration; class m150401_100620_create_table__shop_delivery extends Migration { public function safeUp() { $tableExist = $this->db->getTableSchema("{{%shop_delivery}}", 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_delivery}}", [ '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) NULL DEFAULT "RUB"', 'name' => Schema::TYPE_STRING . '(255) NOT NULL', 'description' => Schema::TYPE_TEXT . ' NULL', 'period_from' => Schema::TYPE_INTEGER . ' NULL', 'period_to' => Schema::TYPE_INTEGER . ' NULL', 'period_type' => Schema::TYPE_STRING . '(1) NULL', 'weight_from' => Schema::TYPE_INTEGER . ' NULL', 'weight_to' => Schema::TYPE_INTEGER . ' NULL', 'order_price_from' => Schema::TYPE_DECIMAL . '(18,2) NULL', 'order_price_to' => Schema::TYPE_DECIMAL . '(18,2) NULL', 'order_currency' => Schema::TYPE_STRING . '(3) NULL', 'active' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1', 'price' => Schema::TYPE_DECIMAL . '(18,2)', 'currency' => Schema::TYPE_STRING. '(3) DEFAULT "RUB"', ], $tableOptions); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(updated_by);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(created_by);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(created_at);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(updated_at);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(currency);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(active);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(name);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(period_from);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(period_to);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(weight_from);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(weight_to);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(order_price_from);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(order_price_to);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(order_currency);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(price);"); $this->execute("ALTER TABLE {{%shop_delivery}} ADD INDEX(currency);"); $this->execute("ALTER TABLE {{%shop_delivery}} COMMENT = 'Система доставки';"); $this->addForeignKey( 'shop_delivery_created_by', "{{%shop_delivery}}", 'created_by', '{{%cms_user}}', 'id', 'SET NULL', 'SET NULL' ); $this->addForeignKey( 'shop_delivery_updated_by', "{{%shop_delivery}}", 'updated_by', '{{%cms_user}}', 'id', 'SET NULL', 'SET NULL' ); } public function safeDown() { $this->dropForeignKey("shop_delivery_updated_by", "{{%shop_delivery}}"); $this->dropForeignKey("shop_delivery_updated_by", "{{%shop_delivery}}"); $this->dropTable("{{%shop_delivery}}"); } }