2020_09_22_015815_create_admin_extensions_table.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class CreateAdminExtensionsTable extends Migration
  6. {
  7. public function getConnection()
  8. {
  9. return $this->config('database.connection') ?: config('database.default');
  10. }
  11. public function config($key)
  12. {
  13. return config('admin.' . $key);
  14. }
  15. /**
  16. * Run the migrations.
  17. *
  18. * @return void
  19. */
  20. public function up()
  21. {
  22. Schema::create($this->config('database.extensions_table') ?: 'admin_extensions', function (Blueprint $table) {
  23. $table->increments('id')->unsigned();
  24. $table->string('name', 100)->unique();
  25. $table->string('version', 20)->default('');
  26. $table->tinyInteger('is_enabled')->default(0);
  27. $table->text('options')->nullable();
  28. $table->timestamps();
  29. $table->engine = 'InnoDB';
  30. });
  31. Schema::create($this->config('database.extension_histories_table') ?: 'admin_extension_histories', function (Blueprint $table) {
  32. $table->bigIncrements('id')->unsigned();
  33. $table->string('name', 100);
  34. $table->tinyInteger('type')->default(1);
  35. $table->string('version', 20)->default(0);
  36. $table->text('detail')->nullable();
  37. $table->index('name');
  38. $table->timestamps();
  39. $table->engine = 'InnoDB';
  40. });
  41. }
  42. /**
  43. * Reverse the migrations.
  44. *
  45. * @return void
  46. */
  47. public function down()
  48. {
  49. Schema::dropIfExists($this->config('database.extensions_table') ?: 'admin_extensions');
  50. Schema::dropIfExists($this->config('database.extension_histories_table') ?: 'admin_extension_histories');
  51. }
  52. }