From 66ffd7714dd9636feea4201fe4996a8ae900bf6c Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Thu, 22 Sep 2016 23:28:24 +0100 Subject: [PATCH] Ensure column does not exist before creation --- ...54_add_deleted_at_column_to_activities.php | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) 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')]); + } } /**