Skip to content

Commit c218434

Browse files
committed
fix: add foreign keys everywhere
1 parent 5992891 commit c218434

File tree

2 files changed

+184
-21
lines changed

2 files changed

+184
-21
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
use Illuminate\Database\Migrations\Migration;
18+
use Illuminate\Database\Schema\Blueprint;
19+
use Illuminate\Support\Facades\Schema;
20+
21+
return new class () extends Migration {
22+
/**
23+
* Run the migrations.
24+
*/
25+
public function up(): void
26+
{
27+
// Missing still:
28+
//
29+
// For performance:
30+
//
31+
// - announces.{user_id,torrent_id}
32+
//
33+
// Foreign records can be deleted but we want to retain these records with the deleted id for transaction history:
34+
//
35+
// - bon_transactions.bon_exchange_id
36+
// - donations.package_id
37+
//
38+
// The tmdb ids are stored before the movie/tv records are fetched via http:
39+
//
40+
// - requests.{tmdb_movie_id,tmdb_tv_id}
41+
// - torrents.{tmdb_movie_id,tmdb_tv_id}
42+
//
43+
// Chatbox needs a separate refactor:
44+
//
45+
// - messages.{bot_id,chatroom_id}
46+
// - user_audibles.{room_id,bot_id}
47+
// - user_echoes.{room_id,bot_id}
48+
49+
Schema::table('application_image_proofs', function (Blueprint $table): void {
50+
$table->dropIndex(['application_id']);
51+
$table->foreign('application_id')->references('id')->on('applications')->cascadeOnUpdate()->cascadeOnDelete();
52+
});
53+
54+
Schema::table('application_url_proofs', function (Blueprint $table): void {
55+
$table->dropIndex(['application_id']);
56+
$table->foreign('application_id')->references('id')->on('applications')->cascadeOnUpdate()->cascadeOnDelete();
57+
});
58+
59+
Schema::table('automatic_torrent_freeleeches', function (Blueprint $table): void {
60+
$table->unsignedSmallInteger('category_id')->nullable()->change();
61+
$table->unsignedSmallInteger('resolution_id')->nullable()->change();
62+
$table->unsignedSmallInteger('type_id')->nullable()->change();
63+
64+
$table->foreign('category_id')->references('id')->on('categories')->cascadeOnUpdate()->nullOnDelete();
65+
$table->foreign('type_id')->references('id')->on('types')->cascadeOnUpdate()->nullOnDelete();
66+
$table->foreign('resolution_id')->references('id')->on('resolutions')->cascadeOnUpdate()->nullOnDelete();
67+
});
68+
69+
Schema::table('donations', function (Blueprint $table): void {
70+
$table->dropIndex(['user_id']);
71+
$table->foreign('user_id')->references('id')->on('users')->cascadeOnUpdate();
72+
$table->dropIndex(['gifted_user_id']);
73+
$table->foreign('gifted_user_id')->references('id')->on('users')->cascadeOnUpdate()->nullOnDelete();
74+
});
75+
76+
Schema::table('forum_permissions', function (Blueprint $table): void {
77+
$table->dropIndex('fk_permissions_groups1_idx');
78+
$table->foreign('group_id')->references('id')->on('groups')->cascadeOnUpdate()->cascadeOnDelete();
79+
});
80+
81+
Schema::table('likes', function (Blueprint $table): void {
82+
$table->foreign('post_id')->references('id')->on('posts')->cascadeOnUpdate()->cascadeOnDelete();
83+
});
84+
85+
Schema::table('playlist_torrents', function (Blueprint $table): void {
86+
$table->dropIndex(['playlist_id']);
87+
$table->foreign('playlist_id')->references('id')->on('playlists')->cascadeOnUpdate()->cascadeOnDelete();
88+
});
89+
90+
Schema::table('reports', function (Blueprint $table): void {
91+
$table->dropIndex(['reported_request_id']);
92+
$table->foreign('reported_request_id')->references('id')->on('requests')->cascadeOnUpdate()->nullOnDelete();
93+
});
94+
95+
Schema::table('request_bounty', function (Blueprint $table): void {
96+
$table->dropIndex('request_id');
97+
$table->foreign('requests_id')->references('id')->on('requests')->cascadeOnUpdate()->cascadeOnDelete();
98+
});
99+
100+
Schema::table('request_claims', function (Blueprint $table): void {
101+
$table->dropIndex('request_id');
102+
$table->foreign('request_id')->references('id')->on('requests')->cascadeOnUpdate()->cascadeOnDelete();
103+
});
104+
105+
Schema::table('subtitles', function (Blueprint $table): void {
106+
$table->dropIndex(['language_id']);
107+
$table->foreign('language_id')->references('id')->on('media_languages')->cascadeOnUpdate()->cascadeOnDelete();
108+
});
109+
110+
Schema::table('ticket_attachments', function (Blueprint $table): void {
111+
$table->dropIndex(['ticket_id']);
112+
$table->foreign('ticket_id')->references('id')->on('tickets')->cascadeOnUpdate();
113+
});
114+
115+
Schema::table('tickets', function (Blueprint $table): void {
116+
$table->dropIndex(['category_id']);
117+
$table->foreign('category_id')->references('id')->on('ticket_categories')->cascadeOnUpdate();
118+
$table->dropIndex(['priority_id']);
119+
$table->foreign('priority_id')->references('id')->on('ticket_categories')->cascadeOnUpdate();
120+
});
121+
122+
Schema::table('torrents', function (Blueprint $table): void {
123+
$table->dropIndex(['distributor_id']);
124+
$table->foreign('distributor_id')->references('id')->on('distributors')->cascadeOnUpdate();
125+
$table->dropIndex(['region_id']);
126+
$table->foreign('region_id')->references('id')->on('regions')->cascadeOnUpdate();
127+
});
128+
129+
Schema::table('users', function (Blueprint $table): void {
130+
$table->dropIndex('fk_users_groups_idx');
131+
$table->foreign('group_id')->references('id')->on('groups')->cascadeOnUpdate();
132+
$table->foreign('chatroom_id')->references('id')->on('chatrooms')->cascadeOnUpdate();
133+
$table->foreign('chat_status_id')->references('id')->on('chat_statuses')->cascadeOnUpdate();
134+
});
135+
}
136+
};

0 commit comments

Comments
 (0)