]> BookStack Code Mirror - bookstack/blob - database/migrations/2020_11_07_232321_simplify_activities_table.php
Mail: Removed custom symfony/mailer fork
[bookstack] / database / migrations / 2020_11_07_232321_simplify_activities_table.php
1 <?php
2
3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\DB;
6 use Illuminate\Support\Facades\Schema;
7
8 return new class extends Migration
9 {
10     /**
11      * Run the migrations.
12      */
13     public function up(): void
14     {
15         Schema::table('activities', function (Blueprint $table) {
16             $table->renameColumn('key', 'type');
17             $table->renameColumn('extra', 'detail');
18             $table->dropColumn('book_id');
19             $table->integer('entity_id')->nullable()->change();
20             $table->string('entity_type', 191)->nullable()->change();
21         });
22
23         DB::table('activities')
24             ->where('entity_id', '=', 0)
25             ->update([
26                 'entity_id'   => null,
27                 'entity_type' => null,
28             ]);
29     }
30
31     /**
32      * Reverse the migrations.
33      */
34     public function down(): void
35     {
36         DB::table('activities')
37             ->whereNull('entity_id')
38             ->update([
39                 'entity_id'   => 0,
40                 'entity_type' => '',
41             ]);
42
43         Schema::table('activities', function (Blueprint $table) {
44             $table->renameColumn('type', 'key');
45             $table->renameColumn('detail', 'extra');
46             $table->integer('book_id');
47
48             $table->integer('entity_id')->change();
49             $table->string('entity_type', 191)->change();
50
51             $table->index('book_id');
52         });
53     }
54 };