Skip to content

Commit e1af230

Browse files
committed
refactor: mark columns as unsigned if negatives aren't expected
1 parent 6467d97 commit e1af230

File tree

2 files changed

+312
-58
lines changed

2 files changed

+312
-58
lines changed
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
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\DB;
20+
use Illuminate\Support\Facades\Schema;
21+
22+
return new class () extends Migration {
23+
/**
24+
* Run the migrations.
25+
*/
26+
public function up(): void
27+
{
28+
Schema::table('application_url_proofs', function (Blueprint $table): void {
29+
$table->unsignedInteger('application_id')->change();
30+
});
31+
32+
DB::table('automatic_torrent_freeleeches')->update([
33+
'freeleech_percentage' => DB::raw('GREATEST(0, freeleech_percentage)'),
34+
]);
35+
36+
Schema::table('automatic_torrent_freeleeches', function (Blueprint $table): void {
37+
$table->unsignedInteger('category_id')->nullable()->change();
38+
$table->unsignedInteger('type_id')->nullable()->change();
39+
$table->unsignedInteger('freeleech_percentage')->change();
40+
});
41+
42+
Schema::table('bon_transactions', function (Blueprint $table): void {
43+
$table->increments('id')->change();
44+
});
45+
46+
Schema::table('bots', function (Blueprint $table): void {
47+
$table->increments('id')->change();
48+
});
49+
50+
Schema::table('forum_permissions', function (Blueprint $table): void {
51+
$table->increments('id')->change();
52+
$table->unsignedInteger('group_id')->change();
53+
});
54+
55+
DB::table('forums')->update([
56+
'num_topic' => DB::raw('GREATEST(0, num_topic)'),
57+
'num_post' => DB::raw('GREATEST(0, num_post)'),
58+
]);
59+
60+
Schema::table('forums', function (Blueprint $table): void {
61+
$table->unsignedInteger('num_topic')->nullable()->change();
62+
$table->unsignedInteger('num_post')->nullable()->change();
63+
});
64+
65+
DB::table('groups')->update([
66+
'download_slots' => DB::raw('GREATEST(0, download_slots)'),
67+
]);
68+
69+
Schema::table('groups', function (Blueprint $table): void {
70+
$table->increments('id')->change();
71+
$table->unsignedInteger('download_slots')->nullable()->change();
72+
});
73+
74+
Schema::table('likes', function (Blueprint $table): void {
75+
$table->unsignedInteger('post_id')->change();
76+
});
77+
78+
DB::table('options')->update([
79+
'votes' => DB::raw('GREATEST(0, votes)'),
80+
]);
81+
82+
Schema::table('options', function (Blueprint $table): void {
83+
$table->unsignedInteger('votes')->default(0)->change();
84+
});
85+
86+
Schema::table('pages', function (Blueprint $table): void {
87+
$table->increments('id')->change();
88+
});
89+
90+
Schema::table('playlist_torrents', function (Blueprint $table): void {
91+
$table->unsignedInteger('playlist_id')->default(0)->change();
92+
});
93+
94+
Schema::table('request_bounty', function (Blueprint $table): void {
95+
$table->increments('id')->change();
96+
$table->unsignedInteger('requests_id')->change();
97+
});
98+
99+
Schema::table('request_claims', function (Blueprint $table): void {
100+
$table->unsignedInteger('request_id')->change();
101+
});
102+
103+
Schema::table('requests', function (Blueprint $table): void {
104+
$table->increments('id')->change();
105+
});
106+
107+
Schema::table('rss', function (Blueprint $table): void {
108+
$table->increments('id')->change();
109+
});
110+
111+
DB::table('subtitles')->update([
112+
'downloads' => DB::raw('GREATEST(0, downloads)'),
113+
]);
114+
115+
Schema::table('subtitles', function (Blueprint $table): void {
116+
$table->unsignedInteger('language_id')->change();
117+
$table->unsignedInteger('downloads')->nullable()->change();
118+
});
119+
120+
Schema::table('ticket_attachments', function (Blueprint $table): void {
121+
$table->unsignedInteger('ticket_id')->change();
122+
});
123+
124+
Schema::table('tickets', function (Blueprint $table): void {
125+
$table->unsignedSmallInteger('category_id')->change();
126+
$table->unsignedSmallInteger('priority_id')->change();
127+
});
128+
129+
DB::table('tmdb_movies')->update([
130+
'vote_count' => DB::raw('GREATEST(0, vote_count)'),
131+
]);
132+
133+
Schema::table('tmdb_movies', function (Blueprint $table): void {
134+
$table->unsignedInteger('vote_count')->nullable()->change();
135+
});
136+
137+
DB::table('tmdb_tv')->update([
138+
'number_of_episodes' => DB::raw('GREATEST(0, number_of_episodes)'),
139+
'count_existing_episodes' => DB::raw('GREATEST(0, count_existing_episodes)'),
140+
'count_total_episodes' => DB::raw('GREATEST(0, count_total_episodes)'),
141+
'number_of_seasons' => DB::raw('GREATEST(0, number_of_seasons)'),
142+
'vote_count' => DB::raw('GREATEST(0, vote_count)'),
143+
]);
144+
145+
Schema::table('tmdb_tv', function (Blueprint $table): void {
146+
$table->unsignedInteger('number_of_episodes')->nullable()->change();
147+
$table->unsignedInteger('count_existing_episodes')->nullable()->change();
148+
$table->unsignedInteger('count_total_episodes')->nullable()->change();
149+
$table->unsignedInteger('number_of_seasons')->nullable()->change();
150+
$table->unsignedInteger('vote_count')->nullable()->change();
151+
});
152+
153+
DB::table('topics')->update([
154+
'num_post' => DB::raw('GREATEST(0, num_post)'),
155+
'views' => DB::raw('GREATEST(0, views)'),
156+
]);
157+
158+
Schema::table('topics', function (Blueprint $table): void {
159+
$table->unsignedInteger('num_post')->nullable()->change();
160+
$table->unsignedInteger('views')->nullable()->change();
161+
});
162+
163+
DB::table('torrent_reseeds')->update([
164+
'requests_count' => DB::raw('GREATEST(0, requests_count)'),
165+
]);
166+
167+
Schema::table('torrent_reseeds', function (Blueprint $table): void {
168+
$table->unsignedInteger('requests_count')->default(0)->change();
169+
});
170+
171+
DB::table('torrents')->update([
172+
'num_file' => DB::raw('GREATEST(0, num_file)'),
173+
'season_number' => DB::raw('GREATEST(0, season_number)'),
174+
'episode_number' => DB::raw('GREATEST(0, episode_number)'),
175+
]);
176+
177+
Schema::table('torrents', function (Blueprint $table): void {
178+
$table->unsignedInteger('num_file')->change();
179+
$table->unsignedInteger('season_number')->nullable()->change();
180+
$table->unsignedInteger('episode_number')->nullable()->change();
181+
$table->unsignedInteger('moderated_by')->nullable()->change();
182+
$table->unsignedInteger('distributor_id')->nullable()->change();
183+
$table->unsignedInteger('region_id')->nullable()->change();
184+
});
185+
186+
Schema::table('user_audibles', function (Blueprint $table): void {
187+
$table->increments('id')->change();
188+
$table->unsignedInteger('room_id')->nullable()->change();
189+
$table->unsignedInteger('bot_id')->nullable()->change();
190+
});
191+
192+
Schema::table('user_echoes', function (Blueprint $table): void {
193+
$table->increments('id')->change();
194+
$table->unsignedInteger('room_id')->nullable()->change();
195+
$table->unsignedInteger('bot_id')->nullable()->change();
196+
});
197+
198+
Schema::table('user_notifications', function (Blueprint $table): void {
199+
$table->increments('id')->change();
200+
});
201+
202+
Schema::table('user_privacy', function (Blueprint $table): void {
203+
$table->increments('id')->change();
204+
});
205+
206+
Schema::table('users', function (Blueprint $table): void {
207+
$table->unsignedInteger('group_id')->change();
208+
});
209+
210+
// Posts
211+
212+
Schema::table('forums', function (Blueprint $table): void {
213+
$table->dropForeign(['last_post_id']);
214+
});
215+
216+
Schema::table('post_tips', function (Blueprint $table): void {
217+
$table->dropForeign(['post_id']);
218+
});
219+
220+
Schema::table('topic_reads', function (Blueprint $table): void {
221+
$table->dropForeign(['last_read_post_id']);
222+
});
223+
Schema::table('topics', function (Blueprint $table): void {
224+
$table->dropForeign(['last_post_id']);
225+
});
226+
227+
Schema::table('posts', function (Blueprint $table): void {
228+
$table->increments('id')->change();
229+
});
230+
231+
Schema::table('forums', function (Blueprint $table): void {
232+
$table->unsignedInteger('last_post_id')->nullable()->change();
233+
234+
$table->foreign('last_post_id')->references('id')->on('posts')->cascadeOnUpdate()->nullOnDelete();
235+
});
236+
237+
Schema::table('post_tips', function (Blueprint $table): void {
238+
$table->unsignedInteger('post_id')->nullable()->change();
239+
240+
$table->foreign('post_id')->references('id')->on('posts')->cascadeOnUpdate()->nullOnDelete();
241+
});
242+
Schema::table('topic_reads', function (Blueprint $table): void {
243+
$table->unsignedInteger('last_read_post_id')->change();
244+
245+
$table->foreign('last_read_post_id')->references('id')->on('posts')->cascadeOnUpdate()->cascadeOnDelete();
246+
});
247+
Schema::table('topics', function (Blueprint $table): void {
248+
$table->unsignedInteger('last_post_id')->nullable()->change();
249+
250+
$table->foreign('last_post_id')->references('id')->on('posts')->cascadeOnUpdate()->nullOnDelete();
251+
});
252+
}
253+
};

0 commit comments

Comments
 (0)