mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
clean peers + snatched table unique
This commit is contained in:
@@ -27,10 +27,10 @@ return new class extends Migration
|
||||
DB::statement($sql);
|
||||
}
|
||||
|
||||
$sql = "alter table peers add index idx_torrent_peer(`torrent`, `peer_id`(20))";
|
||||
$sql = "alter table $tableName add index idx_torrent_peer(`torrent`, `peer_id`(20))";
|
||||
DB::statement($sql);
|
||||
|
||||
$sql = "alter table peers add index idx_peer(`peer_id`(20))";
|
||||
$sql = "alter table $tableName add index idx_peer(`peer_id`(20))";
|
||||
DB::statement($sql);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$tableName = 'snatched';
|
||||
$result = DB::select('show index from ' . $tableName);
|
||||
$indexToDrop = [];
|
||||
foreach ($result as $item) {
|
||||
if (in_array($item->Column_name, ['torrentid', 'userid'])) {
|
||||
if ($item->Non_unique == 0) {
|
||||
return;
|
||||
}
|
||||
$indexToDrop[$item->Key_name] = "drop index " . $item->Key_name;
|
||||
}
|
||||
}
|
||||
if (!empty($indexToDrop)) {
|
||||
$sql = sprintf("alter table %s %s", $tableName, implode(', ', $indexToDrop));
|
||||
DB::statement($sql);
|
||||
}
|
||||
|
||||
$sql = "alter table $tableName add unique unique_torrent_user(`torrentid`, `userid`)";
|
||||
DB::statement($sql);
|
||||
|
||||
$sql = "alter table $tableName add index idx_user(`userid`)";
|
||||
DB::statement($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$tableName = 'peers';
|
||||
$result = DB::select('show index from ' . $tableName);
|
||||
$toDropIndex = 'idx_torrent_peer';
|
||||
foreach ($result as $item) {
|
||||
if ($item->Key_name == $toDropIndex) {
|
||||
DB::statement("alter table $tableName drop index $toDropIndex");
|
||||
break;
|
||||
}
|
||||
}
|
||||
DB::statement("alter table $tableName add unique unique_torrent_peer_user(`torrent`, `peer_id`, `userid`)");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('peers', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user