文档:数据库迁移

文档:数据库迁移

php
                   
use Zodream\Database\Migrations\Migration;
use Zodream\Database\Schema\Table;
use Module\SEO\Domain\Model\OptionModel;


class CreateSEOTables extends Migration {

    public function up() {
        $this->append(OptionModel::tableName(), function(Table $table) {
            $table->id();
            $table->string('name', 20);
        })->autoUp();
    }

    public function seed() {
        // 进行一些初始化数据插入
    }

}
12345678910111213141516171819

$this->autoUp() 会自动判断是安装还是卸载

Migration::createTable(string $table, callable $cb) 创建表,会自动更新已有表字段

Migration::dropTable(string|array $tables) 删除表