. */ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; use Poniverse\Ponyfm\Models\Track; class AddTrackFilesForDeletedTracks extends Migration { /** * Run the migrations. * * @return void */ public function up() { // 2015_05_25_011121_create_track_files_table.php only created // track_files records for non-deleted tracks. This migration // adds them for deleted tracks, too. $tracks = Track::with('trackFiles') ->onlyTrashed() ->get(); foreach ($tracks as $track) { if ($track->trackFiles->count() === 0 && $track->source !== 'mlpma') { foreach (Track::$Formats as $name => $item) { DB::table('track_files')->insert( [ 'track_id' => $track->id, 'is_master' => $name === 'FLAC' ? true : false, 'format' => $name, 'created_at' => $track->created_at, 'updated_at' => Carbon\Carbon::now() ] ); } } } } /** * Reverse the migrations. * * @return void */ public function down() { // There's no need to undo this one! } }