diff --git a/database/migrations/2021_06_08_113437_create_posts_table.php b/database/migrations/2021_06_08_113437_create_posts_table.php index 6cfd5c9c..1014ac3f 100644 --- a/database/migrations/2021_06_08_113437_create_posts_table.php +++ b/database/migrations/2021_06_08_113437_create_posts_table.php @@ -27,7 +27,6 @@ class CreatePostsTable extends Migration $table->dateTime('editdate')->nullable(); $table->index(['topicid', 'id'], 'topicid_id'); }); - \Illuminate\Support\Facades\DB::statement('alter table posts add fulltext body(body)'); } /** diff --git a/database/migrations/2021_06_08_113437_create_torrents_custom_field_values_table.php b/database/migrations/2021_06_08_113437_create_torrents_custom_field_values_table.php index bd10d4f7..cf68b2b2 100644 --- a/database/migrations/2021_06_08_113437_create_torrents_custom_field_values_table.php +++ b/database/migrations/2021_06_08_113437_create_torrents_custom_field_values_table.php @@ -24,7 +24,12 @@ class CreateTorrentsCustomFieldValuesTable extends Migration $table->dateTime('created_at'); $table->dateTime('updated_at'); }); - \Illuminate\Support\Facades\DB::statement('alter table torrents_custom_field_values add index(custom_field_value(191))'); + if (\Nexus\Database\NexusDB::isMysql()) { + \Illuminate\Support\Facades\DB::statement('alter table torrents_custom_field_values add index(custom_field_value(191))'); + } else if (Nexus\Database\NexusDB::isPgsql()) { + \Illuminate\Support\Facades\DB::statement('alter table torrents_custom_field_values left(custom_field_value,191)'); + } + } /** diff --git a/database/migrations/2021_06_08_113437_create_torrents_table.php b/database/migrations/2021_06_08_113437_create_torrents_table.php index 5287a597..48f90059 100644 --- a/database/migrations/2021_06_08_113437_create_torrents_table.php +++ b/database/migrations/2021_06_08_113437_create_torrents_table.php @@ -18,6 +18,7 @@ class CreateTorrentsTable extends Migration } Schema::create('torrents', function (Blueprint $table) { $table->mediumIncrements('id'); + $table->binary('info_hash', 20)->nullable()->unique(); $table->string('name')->default('')->index('name'); $table->string('filename')->default(''); $table->string('save_as')->default(''); @@ -58,14 +59,13 @@ class CreateTorrentsTable extends Migration $table->dateTime('picktime')->nullable(); $table->dateTime('last_reseed')->nullable(); $table->mediumText('pt_gen')->nullable(); -// $table->integer('tags')->default(0); $table->text('technical_info')->nullable(); $table->index(['visible', 'pos_state', 'id'], 'visible_pos_id'); $table->index(['category', 'visible', 'banned'], 'category_visible_banned'); $table->index(['visible', 'banned', 'pos_state', 'id'], 'visible_banned_pos_id'); }); - $sql = 'alter table torrents add column `info_hash` binary(20) NOT NULL after id, add unique info_hash(`info_hash`)'; - \Illuminate\Support\Facades\DB::statement($sql); +// $sql = 'alter table torrents add column `info_hash` binary(20) NOT NULL after id, add unique info_hash(`info_hash`)'; +// \Illuminate\Support\Facades\DB::statement($sql); } /** diff --git a/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php b/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php index 8d1f57fb..4fbfaecb 100644 --- a/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php +++ b/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php @@ -13,6 +13,10 @@ return new class extends Migration */ public function up() { + if (\Nexus\Database\NexusDB::isPgsql()) { + //fresh install no need + return; + } $tableFields = \App\Repositories\UpgradeRepository::DATETIME_INVALID_VALUE_FIELDS; foreach ($tableFields as $table => $fields) { diff --git a/database/migrations/2022_04_18_030257_handle_peers_peer_id_unique.php b/database/migrations/2022_04_18_030257_handle_peers_peer_id_unique.php index f0e7d848..7c134340 100644 --- a/database/migrations/2022_04_18_030257_handle_peers_peer_id_unique.php +++ b/database/migrations/2022_04_18_030257_handle_peers_peer_id_unique.php @@ -15,23 +15,23 @@ return new class extends Migration public function up() { $tableName = 'peers'; - $result = DB::select('show index from ' . $tableName); - $indexToDrop = []; - foreach ($result as $item) { - if (in_array($item->Column_name, ['torrent', 'peer_id'])) { - $indexToDrop[$item->Key_name] = "drop index " . $item->Key_name; + $columnNames = ['torrent', 'peer_id']; + // 1. 获取该表所有的索引信息 + $indexesToDelete = \Nexus\Database\NexusDB::listColumnIndexNames($tableName, $columnNames); + + // 3. 执行删除操作 + Schema::table($tableName, function (Blueprint $table) use ($indexesToDelete) { + foreach ($indexesToDelete as $indexName) { + // 如果是主键,需要单独处理 + if ($indexName === 'primary') { + $table->dropPrimary(); + } else { + $table->dropIndex($indexName); + } } - } - if (!empty($indexToDrop)) { - $sql = sprintf("alter table %s %s", $tableName, implode(', ', $indexToDrop)); - DB::statement($sql); - } - - $sql = "alter table $tableName add index idx_torrent_peer(`torrent`, `peer_id`(20))"; - DB::statement($sql); - - $sql = "alter table $tableName add index idx_peer(`peer_id`(20))"; - DB::statement($sql); + $table->index(['torrent', 'peer_id']); + $table->index('peer_id'); + }); } diff --git a/database/migrations/2023_03_29_021950_handle_snatched_user_torrent_unique.php b/database/migrations/2023_03_29_021950_handle_snatched_user_torrent_unique.php index d77fac0a..a607a597 100644 --- a/database/migrations/2023_03_29_021950_handle_snatched_user_torrent_unique.php +++ b/database/migrations/2023_03_29_021950_handle_snatched_user_torrent_unique.php @@ -4,6 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\DB; +use Nexus\Database\NexusDB; return new class extends Migration { @@ -15,26 +16,24 @@ return new class extends Migration 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; + $columnNames = ['torrentid', 'userid']; + // 1. 获取该表所有的索引信息 + $indexesToDelete = NexusDB::listColumnIndexNames($tableName, $columnNames); + + // 3. 执行删除操作 + Schema::table($tableName, function (Blueprint $table) use ($indexesToDelete) { + foreach ($indexesToDelete as $indexName) { + // 如果是主键,需要单独处理 + if ($indexName === 'primary') { + $table->dropPrimary(); + } else { + $table->dropIndex($indexName); } - $indexToDrop[$item->Key_name] = "drop index " . $item->Key_name; } - } - if (!empty($indexToDrop)) { - $sql = sprintf("alter table %s %s", $tableName, implode(', ', $indexToDrop)); - DB::statement($sql); - } + $table->unique(['torrentid', 'userid']); + $table->index('userid'); + }); - $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); } /** diff --git a/database/migrations/2023_04_01_005409_add_unique_torrent_peer_user_to_peers_table.php b/database/migrations/2023_04_01_005409_add_unique_torrent_peer_user_to_peers_table.php index 908ed19b..1c356171 100644 --- a/database/migrations/2023_04_01_005409_add_unique_torrent_peer_user_to_peers_table.php +++ b/database/migrations/2023_04_01_005409_add_unique_torrent_peer_user_to_peers_table.php @@ -15,15 +15,24 @@ return new class extends Migration 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; + $columnNames = ['torrent', 'peer_id', 'userid']; + // 1. 获取该表所有的索引信息 + $indexesToDelete = \Nexus\Database\NexusDB::listColumnIndexNames($tableName, $columnNames); + + // 3. 执行删除操作 + Schema::table($tableName, function (Blueprint $table) use ($indexesToDelete) { + foreach ($indexesToDelete as $indexName) { + // 如果是主键,需要单独处理 + if ($indexName === 'primary') { + $table->dropPrimary(); + } else { + $table->dropIndex($indexName); + } } - } - DB::statement("alter table $tableName add unique unique_torrent_peer_user(`torrent`, `peer_id`, `userid`)"); + $table->unique(['torrent', 'peer_id', 'userid']); + $table->index('peer_id'); + $table->index('userid'); + }); } diff --git a/database/migrations/2024_02_24_004527_alter_table_torrents_change_field_cache_stamp_to_int.php b/database/migrations/2024_02_24_004527_alter_table_torrents_change_field_cache_stamp_to_int.php index ad92f3fb..56bb04c7 100644 --- a/database/migrations/2024_02_24_004527_alter_table_torrents_change_field_cache_stamp_to_int.php +++ b/database/migrations/2024_02_24_004527_alter_table_torrents_change_field_cache_stamp_to_int.php @@ -13,10 +13,10 @@ return new class extends Migration */ public function up() { - $columnInfo = \Nexus\Database\NexusDB::getMysqlColumnInfo("torrents", "cache_stamp"); - if ($columnInfo["DATA_TYPE"] == "int") { - return; - } +// $columnInfo = \Nexus\Database\NexusDB::getMysqlColumnInfo("torrents", "cache_stamp"); +// if ($columnInfo["DATA_TYPE"] == "int") { +// return; +// } Schema::table('torrents', function (Blueprint $table) { $table->integer("cache_stamp")->default(0)->change(); }); diff --git a/database/migrations/2024_10_13_035900_change_torrents_table_info_hash_nullable.php b/database/migrations/2024_10_13_035900_change_torrents_table_info_hash_nullable.php index 1906a12f..5b8725db 100644 --- a/database/migrations/2024_10_13_035900_change_torrents_table_info_hash_nullable.php +++ b/database/migrations/2024_10_13_035900_change_torrents_table_info_hash_nullable.php @@ -13,8 +13,9 @@ return new class extends Migration */ public function up() { - $sql = 'ALTER table torrents MODIFY column `info_hash` binary(20) DEFAULT NULL'; - \Illuminate\Support\Facades\DB::statement($sql); + Schema::table('torrents', function (Blueprint $table) { + $table->binary('info_hash', 20)->nullable()->change(); + }); } /** diff --git a/database/migrations/2025_06_04_153154_update_invalid_datetime_value.php b/database/migrations/2025_06_04_153154_update_invalid_datetime_value.php index 775cce11..a2eb1c25 100644 --- a/database/migrations/2025_06_04_153154_update_invalid_datetime_value.php +++ b/database/migrations/2025_06_04_153154_update_invalid_datetime_value.php @@ -11,6 +11,9 @@ return new class extends Migration */ public function up(): void { + if (\Nexus\Database\NexusDB::isPgsql()) { + return; + } $tableFields = \App\Repositories\UpgradeRepository::DATETIME_INVALID_VALUE_FIELDS; foreach ($tableFields as $table => $fields) { diff --git a/include/eloquent.php b/include/eloquent.php index e14eaece..97c9a6ce 100644 --- a/include/eloquent.php +++ b/include/eloquent.php @@ -1,7 +1,7 @@ listTimeZone(); } + if ($name == 'DB_CONNECTION') { + $item['type'] = 'select'; + $item['options'] = ['mysql', 'pgsql']; + } $formControls[] = $item; }