<?php
if (!defined('ABSPATH')) exit;

class SIMPINBY_DB {

    public static function maybe_upgrade() {
        global $wpdb;

        $table = $wpdb->prefix . 'simpinby_invoices';

        // Check if column exists
        $column = $wpdb->get_results(
            $wpdb->prepare(
                "SHOW COLUMNS FROM `$table` LIKE %s",
                'public_token'
            )
        );

        if (empty($column)) {
            $wpdb->query("ALTER TABLE `$table` ADD `public_token` VARCHAR(50) NULL");
        }
    }
}