Make tables smaller

This commit is contained in:
myrmidex 2025-06-28 02:47:46 +02:00
parent 9e2babb298
commit 941ef99d32
4 changed files with 70 additions and 4 deletions

View file

@ -9,9 +9,7 @@ public function up(): void {
Capsule::schema()->create('articles', function (Blueprint $table) { Capsule::schema()->create('articles', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('url')->unique(); $table->string('url')->unique();
$table->string('title')->nullable(); $table->timestamp('created_at')->useCurrent();
$table->json('data')->nullable();
$table->timestamp('seen_at')->useCurrent();
}); });
} }

View file

@ -11,7 +11,6 @@ public function up(): void {
$table->foreignId('article_id')->constrained('articles')->onDelete('cascade'); $table->foreignId('article_id')->constrained('articles')->onDelete('cascade');
$table->string('community'); $table->string('community');
$table->timestamp('posted_at')->useCurrent(); $table->timestamp('posted_at')->useCurrent();
$table->json('response')->nullable();
}); });
} }

View file

@ -0,0 +1,39 @@
<?php
namespace Domain\Articles;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Article extends Model
{
protected $table = 'articles';
protected $fillable = [
'url',
'title',
'data',
'seen_at',
];
public $timestamps = false;
protected $casts = [
'seen_at' => 'datetime',
'data' => 'array',
];
public function posts(): HasMany
{
return $this->hasMany(ArticlePosted::class);
}
public function publish(string $community = 'default'): void
{
ArticlePosted::create([
'article_id' => $this->id,
'community' => $community,
'posted_at' => now(),
]);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Domain\Articles;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ArticlePosted extends Model
{
protected $table = 'article_posted';
protected $fillable = [
'article_id',
'community',
'posted_at',
'response',
];
public $timestamps = false;
protected $casts = [
'posted_at' => 'datetime',
'response' => 'array',
];
public function article(): BelongsTo
{
return $this->belongsTo(Article::class);
}
}