<?php

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

/**
 * Only ~30 of the ~83 host modules ship an install flow (InstallController +
 * system.{module}_version row); the 45 specialty plugins and other light
 * modules have no install step at all. The host gate in
 * ModuleLifecycleService::isEnabled() must therefore require the version row
 * only for modules that actually have one to write.
 */
return new class extends Migration
{
    public function up()
    {
        if (! Schema::hasColumn('medreg_modules', 'requires_install')) {
            Schema::table('medreg_modules', function (Blueprint $table) {
                $table->boolean('requires_install')->default(false)->after('is_present');
            });
        }
    }

    public function down()
    {
        if (Schema::hasColumn('medreg_modules', 'requires_install')) {
            Schema::table('medreg_modules', function (Blueprint $table) {
                $table->dropColumn('requires_install');
            });
        }
    }
};
