<?php

/**
 * LolaCore � Migrator
 *
 * @package LolaCore
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore\Database;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Migrator
{
    /**
     * Checks if the database schema needs to be upgraded and runs migrations if necessary.
     */
    public static function maybeUpgrade(): void
    {
        $currentVersion = get_option('lolacore_db_version', '0.0.0');

        if (version_compare($currentVersion, LOLACORE_DB_VERSION, '<')) {
            // For MVP, just run dbDelta via Schema::create() which is idempotent.
            //
            // v1.4.0 extension point: Skills.MD introduces wp_lolacore_skills,
            // created via dbDelta in Schema::getTableDefinitions(). Future skill
            // schema deltas (additional columns, indexes) should be added to
            // Schema::migrate() guarded by INFORMATION_SCHEMA checks.
            require_once __DIR__ . '/Schema.php';
            Schema::create();

            update_option('lolacore_db_version', LOLACORE_DB_VERSION);
        }
    }
}
