From a8bd7ea7c697d0b8feae7c3279dbaa8a596305e7 Mon Sep 17 00:00:00 2001 From: Phan An Date: Sat, 29 Apr 2017 11:49:14 +0800 Subject: [PATCH] Rename contributing_artist_id to simple artist_id --- .../API/ObjectStorage/S3/SongController.php | 2 +- app/Models/ContributingArtist.php | 8 ----- app/Models/File.php | 2 +- app/Models/Song.php | 8 ++--- app/Services/Media.php | 6 ++-- ...9_025836_rename_contributing_artist_id.php | 32 +++++++++++++++++++ resources/assets/js/stores/song.js | 4 +-- resources/assets/js/tests/blobs/data.js | 28 ++++++++-------- resources/assets/js/tests/stores/queueTest.js | 2 +- tests/BrowserKitTestCase.php | 2 +- tests/Feature/MediaTest.php | 2 +- tests/Feature/SongTest.php | 10 +++--- 12 files changed, 64 insertions(+), 42 deletions(-) delete mode 100644 app/Models/ContributingArtist.php create mode 100644 database/migrations/2017_04_29_025836_rename_contributing_artist_id.php diff --git a/app/Http/Controllers/API/ObjectStorage/S3/SongController.php b/app/Http/Controllers/API/ObjectStorage/S3/SongController.php index 8b3e2a7b..d04a7eca 100644 --- a/app/Http/Controllers/API/ObjectStorage/S3/SongController.php +++ b/app/Http/Controllers/API/ObjectStorage/S3/SongController.php @@ -36,7 +36,7 @@ class SongController extends Controller $song = Song::updateOrCreate(['id' => Media::getHash($path)], [ 'path' => $path, 'album_id' => $album->id, - 'contributing_artist_id' => $artist->id, + 'artist_id' => $artist->id, 'title' => trim(array_get($tags, 'title', '')), 'length' => array_get($tags, 'duration', 0), 'track' => (int) array_get($tags, 'track'), diff --git a/app/Models/ContributingArtist.php b/app/Models/ContributingArtist.php deleted file mode 100644 index 9f4c1847..00000000 --- a/app/Models/ContributingArtist.php +++ /dev/null @@ -1,8 +0,0 @@ -id; - $info['contributing_artist_id'] = $artist->id; + $info['artist_id'] = $artist->id; // Remove these values from the info array, so that we can just use the array as model's input data. array_forget($info, ['artist', 'albumartist', 'album', 'cover', 'compilation']); diff --git a/app/Models/Song.php b/app/Models/Song.php index eb4bc70d..d283e1c7 100644 --- a/app/Models/Song.php +++ b/app/Models/Song.php @@ -15,7 +15,6 @@ use YouTube; * @property string path * @property string title * @property Album album - * @property int contributing_artist_id * @property Artist artist * @property string s3_params * @property float length @@ -46,7 +45,6 @@ class Song extends Model 'length' => 'float', 'mtime' => 'int', 'track' => 'int', - 'contributing_artist_id' => 'int', ]; /** @@ -58,7 +56,7 @@ class Song extends Model public function artist() { - return $this->belongsTo(ContributingArtist::class, 'contributing_artist_id'); + return $this->belongsTo(Artist::class); } public function album() @@ -160,7 +158,7 @@ class Song extends Model } return [ - 'artists' => Artist::whereIn('id', $updatedSongs->pluck('contributing_artist_id'))->get(), + 'artists' => Artist::whereIn('id', $updatedSongs->pluck('artist_id'))->get(), 'albums' => Album::whereIn('id', $updatedSongs->pluck('album_id'))->get(), 'songs' => $updatedSongs, ]; @@ -203,7 +201,7 @@ class Song extends Model $album = Album::get($artist, $albumName, $isCompilation); - $this->contributing_artist_id = $artist->id; + $this->artist_id = $artist->id; $this->album_id = $album->id; $this->title = $title; $this->lyrics = $lyrics; diff --git a/app/Services/Media.php b/app/Services/Media.php index dc03dd5a..21d36ea4 100644 --- a/app/Services/Media.php +++ b/app/Services/Media.php @@ -233,10 +233,10 @@ class Media Album::deleteWhereIDsNotIn($inUseAlbums); $inUseArtists = Song::distinct() - ->select('contributing_artist_id') - ->groupBy('contributing_artist_id') + ->select('artist_id') + ->groupBy('artist_id') ->get() - ->pluck('contributing_artist_id') + ->pluck('artist_id') ->toArray(); $inUseArtists[] = Artist::UNKNOWN_ID; $inUseArtists[] = Artist::VARIOUS_ID; diff --git a/database/migrations/2017_04_29_025836_rename_contributing_artist_id.php b/database/migrations/2017_04_29_025836_rename_contributing_artist_id.php new file mode 100644 index 00000000..89ed1518 --- /dev/null +++ b/database/migrations/2017_04_29_025836_rename_contributing_artist_id.php @@ -0,0 +1,32 @@ +renameColumn('contributing_artist_id', 'artist_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('songs', function ($table) { + $table->renameColumn('artist_id', 'contributing_artist_id'); + }); + } +} diff --git a/resources/assets/js/stores/song.js b/resources/assets/js/stores/song.js index 8c625439..0e6c9c60 100644 --- a/resources/assets/js/stores/song.js +++ b/resources/assets/js/stores/song.js @@ -44,7 +44,7 @@ export const songStore = { song.fmtLength = secondsToHis(song.length) const album = albumStore.byId(song.album_id) - const artist = artistStore.byId(song.contributing_artist_id) + const artist = artistStore.byId(song.artist_id) // Manually set these additional properties to be reactive Vue.set(song, 'playCount', song.playCount || 0) @@ -244,7 +244,7 @@ export const songStore = { originalSong.album.songs = without(originalSong.album.songs, originalSong) } - if (originalSong.contributing_artist_id !== song.contributing_artist_id) { + if (originalSong.artist_id !== song.artist_id) { // artist has been changed. Remove the song from its old artist originalSong.artist.songs = without(originalSong.artist.songs, originalSong) } diff --git a/resources/assets/js/tests/blobs/data.js b/resources/assets/js/tests/blobs/data.js index 316f229a..37b8d7d5 100644 --- a/resources/assets/js/tests/blobs/data.js +++ b/resources/assets/js/tests/blobs/data.js @@ -70,7 +70,7 @@ export default { { id: '39189f4545f9d5671fb3dc964f0080a0', album_id: 1193, - contributing_artist_id: 3, + artist_id: 3, title: 'I Swear', length: 259.92, playCount: 4 @@ -78,7 +78,7 @@ export default { { id: 'a6a550f7d950d2a2520f9bf1a60f025a', album_id: 1194, - contributing_artist_id: 3, + artist_id: 3, title: 'I can love you like that', length: 262.61, playCount: 2 @@ -86,84 +86,84 @@ export default { { id: 'd86c30fd34f13c1aff8db59b7fc9c610', album_id: 1195, - contributing_artist_id: 3, + artist_id: 3, title: 'I turn to you', length: 293.04 }, { id: 'e6d3977f3ffa147801ca5d1fdf6fa55e', album_id: 1217, - contributing_artist_id: 4, + artist_id: 4, title: 'Like a rolling stone', length: 373.63 }, { id: 'aa16bbef6a9710eb9a0f41ecc534fad5', album_id: 1218, - contributing_artist_id: 4, + artist_id: 4, title: "Knockin' on heaven's door", length: 151.9 }, { id: 'cb7edeac1f097143e65b1b2cde102482', album_id: 1219, - contributing_artist_id: 4, + artist_id: 4, title: "The times they are a-changin'", length: 196 }, { id: '0ba9fb128427b32683b9eb9140912a70', album_id: 1268, - contributing_artist_id: 5, + artist_id: 5, title: 'No bravery', length: 243.12 }, { id: '123fd1ad32240ecab28a4e86ed5173', album_id: 1268, - contributing_artist_id: 5, + artist_id: 5, title: 'So long, Jimmy', length: 265.04 }, { id: '6a54c674d8b16732f26df73f59c63e21', album_id: 1268, - contributing_artist_id: 5, + artist_id: 5, title: 'Wisemen', length: 223.14 }, { id: '6df7d82a9a8701e40d1c291cf14a16bc', album_id: 1268, - contributing_artist_id: 5, + artist_id: 5, title: 'Goodbye my lover', length: 258.61 }, { id: '74a2000d343e4587273d3ad14e2fd741', album_id: 1268, - contributing_artist_id: 5, + artist_id: 5, title: 'High', length: 245.86 }, { id: '7900ab518f51775fe6cf06092c074ee5', album_id: 1268, - contributing_artist_id: 5, + artist_id: 5, title: "You're beautiful", length: 213.29 }, { id: '803910a51f9893347e087af851e38777', album_id: 1268, - contributing_artist_id: 5, + artist_id: 5, title: 'Cry', length: 246.91 }, { id: 'd82b0d4d4803ebbcb61000a5b6a868f5', album_id: 1268, - contributing_artist_id: 5, + artist_id: 5, title: 'Tears and rain', length: 244.45 } diff --git a/resources/assets/js/tests/stores/queueTest.js b/resources/assets/js/tests/stores/queueTest.js index 47695a69..33144146 100644 --- a/resources/assets/js/tests/stores/queueTest.js +++ b/resources/assets/js/tests/stores/queueTest.js @@ -5,7 +5,7 @@ import data from '../blobs/data' const { songs: allSongs } = data // only get the songs by James Blunt -const songs = allSongs.filter(song => song.contributing_artist_id === 5) +const songs = allSongs.filter(song => song.artist_id === 5) describe('stores/queue', () => { beforeEach(() => { diff --git a/tests/BrowserKitTestCase.php b/tests/BrowserKitTestCase.php index 8fa8d69c..c5b584a8 100644 --- a/tests/BrowserKitTestCase.php +++ b/tests/BrowserKitTestCase.php @@ -81,7 +81,7 @@ abstract class BrowserKitTestCase extends BaseBrowserKitTestCase foreach ($albums as $album) { factory(Song::class, random_int(7, 15))->create([ 'album_id' => $album->id, - 'contributing_artist_id' => $artist->id, + 'artist_id' => $artist->id, ]); } } diff --git a/tests/Feature/MediaTest.php b/tests/Feature/MediaTest.php index 0f1bd783..b54f54e7 100644 --- a/tests/Feature/MediaTest.php +++ b/tests/Feature/MediaTest.php @@ -62,7 +62,7 @@ class MediaTest extends BrowserKitTestCase // Compilation albums, artists and songs must be recognized $song = Song::whereTitle('This song belongs to a compilation')->first(); - $this->assertNotNull($song->contributing_artist_id); + $this->assertNotNull($song->artist_id); $this->assertTrue($song->album->is_compilation); $this->assertEquals(Artist::VARIOUS_ID, $song->album->artist_id); diff --git a/tests/Feature/SongTest.php b/tests/Feature/SongTest.php index f909ed3d..296a3325 100644 --- a/tests/Feature/SongTest.php +++ b/tests/Feature/SongTest.php @@ -182,7 +182,7 @@ class SongTest extends BrowserKitTestCase $this->seeInDatabase('songs', [ 'id' => $song->id, - 'contributing_artist_id' => $artist->id, + 'artist_id' => $artist->id, 'album_id' => $compilationAlbum->id, 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, @@ -211,7 +211,7 @@ class SongTest extends BrowserKitTestCase $this->seeInDatabase('songs', [ 'id' => $song->id, - 'contributing_artist_id' => $contributingArtist->id, + 'artist_id' => $contributingArtist->id, 'album_id' => $compilationAlbum->id, ]); @@ -237,7 +237,7 @@ class SongTest extends BrowserKitTestCase $this->seeInDatabase('songs', [ 'id' => $song->id, - 'contributing_artist_id' => $contributingArtist->id, + 'artist_id' => $contributingArtist->id, 'album_id' => $compilationAlbum->id, ]); @@ -262,7 +262,7 @@ class SongTest extends BrowserKitTestCase $this->seeInDatabase('songs', [ 'id' => $song->id, - 'contributing_artist_id' => $artist->id, + 'artist_id' => $artist->id, 'album_id' => $album->id, ]); @@ -298,7 +298,7 @@ class SongTest extends BrowserKitTestCase $this->assertNotNull($album); $this->seeInDatabase('songs', [ 'id' => $song->id, - 'contributing_artist_id' => $artist->id, + 'artist_id' => $artist->id, 'album_id' => $album->id, 'lyrics' => 'Thor! Nanananananana Batman.', // haha ]);