thinkphp5 migration demo

<?php

use think\migration\Migrator;
use think\migration\db\Column;

class SurveyAnswer extends Migrator
{
    public function up()
    {
        $table = $this->table('survey_answer', ['comment' => '調查問卷答題表']);
        if ($table->exists()) {
            $table->addColumn('user_id', 'integer', ['default' => 0, 'comment' => '用戶表id'])
                ->addColumn('question_id', 'integer', ['default' => 0, 'comment' => '調查問卷問題表id'])
                ->addColumn('choice_id', 'integer', ['default' => 0, 'comment' => '調查問卷選項表id'])
                ->addColumn('answer', 'string', ['length' => 255, 'default' => '', 'comment' => '文本問題輸入值'])
                ->addColumn('create_by', 'integer', ['default' => 0, 'comment' => '建立者'])
                ->addColumn('create_time', 'integer', ['default' => 0, 'comment' => '建立時間'])
                ->create();
        }
    }
    
    public function change()
    {
        $table = $this->table('survey_answer');
        if ($table->exists()) {
            //todo
        }
    }


    public function down() 
    {
        $this->dropTable('survey_answer');
    }
}
相關文章
相關標籤/搜索