<?php

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

/**
 * Generic key/value table for per-role VetClinic settings. First user is the
 * appointment-scope flag ("appointment_scope" = "own") which restricts doctors
 * with that role to only their own appointments on the calendar/list pages
 * (the pet profile still shows every visit, regardless).
 */
class CreateVcRoleSettingsTable extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('vc_role_settings')) {
            Schema::create('vc_role_settings', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedInteger('business_id')->index();
                $table->unsignedBigInteger('role_id')->index();
                $table->string('key', 60);
                $table->string('value', 191);
                $table->timestamps();
                $table->unique(['business_id', 'role_id', 'key']);
            });
        }
    }

    public function down()
    {
        Schema::dropIfExists('vc_role_settings');
    }
}
