<?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::dropIfExists('pendatang');
        Schema::create('pendatang', function (Blueprint $table) {
            $table->id(); // Primary key, auto-increment
            $table->foreignId('penduduk_id') 
                  ->constrained('penduduk') 
                  ->onDelete('cascade'); 
            $table->string('tujuan_datang')->nullable(); // Kolom untuk alasan datang
            $table->foreignId('anggota_kk_id')->nullable()->constrained('anggota_kartu_keluarga')->after('penduduk_id');
            $table->string('alasan_datang')->nullable(); // Kolom untuk alasan datang
            $table->date('tanggal_datang')->nullable(); // Kolom untuk alasan datang
            $table->timestamps(); // created_at dan updated_at
        });
    }

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