mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 14:37:59 +01:00
Ensure column does not exist before creation
This commit is contained in:
parent
abdfe2f698
commit
66ffd7714d
1 changed files with 30 additions and 28 deletions
|
@ -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')]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue