Closes #6: Implemented a "source" attribute for tracks.

This commit is contained in:
Peter Deltchev 2015-10-28 00:05:37 -07:00
parent 96b18643a1
commit 88a787cde8
2 changed files with 44 additions and 1 deletions

View file

@ -100,7 +100,11 @@ class TracksController extends \ApiControllerBase
'small' => $track->getCoverUrl(Image::SMALL), 'small' => $track->getCoverUrl(Image::SMALL),
'normal' => $track->getCoverUrl(Image::NORMAL) 'normal' => $track->getCoverUrl(Image::NORMAL)
], ],
'comments' => $comments 'comments' => $comments,
// As of 2015-10-28, this should be expected to produce either
// "direct_upload" or "mlpma" for all tracks.
'source' => $track->source
], 200); ], 200);
} }
} }

View file

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddTrackSourceColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tracks', function(Blueprint $table){
$table->string('source', 40)->default('direct_upload');
});
// Mark MLPMA tracks retroactively
// --> The default value in the database, set above, will
// be used automatically for all non-MLPMA tracks.
$tracks = DB::table('tracks')
->join('mlpma_tracks', 'mlpma_tracks.track_id', '=', 'tracks.id');
$tracks->whereNotNull('mlpma_tracks.id')->update(['source' => 'mlpma']);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tracks', function(Blueprint $table){
$table->dropColumn('source');
});
}
}