* @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 01.04.2015 */ use yii\db\Schema; use yii\db\Migration; class m150401_100601_create_table__shop_person_type extends Migration { public function safeUp() { $tableExist = $this->db->getTableSchema("{{%shop_person_type}}", 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_person_type}}", [ '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', 'name' => Schema::TYPE_STRING . '(255) NOT NULL', 'active' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1', //статус, активна некативна, удалено 'form_id' => Schema::TYPE_INTEGER . ' NULL', //Форма с данными и полями ], $tableOptions); $this->execute("ALTER TABLE {{%shop_person_type}} ADD INDEX(updated_by);"); $this->execute("ALTER TABLE {{%shop_person_type}} ADD INDEX(created_by);"); $this->execute("ALTER TABLE {{%shop_person_type}} ADD INDEX(created_at);"); $this->execute("ALTER TABLE {{%shop_person_type}} ADD INDEX(updated_at);"); $this->execute("ALTER TABLE {{%shop_person_type}} ADD INDEX(active);"); $this->execute("ALTER TABLE {{%shop_person_type}} ADD INDEX(form_id);"); $this->execute("ALTER TABLE {{%shop_person_type}} ADD INDEX(name);"); $this->execute("ALTER TABLE {{%shop_person_type}} COMMENT = 'Типы плательщика';"); $this->addForeignKey( 'shop_person_type_created_by', "{{%shop_person_type}}", 'created_by', '{{%cms_user}}', 'id', 'SET NULL', 'SET NULL' ); $this->addForeignKey( 'shop_person_type_updated_by', "{{%shop_person_type}}", 'updated_by', '{{%cms_user}}', 'id', 'SET NULL', 'SET NULL' ); $this->addForeignKey( 'shop_person_type_form_form', "{{%shop_person_type}}", 'form_id', '{{%form_form}}', 'id', 'RESTRICT', 'RESTRICT' ); } public function safeDown() { $this->dropForeignKey("shop_person_type_updated_by", "{{%shop_person_type}}"); $this->dropForeignKey("shop_person_type_updated_by", "{{%shop_person_type}}"); $this->dropForeignKey("shop_person_type_form_form", "{{%shop_person_type}}"); $this->dropTable("{{%shop_person_type}}"); } }