Skip to content

Commit

Permalink
Merge pull request #10700 from nanaya/table-aliases
Browse files Browse the repository at this point in the history
Alias some score tables
  • Loading branch information
peppy authored Nov 6, 2023
2 parents 02015c2 + 5cd6c7c commit 91259f7
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/Models/Multiplayer/ScoreLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function complete(ScoreToken $token, array $params): static
public $timestamps = false;

protected $primaryKey = 'score_id';
protected $table = 'multiplayer_score_links';
protected $table = 'multiplayer_playlist_item_scores';

public function playlistItem(): BelongsTo
{
Expand Down
2 changes: 0 additions & 2 deletions app/Models/ScoreToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
*/
class ScoreToken extends Model
{
protected $table = 'solo_score_tokens';

public function beatmap()
{
return $this->belongsTo(Beatmap::class, 'beatmap_id');
Expand Down
1 change: 0 additions & 1 deletion app/Models/Solo/Score.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Score extends Model implements Traits\ReportableInterface

const PROCESSING_QUEUE = 'osu-queue:score-statistics';

protected $table = 'solo_scores';
protected $casts = [
'data' => ScoreData::class,
'has_replay' => 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Solo/ScorePerformance.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ class ScorePerformance extends Model
public $timestamps = false;

protected $primaryKey = 'score_id';
protected $table = 'solo_scores_performance';
protected $table = 'score_performance';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
private const ALIASES = [
'multiplayer_score_links' => 'multiplayer_playlist_item_scores',
'solo_score_tokens' => 'score_tokens',
'solo_scores' => 'scores',
'solo_scores_legacy_id_map' => 'score_legacy_id_map',
'solo_scores_performance' => 'score_performance',
'solo_scores_process_history' => 'score_process_history',
];

public function up(): void
{
foreach (static::ALIASES as $current => $alias) {
DB::statement("CREATE VIEW {$alias} AS SELECT * FROM {$current}");
}
}

public function down(): void
{
foreach (static::ALIASES as $alias) {
DB::statement("DROP VIEW {$alias}");
}
}
};
2 changes: 1 addition & 1 deletion tests/Controllers/BeatmapsControllerSoloScoresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static function tearDownAfterClass(): void
Genre::truncate();
Group::truncate();
Language::truncate();
SoloScore::truncate();
SoloScore::select()->delete(); // TODO: revert to truncate after the table is actually renamed
User::truncate();
UserGroup::truncate();
UserGroupEvent::truncate();
Expand Down
4 changes: 2 additions & 2 deletions tests/Jobs/RemoveBeatmapsetSoloScoresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function testHandle()
Genre::truncate();
Group::truncate();
Language::truncate();
Score::truncate();
ScorePerformance::truncate();
Score::select()->delete(); // TODO: revert to truncate after the table is actually renamed
ScorePerformance::select()->delete(); // TODO: revert to truncate after the table is actually renamed
User::truncate();
UserGroup::truncate();
UserGroupEvent::truncate();
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Solo/ScoreEsIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function tearDownAfterClass(): void
Genre::truncate();
Group::truncate();
Language::truncate();
Score::truncate();
Score::select()->delete(); // TODO: revert to truncate after the table is actually renamed
User::truncate();
UserGroup::truncate();
UserGroupEvent::truncate();
Expand Down

0 comments on commit 91259f7

Please sign in to comment.