You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2024_03_07_100000_create_blueprints_table.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. use Illuminate\Database\Schema\Blueprint;
  3. use Illuminate\Support\Carbon;
  4. use Illuminate\Support\Facades\Schema;
  5. use Statamic\Eloquent\Database\BaseMigration as Migration;
  6. return new class extends Migration
  7. {
  8. public function up()
  9. {
  10. Schema::create($this->prefix('blueprints'), function (Blueprint $table) {
  11. $table->id();
  12. $table->string('namespace')->nullable()->default(null)->index();
  13. $table->string('handle');
  14. $table->jsonb('data');
  15. $table->timestamps();
  16. $table->unique(['handle', 'namespace']);
  17. });
  18. $this->seedDefaultBlueprint();
  19. }
  20. public function down()
  21. {
  22. Schema::dropIfExists($this->prefix('blueprints'));
  23. }
  24. public function seedDefaultBlueprint()
  25. {
  26. try {
  27. $config = json_encode([
  28. 'fields' => [
  29. [
  30. 'field' => [
  31. 'type' => 'markdown',
  32. 'display' => 'Content',
  33. 'localizable' => true,
  34. ],
  35. 'handle' => 'content',
  36. ],
  37. ],
  38. ]);
  39. } catch (\JsonException $e) {
  40. $config = '[]';
  41. }
  42. DB::table($this->prefix('blueprints'))->insert([
  43. 'namespace' => null,
  44. 'handle' => 'default',
  45. 'data' => $config,
  46. 'created_at' => Carbon::now(),
  47. ]);
  48. }
  49. };