diff --git a/database/migrations/2024_01_01_000003_add_karma_to_users_table.php b/database/migrations/2024_01_01_000003_add_karma_to_users_table.php new file mode 100644 index 0000000..3c78297 --- /dev/null +++ b/database/migrations/2024_01_01_000003_add_karma_to_users_table.php @@ -0,0 +1,22 @@ +integer('karma')->default(0)->after('email'); + }); + } + + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('karma'); + }); + } +}; diff --git a/database/migrations/2024_01_01_000004_create_communities_table.php b/database/migrations/2024_01_01_000004_create_communities_table.php new file mode 100644 index 0000000..cde5a20 --- /dev/null +++ b/database/migrations/2024_01_01_000004_create_communities_table.php @@ -0,0 +1,25 @@ +id(); + $table->string('name')->unique(); + $table->string('slug')->unique(); + $table->text('description')->nullable(); + $table->foreignId('created_by')->constrained('users')->onDelete('cascade'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('communities'); + } +}; diff --git a/database/migrations/2024_01_01_000005_create_posts_table.php b/database/migrations/2024_01_01_000005_create_posts_table.php new file mode 100644 index 0000000..76d180e --- /dev/null +++ b/database/migrations/2024_01_01_000005_create_posts_table.php @@ -0,0 +1,31 @@ +id(); + $table->foreignId('community_id')->constrained()->onDelete('cascade'); + $table->foreignId('user_id')->constrained()->onDelete('cascade'); + $table->string('title'); + $table->text('content')->nullable(); + $table->string('url')->nullable(); + $table->enum('type', ['text', 'link', 'image'])->default('text'); + $table->integer('votes')->default(0); + $table->timestamps(); + + $table->index(['community_id', 'created_at']); + $table->index(['user_id', 'created_at']); + }); + } + + public function down(): void + { + Schema::dropIfExists('posts'); + } +}; diff --git a/database/migrations/2024_01_01_000006_create_comments_table.php b/database/migrations/2024_01_01_000006_create_comments_table.php new file mode 100644 index 0000000..bb7d0d5 --- /dev/null +++ b/database/migrations/2024_01_01_000006_create_comments_table.php @@ -0,0 +1,29 @@ +id(); + $table->foreignId('post_id')->constrained()->onDelete('cascade'); + $table->foreignId('user_id')->constrained()->onDelete('cascade'); + $table->foreignId('parent_id')->nullable()->constrained('comments')->onDelete('cascade'); + $table->text('content'); + $table->integer('votes')->default(0); + $table->timestamps(); + + $table->index(['post_id', 'created_at']); + $table->index(['parent_id', 'created_at']); + }); + } + + public function down(): void + { + Schema::dropIfExists('comments'); + } +}; diff --git a/database/migrations/2024_01_01_000007_create_votes_table.php b/database/migrations/2024_01_01_000007_create_votes_table.php new file mode 100644 index 0000000..a1343f0 --- /dev/null +++ b/database/migrations/2024_01_01_000007_create_votes_table.php @@ -0,0 +1,26 @@ +id(); + $table->foreignId('user_id')->constrained()->onDelete('cascade'); + $table->morphs('voteable'); + $table->tinyInteger('vote'); + $table->timestamps(); + + $table->unique(['user_id', 'voteable_id', 'voteable_type']); + }); + } + + public function down(): void + { + Schema::dropIfExists('votes'); + } +}; diff --git a/database/migrations/2024_01_01_000008_create_community_user_table.php b/database/migrations/2024_01_01_000008_create_community_user_table.php new file mode 100644 index 0000000..e296d32 --- /dev/null +++ b/database/migrations/2024_01_01_000008_create_community_user_table.php @@ -0,0 +1,25 @@ +id(); + $table->foreignId('community_id')->constrained()->onDelete('cascade'); + $table->foreignId('user_id')->constrained()->onDelete('cascade'); + $table->timestamps(); + + $table->unique(['community_id', 'user_id']); + }); + } + + public function down(): void + { + Schema::dropIfExists('community_user'); + } +};