Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

feat: add ai_messages table and model

Paulo Castellano91e093018235
diff --git a/app/Models/AiMessage.php b/app/Models/AiMessage.php
new file mode 100644
index 000000000..26780b07b
--- /dev/null
+++ b/app/Models/AiMessage.php
@@ -0,0 +1,44 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Models;
+
+use Database\Factories\AiMessageFactory;
+use Illuminate\Database\Eloquent\Concerns\HasUuids;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class AiMessage extends Model
+{
+ /** @use HasFactory<AiMessageFactory> */
+ use HasFactory, HasUuids;
+
+ protected $fillable = [
+ 'post_id',
+ 'user_id',
+ 'role',
+ 'content',
+ 'attachments',
+ 'metadata',
+ ];
+
+ protected function casts(): array
+ {
+ return [
+ 'attachments' => 'array',
+ 'metadata' => 'array',
+ ];
+ }
+
+ public function post(): BelongsTo
+ {
+ return $this->belongsTo(Post::class);
+ }
+
+ public function user(): BelongsTo
+ {
+ return $this->belongsTo(User::class);
+ }
+}
diff --git a/app/Models/Post.php b/app/Models/Post.php
index 4d770ca08..4e870a4ce 100644
--- a/app/Models/Post.php
+++ b/app/Models/Post.php
@@ -69,6 +69,11 @@ class Post extends Model
return $this->hasMany(PostPlatform::class);
}
+ public function aiMessages(): HasMany
+ {
+ return $this->hasMany(AiMessage::class);
+ }
+
public function comments(): HasMany
{
return $this->hasMany(PostComment::class);
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index 669a43161..44ce5fc16 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -6,6 +6,7 @@ namespace App\Providers;
use App\Listeners\StripeEventListener;
use App\Models\Account;
+use App\Models\AiMessage;
use App\Models\Invite;
use App\Models\Media;
use App\Models\Notification;
@@ -90,6 +91,7 @@ class AppServiceProvider extends ServiceProvider
{
Relation::enforceMorphMap([
'account' => Account::class,
+ 'aiMessage' => AiMessage::class,
'invite' => Invite::class,
'media' => Media::class,
'notification' => Notification::class,
diff --git a/database/factories/AiMessageFactory.php b/database/factories/AiMessageFactory.php
new file mode 100644
index 000000000..d3515373e
--- /dev/null
+++ b/database/factories/AiMessageFactory.php
@@ -0,0 +1,33 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Database\Factories;
+
+use App\Models\AiMessage;
+use App\Models\Post;
+use App\Models\User;
+use Illuminate\Database\Eloquent\Factories\Factory;
+
+/** @extends Factory<AiMessage> */
+class AiMessageFactory extends Factory
+{
+ public function definition(): array
+ {
+ return [
+ 'post_id' => Post::factory(),
+ 'user_id' => User::factory(),
+ 'role' => 'user',
+ 'content' => $this->faker->sentence(),
+ 'attachments' => [],
+ ];
+ }
+
+ public function assistant(): static
+ {
+ return $this->state(fn () => [
+ 'role' => 'assistant',
+ 'user_id' => null,
+ ]);
+ }
+}
diff --git a/database/migrations/2026_04_15_000002_create_ai_messages_table.php b/database/migrations/2026_04_15_000002_create_ai_messages_table.php
new file mode 100644
index 000000000..51654b661
--- /dev/null
+++ b/database/migrations/2026_04_15_000002_create_ai_messages_table.php
@@ -0,0 +1,33 @@
+<?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_messages', function (Blueprint $table) {
+ $table->uuid('id')->primary();
+ $table->uuid('post_id');
+ $table->uuid('user_id')->nullable();
+ $table->string('role');
+ $table->text('content');
+ $table->json('attachments')->default('[]');
+ $table->json('metadata')->nullable();
+ $table->timestamps();
+
+ $table->foreign('post_id')->references('id')->on('posts')->cascadeOnDelete();
+ $table->foreign('user_id')->references('id')->on('users')->nullOnDelete();
+ $table->index(['post_id', 'created_at']);
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::dropIfExists('ai_messages');
+ }
+};