id(); $table->string('name', 100); $table->string('slug', 120)->unique(); $table->text('description')->nullable(); $table->string('cover_path', 300)->nullable(); // open: jeder tritt bei | closed: sichtbar, Beitritt auf Anfrage | secret: unsichtbar, nur auf Einladung $table->string('privacy', 10)->default('open'); $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete(); $table->unsignedInteger('members_count')->default(0); $table->unsignedInteger('posts_count')->default(0); $table->timestamp('last_activity_at')->nullable()->index(); $table->timestamps(); }); Schema::create('gruppen_members', function (Blueprint $table) { $table->foreignId('group_id')->constrained('gruppen_groups')->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->string('role', 10)->default('member'); // admin | moderator | member $table->string('status', 10)->default('active'); // active | pending | invited $table->foreignId('invited_by')->nullable()->constrained('users')->nullOnDelete(); $table->string('notify', 10)->default('all'); // all | off $table->timestamp('joined_at')->nullable(); $table->timestamp('last_seen_at')->nullable(); $table->timestamp('notified_at')->nullable(); $table->timestamps(); $table->primary(['group_id', 'user_id']); $table->index(['user_id', 'status']); }); Schema::create('gruppen_posts', function (Blueprint $table) { $table->id(); $table->foreignId('group_id')->constrained('gruppen_groups')->cascadeOnDelete(); $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete(); $table->text('body')->nullable(); $table->json('poll')->nullable(); // { options: [...], multiple: bool } $table->timestamp('pinned_at')->nullable(); $table->timestamp('edited_at')->nullable(); $table->unsignedInteger('comments_count')->default(0); $table->timestamps(); $table->index(['group_id', 'created_at']); }); Schema::create('gruppen_attachments', function (Blueprint $table) { $table->id(); $table->foreignId('post_id')->constrained('gruppen_posts')->cascadeOnDelete(); $table->string('path', 300); $table->string('thumb_path', 300)->nullable(); $table->string('name', 200); $table->string('mime', 100); $table->unsignedBigInteger('size'); $table->unsignedInteger('width')->nullable(); $table->unsignedInteger('height')->nullable(); $table->unsignedSmallInteger('sort')->default(0); }); Schema::create('gruppen_poll_votes', function (Blueprint $table) { $table->foreignId('post_id')->constrained('gruppen_posts')->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->unsignedTinyInteger('option'); $table->primary(['post_id', 'user_id', 'option']); }); Schema::create('gruppen_comments', function (Blueprint $table) { $table->id(); $table->foreignId('post_id')->constrained('gruppen_posts')->cascadeOnDelete(); $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete(); $table->foreignId('parent_id')->nullable()->constrained('gruppen_comments')->cascadeOnDelete(); $table->text('body'); $table->timestamp('edited_at')->nullable(); $table->timestamps(); $table->index(['post_id', 'id']); }); Schema::create('gruppen_reactions', function (Blueprint $table) { $table->foreignId('post_id')->constrained('gruppen_posts')->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->string('emoji', 16); $table->primary(['post_id', 'user_id']); }); Schema::create('gruppen_reports', function (Blueprint $table) { $table->id(); $table->foreignId('group_id')->constrained('gruppen_groups')->cascadeOnDelete(); $table->foreignId('post_id')->constrained('gruppen_posts')->cascadeOnDelete(); $table->foreignId('comment_id')->nullable()->constrained('gruppen_comments')->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->string('reason', 500); $table->timestamp('resolved_at')->nullable(); $table->timestamps(); $table->unique(['user_id', 'post_id', 'comment_id']); }); } public function down(): void { foreach (['gruppen_reports', 'gruppen_reactions', 'gruppen_comments', 'gruppen_poll_votes', 'gruppen_attachments', 'gruppen_posts', 'gruppen_members', 'gruppen_groups'] as $table) { Schema::dropIfExists($table); } } };