4
0
Fork 0
dcat-admin/packages/article/updates/CreateArticleTable.php

67 lines
2.7 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateArticleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('article_categories')) {
Schema::create('article_categories', function (Blueprint $table) {
$table->id();
$table->string('name')->comment('名称');
$table->string('key')->unique()->nullable()->comment('key');
$table->unsignedTinyInteger('is_recommend')->default(0)->comment('推荐状态');
$table->unsignedTinyInteger('is_enable')->default(1)->comment('可用状态');
$table->unsignedBigInteger('parent_id')->default(0)->comment('上级ID');
$table->unsignedInteger('level')->default(1)->comment('层级');
$table->string('path')->default('-')->comment('所有的父级ID');
$table->unsignedInteger('sort')->default(0)->comment('排序 desc');
$table->string('remarks')->nullable()->comment('备注');
$table->timestamps();
});
}
if (!Schema::hasTable('articles')) {
Schema::create('articles', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('category_id')->nullable()->comment('分类ID');
$table->string('category_path')->default('-')->comment('分类 path');
$table->unsignedBigInteger('admin_user_id')->comment('创建人');
$table->string('title')->comment('文章标题');
$table->string('sub_title')->nullable()->comment('副标题');
$table->string('author')->nullable()->comment('作者');
$table->string('cover')->nullable()->comment('封面');
$table->longText('content')->nullable()->comment('文章内容');
$table->timestamp('published_at')->nullable()->comment('发布时间');
$table->unsignedInteger('sort')->default(1)->comment('排序 desc');
$table->string('remarks')->nullable()->comment('备注');
$table->unsignedTinyInteger('is_recommend')->default(0)->comment('推荐状态');
$table->unsignedTinyInteger('is_enable')->default(1)->comment('可用状态');
$table->timestamps();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles');
Schema::dropIfExists('article_categories');
}
};