<?php

namespace HelpGent\Database\Migrations;

defined( 'ABSPATH' ) || exit;

use HelpGent\WpMVC\Contracts\Migration;

class AddQuizPointsToElementAnswers implements Migration {
    public function more_than_version() {
        return '2.3.0-quiz-points';
    }

    public function execute(): bool {
        global $wpdb;

        $points_column = $wpdb->get_results(
            $wpdb->prepare(
                "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = %s AND table_name = %s AND COLUMN_NAME = 'points'",
                DB_NAME,
                "{$wpdb->prefix}helpgent_element_answers"
            )
        );

        if ( empty( $points_column ) ) {
            $wpdb->query(
                "ALTER TABLE {$wpdb->prefix}helpgent_element_answers ADD COLUMN points INT NULL AFTER attachment_id"
            );
        }

        return true;
    }
}
