init
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled

This commit is contained in:
jiangdong.cheng
2026-02-11 17:28:36 +08:00
parent dcb82557c7
commit aa16c9f8c2
162 changed files with 22333 additions and 0 deletions

1
database/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.sqlite*

View File

@@ -0,0 +1,44 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}

View File

@@ -0,0 +1,55 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasTable('users')) {
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
if (! Schema::hasTable('password_reset_tokens')) {
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
if (! Schema::hasTable('sessions')) {
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};

View File

@@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasTable('cache')) {
Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration')->index();
});
}
if (! Schema::hasTable('cache_locks')) {
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration')->index();
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};

View File

@@ -0,0 +1,63 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasTable('jobs')) {
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
if (! Schema::hasTable('job_batches')) {
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
}
if (! Schema::hasTable('failed_jobs')) {
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
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): void {
$table->id();
$table->string('type', 32);
$table->string('name', 120);
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index(['type', 'is_active']);
});
}
public function down(): void
{
Schema::dropIfExists('categories');
}
};

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
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('tags', function (Blueprint $table): void {
$table->id();
$table->string('name', 120);
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('is_active');
});
}
public function down(): void
{
Schema::dropIfExists('tags');
}
};

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
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('sources', function (Blueprint $table): void {
$table->id();
$table->string('name', 150);
$table->string('domain', 255)->unique();
$table->string('type', 32)->default('media');
$table->string('trust_level', 32)->default('trusted_media');
$table->boolean('is_whitelisted')->default(true);
$table->boolean('crawl_allowed')->default(false);
$table->text('note')->nullable();
$table->timestamps();
$table->index(['is_whitelisted', 'trust_level']);
});
}
public function down(): void
{
Schema::dropIfExists('sources');
}
};

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
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('tools', function (Blueprint $table): void {
$table->id();
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('source_id')->nullable()->constrained()->nullOnDelete();
$table->string('name', 160);
$table->string('slug')->unique();
$table->string('summary', 260);
$table->longText('description')->nullable();
$table->string('official_url', 2048)->nullable();
$table->string('pricing_type', 32)->default('freemium');
$table->string('platform', 64)->nullable();
$table->string('language', 64)->nullable();
$table->boolean('has_api')->default(false);
$table->string('source_level', 32)->default('unknown');
$table->timestamp('last_verified_at')->nullable();
$table->string('status', 32)->default('draft');
$table->boolean('is_stale')->default(false);
$table->text('stale_note')->nullable();
$table->foreignId('alternative_tool_id')->nullable()->constrained('tools')->nullOnDelete();
$table->string('seo_title', 180)->nullable();
$table->string('seo_description', 320)->nullable();
$table->string('h1', 180)->nullable();
$table->string('canonical_url', 2048)->nullable();
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->index(['status', 'is_stale', 'published_at']);
$table->index(['category_id', 'pricing_type']);
$table->index(['source_level', 'last_verified_at']);
$table->fullText(['name', 'summary', 'description']);
});
}
public function down(): void
{
Schema::dropIfExists('tools');
}
};

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
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('ai_models', function (Blueprint $table): void {
$table->id();
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('source_id')->nullable()->constrained()->nullOnDelete();
$table->string('name', 160);
$table->string('slug')->unique();
$table->string('provider', 120)->nullable();
$table->string('summary', 260);
$table->longText('description')->nullable();
$table->string('modality', 64)->default('text');
$table->unsignedInteger('context_window')->nullable();
$table->decimal('price_input', 12, 6)->nullable();
$table->decimal('price_output', 12, 6)->nullable();
$table->string('deployment_mode', 32)->default('api');
$table->unsignedTinyInteger('effectiveness_score')->default(60);
$table->unsignedTinyInteger('price_score')->default(60);
$table->unsignedTinyInteger('speed_score')->default(60);
$table->unsignedTinyInteger('total_score')->default(60);
$table->string('source_level', 32)->default('unknown');
$table->timestamp('last_verified_at')->nullable();
$table->string('status', 32)->default('draft');
$table->boolean('is_stale')->default(false);
$table->text('stale_note')->nullable();
$table->foreignId('alternative_model_id')->nullable()->constrained('ai_models')->nullOnDelete();
$table->string('seo_title', 180)->nullable();
$table->string('seo_description', 320)->nullable();
$table->string('h1', 180)->nullable();
$table->string('canonical_url', 2048)->nullable();
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->index(['status', 'is_stale', 'published_at']);
$table->index(['modality', 'deployment_mode']);
$table->index(['total_score', 'effectiveness_score']);
$table->fullText(['name', 'summary', 'description']);
});
}
public function down(): void
{
Schema::dropIfExists('ai_models');
}
};

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
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('articles', function (Blueprint $table): void {
$table->id();
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('source_id')->nullable()->constrained()->nullOnDelete();
$table->string('title', 200);
$table->string('slug')->unique();
$table->string('excerpt', 320);
$table->longText('body');
$table->string('source_name', 160)->nullable();
$table->string('source_url', 2048)->nullable();
$table->string('source_level', 32)->default('unknown');
$table->timestamp('last_verified_at')->nullable();
$table->string('status', 32)->default('draft');
$table->boolean('is_stale')->default(false);
$table->text('stale_note')->nullable();
$table->string('seo_title', 180)->nullable();
$table->string('seo_description', 320)->nullable();
$table->string('h1', 180)->nullable();
$table->string('canonical_url', 2048)->nullable();
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->index(['status', 'published_at']);
$table->index(['is_stale', 'last_verified_at']);
$table->fullText(['title', 'excerpt', 'body']);
});
}
public function down(): void
{
Schema::dropIfExists('articles');
}
};

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
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('guides', function (Blueprint $table): void {
$table->id();
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
$table->string('title', 200);
$table->string('slug')->unique();
$table->string('excerpt', 320);
$table->longText('body');
$table->string('difficulty', 32)->default('beginner');
$table->string('status', 32)->default('draft');
$table->string('seo_title', 180)->nullable();
$table->string('seo_description', 320)->nullable();
$table->string('h1', 180)->nullable();
$table->string('canonical_url', 2048)->nullable();
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->index(['status', 'published_at']);
$table->index(['difficulty', 'published_at']);
$table->fullText(['title', 'excerpt', 'body']);
});
}
public function down(): void
{
Schema::dropIfExists('guides');
}
};

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
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('entity_tag_maps', function (Blueprint $table): void {
$table->id();
$table->foreignId('tag_id')->constrained()->cascadeOnDelete();
$table->string('entity_type', 64);
$table->unsignedBigInteger('entity_id');
$table->timestamps();
$table->unique(['tag_id', 'entity_type', 'entity_id'], 'entity_tag_maps_unique');
$table->index(['entity_type', 'entity_id']);
});
}
public function down(): void
{
Schema::dropIfExists('entity_tag_maps');
}
};

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('change_logs')) {
Schema::create('change_logs', function (Blueprint $table): void {
$table->id();
$table->string('entity_type', 64);
$table->unsignedBigInteger('entity_id');
$table->string('action', 64);
$table->json('before_data')->nullable();
$table->json('after_data')->nullable();
$table->unsignedBigInteger('changed_by')->nullable();
$table->timestamp('changed_at')->useCurrent();
$table->timestamps();
$table->index(['entity_type', 'entity_id', 'changed_at']);
$table->index('action');
$table->index('changed_by');
});
}
}
public function down(): void
{
Schema::dropIfExists('change_logs');
}
};

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
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('tools', function (Blueprint $table): void {
if (!Schema::hasColumn('tools', 'logo_url')) {
$table->string('logo_url', 2048)->nullable()->after('official_url');
}
});
}
public function down(): void
{
Schema::table('tools', function (Blueprint $table): void {
if (Schema::hasColumn('tools', 'logo_url')) {
$table->dropColumn('logo_url');
}
});
}
};

View File

@@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
namespace Database\Seeders;
use App\Enums\EntityStatus;
use App\Enums\SourceLevel;
use App\Models\AiModel;
use App\Models\Article;
use App\Models\Category;
use App\Models\Guide;
use App\Models\Source;
use App\Models\Tool;
use App\Services\ModelScoringService;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$categories = collect([
['type' => 'tool', 'name' => '写作与办公', 'slug' => 'writing-office'],
['type' => 'tool', 'name' => '图像与设计', 'slug' => 'image-design'],
['type' => 'model', 'name' => '大语言模型', 'slug' => 'llm'],
['type' => 'model', 'name' => '多模态模型', 'slug' => 'multimodal'],
['type' => 'news', 'name' => '行业动态', 'slug' => 'industry-news'],
['type' => 'guide', 'name' => '新手入门', 'slug' => 'beginner-guide'],
])->map(fn (array $payload) => Category::query()->updateOrCreate(['slug' => $payload['slug']], $payload));
$source = Source::query()->updateOrCreate(
['domain' => 'openai.com'],
[
'name' => 'OpenAI',
'type' => 'official',
'trust_level' => SourceLevel::Official,
'is_whitelisted' => true,
'crawl_allowed' => false,
],
);
$tool = Tool::query()->updateOrCreate(
['slug' => 'chat-assistant-pro'],
[
'category_id' => $categories->firstWhere('slug', 'writing-office')?->id,
'source_id' => $source->id,
'name' => 'Chat Assistant Pro',
'summary' => '用于写作、表格处理和知识问答的AI助手。',
'description' => '支持文案生成、会议纪要整理和多语言翻译。',
'pricing_type' => 'freemium',
'platform' => 'web',
'language' => 'zh-CN/en-US',
'has_api' => true,
'source_level' => SourceLevel::Official,
'status' => EntityStatus::Published,
'published_at' => now()->subDays(7),
'last_verified_at' => now()->subDays(1),
],
);
$model = AiModel::query()->updateOrCreate(
['slug' => 'omni-text-1'],
[
'category_id' => $categories->firstWhere('slug', 'llm')?->id,
'source_id' => $source->id,
'name' => 'Omni Text 1',
'provider' => 'OpenAI',
'summary' => '高质量通用文本生成模型,适合内容生产与客服场景。',
'description' => '可用于摘要、问答、分类、结构化抽取。',
'modality' => 'text',
'deployment_mode' => 'api',
'effectiveness_score' => 90,
'price_score' => 72,
'speed_score' => 80,
'status' => EntityStatus::Published,
'published_at' => now()->subDays(6),
'last_verified_at' => now()->subDays(1),
'source_level' => SourceLevel::Official,
],
);
$modelScoringService = app(ModelScoringService::class);
$modelScoringService->apply($model);
$model->save();
Article::query()->updateOrCreate(
['slug' => 'ai-product-weekly-sample'],
[
'category_id' => $categories->firstWhere('slug', 'industry-news')?->id,
'source_id' => $source->id,
'title' => 'AI产品周报示例本周模型与工具更新',
'excerpt' => '汇总本周AI模型升级、工具发布与重要行业动向。',
'body' => Str::repeat('这是资讯示例内容用于演示发布流程与SEO模板。', 20),
'source_name' => 'OpenAI',
'source_url' => 'https://openai.com',
'source_level' => SourceLevel::Official,
'status' => EntityStatus::Published,
'published_at' => now()->subDays(5),
'last_verified_at' => now()->subDays(1),
],
);
Guide::query()->updateOrCreate(
['slug' => 'first-ai-workflow'],
[
'category_id' => $categories->firstWhere('slug', 'beginner-guide')?->id,
'title' => '第一套AI工作流从需求到输出',
'excerpt' => '给跨界学习者的AI工作流入门教程。',
'body' => Str::repeat('这是教程示例内容,覆盖提示词、质量校验和结果复用。', 25),
'difficulty' => 'beginner',
'status' => EntityStatus::Published,
'published_at' => now()->subDays(4),
],
);
}
}