]> BookStack Code Mirror - bookstack/blob - database/migrations/2020_11_07_232321_simplify_activities_table.php
New translations editor.php (Welsh)
[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 class SimplifyActivitiesTable extends Migration
9 {
10     /**
11      * Run the migrations.
12      *
13      * @return void
14      */
15     public function up()
16     {
17         Schema::table('activities', function (Blueprint $table) {
18             $table->renameColumn('key', 'type');
19             $table->renameColumn('extra', 'detail');
20             $table->dropColumn('book_id');
21             $table->integer('entity_id')->nullable()->change();
22             $table->string('entity_type', 191)->nullable()->change();
23         });
24
25         DB::table('activities')
26             ->where('entity_id', '=', 0)
27             ->update([
28                 'entity_id'   => null,
29                 'entity_type' => null,
30             ]);
31     }
32
33     /**
34      * Reverse the migrations.
35      *
36      * @return void
37      */
38     public function down()
39     {
40         DB::table('activities')
41             ->whereNull('entity_id')
42             ->update([
43                 'entity_id'   => 0,
44                 'entity_type' => '',
45             ]);
46
47         Schema::table('activities', function (Blueprint $table) {
48             $table->renameColumn('type', 'key');
49             $table->renameColumn('detail', 'extra');
50             $table->integer('book_id');
51
52             $table->integer('entity_id')->change();
53             $table->string('entity_type', 191)->change();
54
55             $table->index('book_id');
56         });
57     }
58 }