<?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('patient_medications', function (Blueprint $table) {
            $table->id('medication_id'); // Creates the medication_id column as an auto-incrementing primary key
            $table->unsignedBigInteger('patient_id'); // Define patient_id as an unsigned big integer
            $table->string('medication_name', 100); // Define medication_name as a variable character string with length 100
            $table->string('dosage', 50)->nullable(); // Define dosage as a variable character string with length 50, allowing null
            $table->string('frequency', 50)->nullable(); // Define frequency as a variable character string with length 50, allowing null
            
            // Set up the foreign key constraint
            $table->foreign('patient_id')->references('patient_id')->on('patient')->onUpdate('no action')->onDelete('no action');
        });
    }

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