update: fulfill requests with torrent id instead of info_hash

This commit is contained in:
Roardom
2022-12-23 15:53:57 -06:00
parent aa064cc840
commit fc0235e39b
60 changed files with 140 additions and 114 deletions
+5 -5
View File
@@ -23,10 +23,10 @@ class TorrentRequestFactory extends Factory
'category_id' => fn () => Category::factory()->create()->id,
'type_id' => fn () => Type::factory()->create()->id,
'resolution_id' => fn () => Resolution::factory()->create()->id,
'imdb' => $this->faker->word(),
'tvdb' => $this->faker->word(),
'tmdb' => $this->faker->word(),
'mal' => $this->faker->word(),
'imdb' => $this->faker->randomNumber(),
'tvdb' => $this->faker->randomNumber(),
'tmdb' => $this->faker->randomNumber(),
'mal' => $this->faker->randomNumber(),
'igdb' => $this->faker->word(),
'description' => $this->faker->text(),
'user_id' => fn () => User::factory()->create()->id,
@@ -35,7 +35,7 @@ class TorrentRequestFactory extends Factory
'claimed' => $this->faker->boolean(),
'anon' => $this->faker->boolean(),
'filled_by' => fn () => User::factory()->create()->id,
'filled_hash' => fn () => Torrent::factory()->create()->id,
'torrent_id' => fn () => Torrent::factory()->create()->id,
'filled_when' => $this->faker->dateTime(),
'filled_anon' => $this->faker->boolean(),
'approved_by' => fn () => User::factory()->create()->id,
@@ -0,0 +1,34 @@
<?php
use App\Models\TorrentRequest;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('requests', function (Blueprint $table) {
$table->unsignedInteger('torrent_id')->nullable()->after('filled_hash');
$table->foreign('torrent_id')->references('id')->on('torrents')->cascadeOnUpdate()->cascadeOnDelete();
});
TorrentRequest::query()
->join('torrents', 'requests.filled_hash', 'torrents.info_hash')
->update([
'torrent_id' => DB::raw('torrents.id'),
'updated_at' => DB::raw('requests.updated_at'),
]);
Schema::table('requests', function (Blueprint $table) {
$table->dropIndex('filled_hash');
$table->dropColumn('filled_hash');
});
}
};