| 
									
										
										
										
											2020-11-08 08:03:19 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Illuminate\Database\Migrations\Migration; | 
					
						
							|  |  |  | use Illuminate\Database\Schema\Blueprint; | 
					
						
							|  |  |  | use Illuminate\Support\Facades\DB; | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | use Illuminate\Support\Facades\Schema; | 
					
						
							| 
									
										
										
										
											2020-11-08 08:03:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-07 00:58:29 +08:00
										 |  |  | return new class extends Migration | 
					
						
							| 
									
										
										
										
											2020-11-08 08:03:19 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Run the migrations. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2024-03-17 23:29:09 +08:00
										 |  |  |     public function up(): void | 
					
						
							| 
									
										
										
										
											2020-11-08 08:03:19 +08:00
										 |  |  |     { | 
					
						
							|  |  |  |         Schema::table('activities', function (Blueprint $table) { | 
					
						
							|  |  |  |             $table->renameColumn('key', 'type'); | 
					
						
							|  |  |  |             $table->renameColumn('extra', 'detail'); | 
					
						
							|  |  |  |             $table->dropColumn('book_id'); | 
					
						
							|  |  |  |             $table->integer('entity_id')->nullable()->change(); | 
					
						
							|  |  |  |             $table->string('entity_type', 191)->nullable()->change(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         DB::table('activities') | 
					
						
							|  |  |  |             ->where('entity_id', '=', 0) | 
					
						
							|  |  |  |             ->update([ | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |                 'entity_id'   => null, | 
					
						
							| 
									
										
										
										
											2020-11-08 08:03:19 +08:00
										 |  |  |                 'entity_type' => null, | 
					
						
							|  |  |  |             ]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Reverse the migrations. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2024-03-17 23:29:09 +08:00
										 |  |  |     public function down(): void | 
					
						
							| 
									
										
										
										
											2020-11-08 08:03:19 +08:00
										 |  |  |     { | 
					
						
							|  |  |  |         DB::table('activities') | 
					
						
							|  |  |  |             ->whereNull('entity_id') | 
					
						
							|  |  |  |             ->update([ | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |                 'entity_id'   => 0, | 
					
						
							| 
									
										
										
										
											2020-11-08 08:03:19 +08:00
										 |  |  |                 'entity_type' => '', | 
					
						
							|  |  |  |             ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Schema::table('activities', function (Blueprint $table) { | 
					
						
							|  |  |  |             $table->renameColumn('type', 'key'); | 
					
						
							|  |  |  |             $table->renameColumn('detail', 'extra'); | 
					
						
							|  |  |  |             $table->integer('book_id'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $table->integer('entity_id')->change(); | 
					
						
							|  |  |  |             $table->string('entity_type', 191)->change(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $table->index('book_id'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-02-07 00:58:29 +08:00
										 |  |  | }; |