2024_01_09_052419_create_parental_controls_table.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. */
  10. public function up(): void
  11. {
  12. Schema::create('parental_controls', function (Blueprint $table) {
  13. $table->id();
  14. $table->unsignedInteger('parent_id')->index();
  15. $table->unsignedInteger('child_id')->unique()->index()->nullable();
  16. $table->string('email')->unique()->nullable();
  17. $table->string('verify_code')->nullable();
  18. $table->timestamp('email_sent_at')->nullable();
  19. $table->timestamp('email_verified_at')->nullable();
  20. $table->json('permissions')->nullable();
  21. $table->softDeletes();
  22. $table->timestamps();
  23. });
  24. Schema::table('user_roles', function (Blueprint $table) {
  25. $indexes = Schema::getIndexes('user_roles');
  26. $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
  27. if (in_array('user_roles_profile_id_unique', $indexesFound)) {
  28. $table->dropUnique('user_roles_profile_id_unique');
  29. }
  30. $table->unsignedBigInteger('profile_id')->unique()->nullable()->index()->change();
  31. });
  32. }
  33. /**
  34. * Reverse the migrations.
  35. */
  36. public function down(): void
  37. {
  38. Schema::dropIfExists('parental_controls');
  39. Schema::table('user_roles', function (Blueprint $table) {
  40. $indexes = Schema::getIndexes('user_roles');
  41. $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
  42. if (in_array('user_roles_profile_id_unique', $indexesFound)) {
  43. $table->dropUnique('user_roles_profile_id_unique');
  44. }
  45. $table->unsignedBigInteger('profile_id')->unique()->index()->change();
  46. });
  47. }
  48. };