feat: installer - DB table + defaults
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace AskTamMCP\Core;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Handles DB table creation on activation, cleanup on deactivation.
|
||||
*/
|
||||
class Installer {
|
||||
|
||||
public static function activate(): void {
|
||||
self::createTables();
|
||||
self::setDefaults();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
public static function deactivate(): void {
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
private static function createTables(): void {
|
||||
global $wpdb;
|
||||
$charset = $wpdb->get_charset_collate();
|
||||
|
||||
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}asktam_mcp_keys (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
api_key VARCHAR(64) NOT NULL,
|
||||
scopes VARCHAR(255) NOT NULL DEFAULT 'read',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_used DATETIME NULL,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY api_key (api_key)
|
||||
) $charset;";
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta($sql);
|
||||
|
||||
update_option('asktam_mcp_db_version', ASKTAM_MCP_VERSION);
|
||||
}
|
||||
|
||||
private static function setDefaults(): void {
|
||||
if (!get_option('asktam_mcp_settings')) {
|
||||
update_option('asktam_mcp_settings', [
|
||||
'rate_limit' => 60, // requests per minute per key
|
||||
'log_requests' => true,
|
||||
'allow_raw_sql' => false,
|
||||
'wc_enabled' => class_exists('WooCommerce'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user