diff --git a/database/migrations/2016_07_10_000354_add_deleted_at_column_to_activities.php b/database/migrations/2016_07_10_000354_add_deleted_at_column_to_activities.php index e62de81a..6c4bad34 100644 --- a/database/migrations/2016_07_10_000354_add_deleted_at_column_to_activities.php +++ b/database/migrations/2016_07_10_000354_add_deleted_at_column_to_activities.php @@ -30,38 +30,40 @@ class AddDeletedAtColumnToActivities extends Migration */ public function up() { - Schema::table('activities', function(Blueprint $table) { - $table->softDeletes()->index(); - }); + if (!Schema::hasColumn('activities', 'deleted_at')) { + Schema::table('activities', function (Blueprint $table) { + $table->softDeletes()->index(); + }); - // Retroactively fix activities that should be marked as deleted. - // Tracks - DB::table('activities') - ->where('resource_type', 2) - ->join('tracks', 'activities.resource_id', '=', 'tracks.id') - ->whereNotNull('tracks.deleted_at') - ->update(['deleted_at' => DB::raw('tracks.deleted_at')]); + // Retroactively fix activities that should be marked as deleted. + // Tracks + DB::table('activities') + ->where('resource_type', 2) + ->join('tracks', 'activities.resource_id', '=', 'tracks.id') + ->whereNotNull('tracks.deleted_at') + ->update(['deleted_at' => DB::raw('tracks.deleted_at')]); - // Albums - DB::table('activities') - ->where('resource_type', 3) - ->join('albums', 'activities.resource_id', '=', 'albums.id') - ->whereNotNull('albums.deleted_at') - ->update(['deleted_at' => DB::raw('albums.deleted_at')]); + // Albums + DB::table('activities') + ->where('resource_type', 3) + ->join('albums', 'activities.resource_id', '=', 'albums.id') + ->whereNotNull('albums.deleted_at') + ->update(['deleted_at' => DB::raw('albums.deleted_at')]); - // Playlists - DB::table('activities') - ->where('resource_type', 4) - ->join('playlists', 'activities.resource_id', '=', 'playlists.id') - ->whereNotNull('playlists.deleted_at') - ->update(['deleted_at' => DB::raw('playlists.deleted_at')]); + // Playlists + DB::table('activities') + ->where('resource_type', 4) + ->join('playlists', 'activities.resource_id', '=', 'playlists.id') + ->whereNotNull('playlists.deleted_at') + ->update(['deleted_at' => DB::raw('playlists.deleted_at')]); - // Comments - DB::table('activities') - ->where('resource_type', 5) - ->join('comments', 'activities.resource_id', '=', 'comments.id') - ->whereNotNull('comments.deleted_at') - ->update(['deleted_at' => DB::raw('comments.deleted_at')]); + // Comments + DB::table('activities') + ->where('resource_type', 5) + ->join('comments', 'activities.resource_id', '=', 'comments.id') + ->whereNotNull('comments.deleted_at') + ->update(['deleted_at' => DB::raw('comments.deleted_at')]); + } } /**