|
| 1 | +<?php |
| 2 | + |
| 3 | +declare (strict_types = 1); |
| 4 | + |
| 5 | +use Hyperf\Database\Migrations\Migration; |
| 6 | +use Hyperf\Database\Schema\Blueprint; |
| 7 | +use Hypervel\Support\Facades\Schema; |
| 8 | + |
| 9 | +return new class extends Migration |
| 10 | +{ |
| 11 | + /** |
| 12 | + * Run the migrations. |
| 13 | + */ |
| 14 | + public function up(): void |
| 15 | + { |
| 16 | + /*Schema::create('school_management', function (Blueprint $table) { |
| 17 | + $table->bigIncrements('id'); |
| 18 | + $table->datetimes(); |
| 19 | + });*/ |
| 20 | + |
| 21 | + // Parents table |
| 22 | + Schema::create('parents', function (Blueprint $table) { |
| 23 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 24 | + $table->uuid('user_id')->unique(); |
| 25 | + $table->string('occupation', 100)->nullable(); |
| 26 | + $table->text('address')->nullable(); |
| 27 | + |
| 28 | + $table->datetimes(); |
| 29 | + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); |
| 30 | + }); |
| 31 | + |
| 32 | + // Teachers table |
| 33 | + Schema::create('teachers', function (Blueprint $table) { |
| 34 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 35 | + $table->uuid('user_id')->unique(); |
| 36 | + $table->string('nip', 20)->unique(); |
| 37 | + $table->string('expertise', 100)->nullable(); |
| 38 | + $table->date('join_date'); |
| 39 | + $table->string('status', 20)->default('active'); |
| 40 | + |
| 41 | + $table->datetimes(); |
| 42 | + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); |
| 43 | + }); |
| 44 | + |
| 45 | + // Classes table |
| 46 | + Schema::create('classes', function (Blueprint $table) { |
| 47 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 48 | + $table->string('name', 50); |
| 49 | + $table->string('level', 20); |
| 50 | + $table->uuid('homeroom_teacher_id')->nullable(); |
| 51 | + $table->string('academic_year', 9); |
| 52 | + $table->integer('capacity')->nullable(); |
| 53 | + |
| 54 | + $table->datetimes(); |
| 55 | + $table->foreign('homeroom_teacher_id')->references('id')->on('teachers')->onDelete('set null'); |
| 56 | + }); |
| 57 | + |
| 58 | + // Students table |
| 59 | + Schema::create('students', function (Blueprint $table) { |
| 60 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 61 | + $table->uuid('user_id')->unique(); |
| 62 | + $table->string('nisn', 20)->unique(); |
| 63 | + $table->uuid('class_id')->nullable(); |
| 64 | + $table->date('birth_date')->nullable(); |
| 65 | + $table->string('birth_place', 50)->nullable(); |
| 66 | + $table->text('address')->nullable(); |
| 67 | + $table->uuid('parent_id')->nullable(); |
| 68 | + $table->date('enrollment_date'); |
| 69 | + $table->string('status', 20)->default('active'); |
| 70 | + |
| 71 | + $table->datetimes(); |
| 72 | + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); |
| 73 | + $table->foreign('class_id')->references('id')->on('classes')->onDelete('set null'); |
| 74 | + $table->foreign('parent_id')->references('id')->on('parents')->onDelete('set null'); |
| 75 | + }); |
| 76 | + |
| 77 | + // Staff table |
| 78 | + Schema::create('staff', function (Blueprint $table) { |
| 79 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 80 | + $table->uuid('user_id')->unique(); |
| 81 | + $table->string('position', 100); |
| 82 | + $table->string('department', 100)->nullable(); |
| 83 | + $table->date('join_date'); |
| 84 | + $table->string('status', 20)->default('active'); |
| 85 | + |
| 86 | + $table->datetimes(); |
| 87 | + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); |
| 88 | + }); |
| 89 | + |
| 90 | + // Subjects table |
| 91 | + Schema::create('subjects', function (Blueprint $table) { |
| 92 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 93 | + $table->string('code', 20)->unique(); |
| 94 | + $table->string('name', 100); |
| 95 | + $table->text('description')->nullable(); |
| 96 | + $table->integer('credit_hours')->nullable(); |
| 97 | + |
| 98 | + $table->datetimes(); |
| 99 | + }); |
| 100 | + |
| 101 | + // Class-Subject relationship |
| 102 | + Schema::create('class_subjects', function (Blueprint $table) { |
| 103 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 104 | + $table->uuid('class_id'); |
| 105 | + $table->uuid('subject_id'); |
| 106 | + $table->uuid('teacher_id')->nullable(); |
| 107 | + $table->text('schedule_info')->nullable(); |
| 108 | + $table->unique(['class_id', 'subject_id']); |
| 109 | + |
| 110 | + $table->datetimes(); |
| 111 | + $table->foreign('class_id')->references('id')->on('classes')->onDelete('cascade'); |
| 112 | + $table->foreign('subject_id')->references('id')->on('subjects')->onDelete('cascade'); |
| 113 | + $table->foreign('teacher_id')->references('id')->on('teachers')->onDelete('set null'); |
| 114 | + }); |
| 115 | + |
| 116 | + // Schedules table |
| 117 | + Schema::create('schedules', function (Blueprint $table) { |
| 118 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 119 | + $table->uuid('class_subject_id'); |
| 120 | + $table->smallInteger('day_of_week'); |
| 121 | + $table->time('start_time'); |
| 122 | + $table->time('end_time'); |
| 123 | + $table->string('room', 50)->nullable(); |
| 124 | + |
| 125 | + $table->datetimes(); |
| 126 | + $table->foreign('class_subject_id')->references('id')->on('class_subjects')->onDelete('cascade'); |
| 127 | + }); |
| 128 | + |
| 129 | + // School Inventory table |
| 130 | + Schema::create('school_inventory', function (Blueprint $table) { |
| 131 | + $table->uuid('id')->primary()->default(DB::raw('(UUID())')); |
| 132 | + $table->string('name', 100); |
| 133 | + $table->string('category', 50); |
| 134 | + $table->integer('quantity'); |
| 135 | + $table->string('location', 100)->nullable(); |
| 136 | + $table->string('condition', 50)->nullable(); |
| 137 | + $table->date('purchase_date')->nullable(); |
| 138 | + $table->date('last_maintenance')->nullable(); |
| 139 | + |
| 140 | + $table->datetimes(); |
| 141 | + }); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Reverse the migrations. |
| 146 | + */ |
| 147 | + public function down() |
| 148 | + { |
| 149 | + Schema::dropIfExists('schedules'); |
| 150 | + Schema::dropIfExists('class_subjects'); |
| 151 | + Schema::dropIfExists('subjects'); |
| 152 | + Schema::dropIfExists('students'); |
| 153 | + Schema::dropIfExists('classes'); |
| 154 | + Schema::dropIfExists('teachers'); |
| 155 | + Schema::dropIfExists('parents'); |
| 156 | + Schema::dropIfExists('staff'); |
| 157 | + Schema::dropIfExists('school_inventory'); |
| 158 | + } |
| 159 | +}; |
0 commit comments