start project

This commit is contained in:
2026-05-15 16:33:34 +03:30
parent 553238b0fb
commit d756661b45
50 changed files with 3523 additions and 0 deletions

1
database/.gitignore vendored Normal file
View File

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

View File

@@ -0,0 +1,29 @@
<?php
namespace Database\Factories;
use App\Models\Broadcast;
use App\Models\Channel;
use Illuminate\Database\Eloquent\Factories\Factory;
class BroadcastFactory extends Factory
{
public function definition(): array
{
return [
'channel_id' => Channel::factory(),
'title' => fake()->sentence(4),
'status' => Broadcast::STATUS_PENDING,
'recording_enabled' => false,
];
}
public function live(): static
{
return $this->state(fn (array $attributes) => [
'status' => Broadcast::STATUS_LIVE,
'started_at' => now(),
'hls_url' => 'http://localhost:8888/demo/index.m3u8',
]);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class CategoryFactory extends Factory
{
public function definition(): array
{
$name = fake()->unique()->words(2, true);
return [
'name' => Str::headline($name),
'slug' => Str::slug($name),
'description' => fake()->optional()->sentence(),
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Database\Factories;
use App\Models\Category;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class ChannelFactory extends Factory
{
public function definition(): array
{
$name = fake()->unique()->words(2, true);
return [
'user_id' => User::factory(),
'category_id' => Category::factory(),
'slug' => Str::slug($name),
'display_name' => Str::headline($name),
'description' => fake()->sentence(),
'is_live' => false,
'viewer_count' => 0,
];
}
}

View File

@@ -0,0 +1,23 @@
<?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->boolean('is_admin')->default(false)->index();
$table->timestamp('suspended_at')->nullable()->index();
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['is_admin', 'suspended_at']);
});
}
};

View File

@@ -0,0 +1,119 @@
<?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')->unique();
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->timestamps();
});
Schema::create('channels', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->unique()->constrained()->cascadeOnDelete();
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
$table->unsignedBigInteger('live_broadcast_id')->nullable()->index();
$table->string('slug')->unique();
$table->string('display_name');
$table->text('description')->nullable();
$table->string('avatar_path')->nullable();
$table->string('banner_path')->nullable();
$table->string('thumbnail_path')->nullable();
$table->boolean('is_live')->default(false)->index();
$table->unsignedInteger('viewer_count')->default(0);
$table->timestamp('suspended_at')->nullable()->index();
$table->timestamps();
});
Schema::create('stream_keys', function (Blueprint $table) {
$table->id();
$table->foreignId('channel_id')->unique()->constrained()->cascadeOnDelete();
$table->string('key_hash');
$table->timestamp('last_used_at')->nullable();
$table->timestamp('revoked_at')->nullable()->index();
$table->timestamps();
});
Schema::create('broadcasts', function (Blueprint $table) {
$table->id();
$table->foreignId('channel_id')->constrained()->cascadeOnDelete();
$table->string('title');
$table->string('status')->default('pending')->index();
$table->boolean('recording_enabled')->default(false);
$table->string('mediamtx_path')->nullable()->index();
$table->string('source_type')->nullable();
$table->string('source_id')->nullable();
$table->string('hls_url')->nullable();
$table->unsignedInteger('viewer_peak')->default(0);
$table->timestamp('started_at')->nullable()->index();
$table->timestamp('ended_at')->nullable()->index();
$table->timestamps();
});
Schema::create('vods', function (Blueprint $table) {
$table->id();
$table->foreignId('broadcast_id')->unique()->constrained()->cascadeOnDelete();
$table->foreignId('channel_id')->constrained()->cascadeOnDelete();
$table->string('title');
$table->string('storage_path');
$table->string('playback_url')->nullable();
$table->unsignedInteger('duration_seconds')->nullable();
$table->unsignedBigInteger('size_bytes')->nullable();
$table->timestamp('published_at')->nullable()->index();
$table->timestamp('expires_at')->nullable()->index();
$table->softDeletes();
$table->timestamps();
});
Schema::create('follows', function (Blueprint $table) {
$table->id();
$table->foreignId('channel_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->timestamps();
$table->unique(['channel_id', 'user_id']);
});
Schema::create('chat_messages', function (Blueprint $table) {
$table->id();
$table->foreignId('channel_id')->constrained()->cascadeOnDelete();
$table->foreignId('broadcast_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('body', 500);
$table->softDeletes();
$table->timestamps();
});
Schema::create('admin_audit_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('admin_user_id')->nullable()->constrained('users')->nullOnDelete();
$table->string('subject_type');
$table->unsignedBigInteger('subject_id');
$table->string('action');
$table->json('metadata')->nullable();
$table->timestamp('created_at')->nullable();
$table->index(['subject_type', 'subject_id']);
});
}
public function down(): void
{
Schema::dropIfExists('admin_audit_logs');
Schema::dropIfExists('chat_messages');
Schema::dropIfExists('follows');
Schema::dropIfExists('vods');
Schema::dropIfExists('broadcasts');
Schema::dropIfExists('stream_keys');
Schema::dropIfExists('channels');
Schema::dropIfExists('categories');
}
};

View File

@@ -0,0 +1,38 @@
<?php
namespace Database\Seeders;
use App\Models\Category;
use App\Models\User;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
collect([
['name' => 'Gaming', 'slug' => 'gaming'],
['name' => 'Music', 'slug' => 'music'],
['name' => 'Talk Shows', 'slug' => 'talk-shows'],
['name' => 'Education', 'slug' => 'education'],
['name' => 'Creative', 'slug' => 'creative'],
])->each(fn (array $category) => Category::query()->firstOrCreate(
['slug' => $category['slug']],
['name' => $category['name']],
));
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
User::factory()->create([
'name' => 'Admin User',
'email' => 'admin@example.com',
'is_admin' => true,
]);
}
}