M1: 数据模型 + sablog:import 脚本(MySQL 8 验证通过,不迁移 trackback 等过时功能)

This commit is contained in:
ak
2026-08-11 17:40:13 +08:00
parent 8d526a8cfd
commit f16bb75538
17 changed files with 1010 additions and 13 deletions
@@ -16,7 +16,7 @@ return new class extends Migration
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('password')->nullable();
$table->rememberToken();
$table->timestamps();
});
@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name', 50);
$table->string('slug', 120)->nullable()->unique();
$table->tinyInteger('display_order')->default(0);
$table->unsignedInteger('post_count')->default(0);
$table->timestamps();
});
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('title');
$table->string('slug', 255)->nullable()->unique();
$table->text('excerpt')->nullable();
$table->longText('content');
$table->string('keywords', 255)->nullable();
$table->string('status', 20)->default('published')->index();
$table->boolean('is_sticky')->default(false);
$table->boolean('close_comment')->default(false);
$table->string('read_password', 255)->nullable();
$table->unsignedBigInteger('views')->default(0);
$table->unsignedInteger('comment_count')->default(0);
$table->json('meta')->nullable();
$table->timestamp('published_at')->nullable()->index();
$table->timestamps();
$table->index(['status', 'published_at']);
});
}
public function down(): void
{
Schema::dropIfExists('posts');
Schema::dropIfExists('categories');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('comments', function (Blueprint $table) {
$table->id();
$table->foreignId('post_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('author_name', 50);
$table->string('author_email', 255)->nullable();
$table->string('author_url', 255)->nullable();
$table->mediumText('content');
$table->string('ip', 64)->nullable();
$table->string('status', 20)->default('pending')->index();
$table->json('ai_review')->nullable();
$table->timestamp('created_at')->useCurrent();
$table->index(['post_id', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('comments');
}
};
@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('links', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->string('url', 255);
$table->string('note', 255)->nullable();
$table->tinyInteger('display_order')->default(0);
$table->boolean('visible')->default(true);
$table->timestamps();
});
Schema::create('settings', function (Blueprint $table) {
$table->string('key')->primary();
$table->text('value');
$table->timestamps();
});
Schema::create('plugin_records', function (Blueprint $table) {
$table->id();
$table->string('vendor', 60);
$table->string('name', 60);
$table->string('version', 40)->nullable();
$table->boolean('enabled')->default(true);
$table->timestamps();
$table->unique(['vendor', 'name']);
});
}
public function down(): void
{
Schema::dropIfExists('plugin_records');
Schema::dropIfExists('settings');
Schema::dropIfExists('links');
}
};
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('legacy_md5', 32)->nullable()->index();
$table->string('url', 255)->nullable();
$table->unsignedInteger('logincount')->default(0);
$table->string('loginip', 64)->nullable();
$table->string('regip', 64)->nullable();
$table->timestamp('logintime')->nullable();
$table->timestamp('lastpost_at')->nullable();
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn([
'legacy_md5', 'url', 'logincount', 'loginip', 'regip', 'logintime', 'lastpost_at',
]);
});
}
};
+30 -10
View File
@@ -2,24 +2,44 @@
namespace Database\Seeders;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Role;
class DatabaseSeeder extends Seeder
{
use WithoutModelEvents;
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
foreach (['admin', 'editor', 'member'] as $role) {
Role::findOrCreate($role);
}
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
$admin = User::query()->firstOrCreate(
['email' => 'admin@laralog.test'],
[
'name' => '管理员',
'password' => Hash::make('password'),
]
);
$admin->assignRole('admin');
Setting::seedDefaults([
'site_name' => config('blog.name'),
'site_description' => config('blog.description'),
'site_icp' => config('blog.icp'),
'active_theme' => 'sablog',
'comment_audit' => '0',
'comment_min_len' => (string) config('blog.comment_min_len'),
'comment_max_len' => (string) config('blog.comment_max_len'),
'comment_post_space' => (string) config('blog.comment_post_space'),
'comment_order' => '1',
'rss_num' => (string) config('blog.rss_num'),
'seo_default_keywords' => '',
'seo_default_description' => '',
'site_closed' => '0',
'site_closed_note' => '系统升级中...',
]);
}
}