> For the complete documentation index, see [llms.txt](https://alvan.kitakale.id/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alvan.kitakale.id/buku-induk/data-master/membuat-file-miggrasi.md).

# Membuat File Miggrasi

## 1) `php artisan make:model School -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('schools', function (Blueprint $table) {
            $table->id();

            $table->string('npsn', 20)->nullable()->unique();
            $table->string('school_code', 30)->nullable();
            $table->string('school_statistic_number', 50)->nullable();

            $table->string('name', 150);
            $table->string('school_level', 20)->default('SMK');
            $table->string('status', 20)->nullable(); // NEGERI / SWASTA

            $table->text('address')->nullable();
            $table->string('rt', 10)->nullable();
            $table->string('rw', 10)->nullable();

            $table->string('village', 100)->nullable();
            $table->string('village_code', 20)->nullable();

            $table->string('district', 100)->nullable();
            $table->string('district_code', 20)->nullable();

            $table->string('city', 100)->nullable();
            $table->string('city_code', 20)->nullable();

            $table->string('province', 100)->nullable();
            $table->string('province_code', 20)->nullable();

            $table->string('postal_code', 10)->nullable();
            $table->string('phone', 30)->nullable();
            $table->string('email', 100)->nullable();
            $table->string('website', 150)->nullable();

            $table->string('principal_name', 150)->nullable();
            $table->string('principal_nip', 50)->nullable();

            $table->string('logo_path')->nullable();

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('schools');
    }
};
```

***

## 2) `php artisan make:model AcademicYear -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('academic_years', function (Blueprint $table) {
            $table->id();

            $table->foreignId('school_id')
                ->constrained('schools')
                ->cascadeOnDelete();

            $table->string('name', 20); // contoh: 2026/2027
            $table->date('start_date')->nullable();
            $table->date('end_date')->nullable();
            $table->boolean('is_active')->default(false);

            $table->timestamps();

            $table->unique(['school_id', 'name']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('academic_years');
    }
};
```

***

## 3) `php artisan make:model Curriculum -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('curriculums', function (Blueprint $table) {
            $table->id();

            $table->foreignId('school_id')
                ->constrained('schools')
                ->cascadeOnDelete();

            $table->string('code', 50)->nullable();
            $table->string('name', 150);
            $table->string('version', 50)->nullable();
            $table->text('description')->nullable();
            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index(['school_id', 'is_active']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('curriculums');
    }
};
```

***

## 4) `php artisan make:model Major -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('majors', function (Blueprint $table) {
            $table->id();

            $table->foreignId('school_id')
                ->constrained('schools')
                ->cascadeOnDelete();

            $table->string('code', 30)->nullable();
            $table->string('name', 150);
            $table->string('short_name', 50)->nullable();
            $table->text('description')->nullable();
            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index(['school_id', 'is_active']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('majors');
    }
};
```

***

## 5) `php artisan make:model Concentration -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('concentrations', function (Blueprint $table) {
            $table->id();

            $table->foreignId('major_id')
                ->constrained('majors')
                ->cascadeOnDelete();

            $table->string('code', 30)->nullable();
            $table->string('name', 150);
            $table->string('short_name', 50)->nullable();
            $table->text('description')->nullable();
            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index(['major_id', 'is_active']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('concentrations');
    }
};
```

***

## 6) `php artisan make:model Subject -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('subjects', function (Blueprint $table) {
            $table->id();

            $table->foreignId('school_id')
                ->constrained('schools')
                ->cascadeOnDelete();

            $table->string('code', 30)->nullable();
            $table->string('name', 150);
            $table->string('short_name', 50)->nullable();

            $table->string('subject_group', 50)->nullable();
            $table->boolean('is_local_content')->default(false);
            $table->boolean('is_active')->default(true);

            $table->text('description')->nullable();

            $table->timestamps();

            $table->index(['school_id', 'subject_group']);
            $table->index(['school_id', 'is_active']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('subjects');
    }
};
```

***

## 7) `php artisan make:model CurriculumSubjects -mc`&#x20;

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('curriculum_subjects', function (Blueprint $table) {
            $table->id();

            $table->foreignId('curriculum_id')
                ->constrained('curriculums')
                ->cascadeOnDelete();

            $table->foreignId('subject_id')
                ->constrained('subjects')
                ->cascadeOnDelete();

            $table->foreignId('major_id')
                ->nullable()
                ->constrained('majors')
                ->nullOnDelete();

            $table->foreignId('concentration_id')
                ->nullable()
                ->constrained('concentrations')
                ->nullOnDelete();

            $table->string('grade_level', 10); // X / XI / XII
            $table->string('phase', 10)->nullable(); // E / F
            $table->string('subject_group', 50)->nullable();

            $table->unsignedSmallInteger('sort_order')->default(0);
            $table->decimal('default_kktp', 5, 2)->nullable();

            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index(['curriculum_id', 'grade_level']);
            $table->index(['major_id']);
            $table->index(['concentration_id']);
            $table->index(['subject_id']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('curriculum_subjects');
    }
};
```

***

## 8) `php artisan make:model SchoolStaff -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('school_staff', function (Blueprint $table) {
            $table->id();

            $table->foreignId('school_id')
                ->constrained('schools')
                ->cascadeOnDelete();

            $table->string('nip', 50)->nullable();
            $table->string('nuptk', 50)->nullable();
            $table->string('nik', 30)->nullable();

            $table->string('name', 150);
            $table->string('gender', 1)->nullable(); // L / P

            $table->string('birth_place', 100)->nullable();
            $table->date('birth_date')->nullable();

            $table->string('staff_type', 30)->default('TEACHER'); // TEACHER / STAFF
            $table->string('employment_status', 50)->nullable();
            $table->string('position', 100)->nullable();

            $table->string('phone', 30)->nullable();
            $table->string('email', 100)->nullable();
            $table->text('address')->nullable();

            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index(['school_id', 'staff_type']);
            $table->index(['school_id', 'is_active']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('school_staff');
    }
};
```

***

## 9) `php artisan make:model SchoolClass -mc`&#x20;

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('school_classes', function (Blueprint $table) {
            $table->id();

            $table->foreignId('school_id')
                ->constrained('schools')
                ->cascadeOnDelete();

            $table->foreignId('academic_year_id')
                ->constrained('academic_years')
                ->cascadeOnDelete();

            $table->foreignId('curriculum_id')
                ->nullable()
                ->constrained('curriculums')
                ->nullOnDelete();

            $table->foreignId('major_id')
                ->nullable()
                ->constrained('majors')
                ->nullOnDelete();

            $table->foreignId('concentration_id')
                ->nullable()
                ->constrained('concentrations')
                ->nullOnDelete();

            $table->foreignId('homeroom_teacher_id')
                ->nullable()
                ->constrained('school_staff')
                ->nullOnDelete();

            $table->string('code', 30)->nullable();
            $table->string('name', 100); // contoh: X RPL 1
            $table->string('grade_level', 10); // X / XI / XII
            $table->string('phase', 10)->nullable(); // E / F

            $table->unsignedInteger('capacity')->nullable();
            $table->string('room_name', 100)->nullable();

            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index(['school_id', 'academic_year_id']);
            $table->index(['major_id']);
            $table->index(['concentration_id']);
            $table->index(['homeroom_teacher_id']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('school_classes');
    }
};
```

***

## 10)  `php artisan make:model Extracurricular -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('extracurriculars', function (Blueprint $table) {
            $table->id();

            $table->foreignId('school_id')
                ->constrained('schools')
                ->cascadeOnDelete();

            $table->foreignId('advisor_id')
                ->nullable()
                ->constrained('school_staff')
                ->nullOnDelete();

            $table->string('code', 30)->nullable();
            $table->string('name', 150);
            $table->text('description')->nullable();

            $table->boolean('is_mandatory')->default(false);
            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index(['school_id', 'is_active']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('extracurriculars');
    }
};
```

***

## 11) `php artisan make:model Company -mc`

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('companies', function (Blueprint $table) {
            $table->id();

            $table->foreignId('school_id')
                ->constrained('schools')
                ->cascadeOnDelete();

            $table->string('code', 30)->nullable();
            $table->string('name', 200);

            $table->string('business_field', 150)->nullable();

            $table->text('address')->nullable();
            $table->string('village', 100)->nullable();
            $table->string('district', 100)->nullable();
            $table->string('city', 100)->nullable();
            $table->string('province', 100)->nullable();
            $table->string('postal_code', 10)->nullable();

            $table->string('phone', 30)->nullable();
            $table->string('email', 100)->nullable();
            $table->string('website', 150)->nullable();

            $table->string('contact_person_name', 150)->nullable();
            $table->string('contact_person_position', 100)->nullable();
            $table->string('contact_person_phone', 30)->nullable();

            $table->string('cooperation_status', 30)->default('PROSPECT'); // ACTIVE / INACTIVE / PROSPECT
            $table->string('mou_number', 100)->nullable();
            $table->date('mou_start_date')->nullable();
            $table->date('mou_end_date')->nullable();

            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index(['school_id', 'cooperation_status']);
            $table->index(['school_id', 'is_active']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('companies');
    }
};
```
