m170503_140828_create_customer_table.php 2.05 KB
<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation of table `customer`.
     */
    class m170503_140828_create_customer_table extends Migration
    {
        /**
         * @inheritdoc
         */
        public function safeUp()
        {
            $this->createTable(
                'customer',
                [
                    'id'                   => $this->primaryKey(),
                    'username'             => $this->string()
                                                   ->notNull()
                                                   ->unique(),
                    'auth_key'             => $this->string(32)
                                                   ->notNull(),
                    'password_hash'        => $this->string()
                                                   ->notNull(),
                    'password_reset_token' => $this->string()
                                                   ->unique(),
                    'email'                => $this->string()
                                                   ->notNull()
                                                   ->unique(),
                    
                    'status'     => $this->smallInteger()
                                         ->notNull()
                                         ->defaultValue(10),
                    'created_at' => $this->integer()
                                         ->notNull(),
                    'updated_at' => $this->integer()
                                         ->notNull(),
                    'name'       => $this->string(),
                    'phone'      => $this->string(),
                    'gender'     => $this->smallInteger(1),
                    'birthday'   => $this->integer(),
                    'city'       => $this->string(),
                    'address'    => $this->string(),
                ]
            );
        }
        
        /**
         * @inheritdoc
         */
        public function safeDown()
        {
            $this->dropTable('customer');
        }
    }