# SCHEMA_MAP.md
> **Version**: 4.0 - Full System Audit (2026-06-20)
> **Databases**: `store` (Origin 558201) + `engine` (Engine 669427)
> **Origin Tables**: 112 + 6 views
> **Engine Tables**: 6 (wg_config + 5 new)
> **Installable**: [INSTALL_ALL.sql](file:///Y:/5/var/www/dashboard/system/INSTALL_ALL.sql) v2.0 - idempotent, safe to run multiple times
> **Dump Date**: 2026-06-11 (original), refreshed 2026-06-20 (audit)

### Audit Notes (2026-06-20)
- **Schema drift**: Original dump had 75 tables. Live DB now has 112 (37 added since June 11)
- **3-database architecture**: store (Origin), engine (Engine), ~~s3rv1c3_admin~~ (Shield — DOES NOT EXIST)
- **log_to_db.sh FIXED**: Was targeting s3rv1c3_admin on Shield (no MySQL). Now targets engine on Engine
- **~47 orphaned tables**: Infrastructure for designed-but-not-wired features. KEPT in schema
- **store_domains**: Is a VIEW over stores table, not a base table
- Database is named `store` on server, aliased as `noname` in application code
- The `stores` table has 3 additional columns added after this dump (see comments at table definition):
 - `store_email TEXT DEFAULT NULL`
 - `welcome_gate_enabled TINYINT(1) DEFAULT 1`
 - `welcome_gate_type VARCHAR(20) DEFAULT 'age'`
- The `nodes` table `ssh_port` column default has been corrected to 9922 (was 33022 in original dump, updated 2026-07-02)
- Per Rule **OPS-08**: If code references a table not in this file, STOP and update docs

---

```sql
/*M!999999\- enable the sandbox mode */ 
-- MariaDB dump 10.19 Distrib 10.5.29-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: store
-- ------------------------------------------------------
-- Server version	10.5.29-MariaDB-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `admin_users`
--

DROP TABLE IF EXISTS `admin_users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `admin_users` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `username` varchar(100) DEFAULT NULL,
 `password_hash` varchar(255) DEFAULT NULL,
 `admin_level` tinyint(4) DEFAULT 0,
 `access_tier` varchar(20) DEFAULT NULL,
 `pref_a` int(11) DEFAULT 0,
 `pref_b` int(11) DEFAULT 0,
 `pref_c` int(11) DEFAULT 0,
 `pref_d` int(11) DEFAULT 0,
 `is_active` tinyint(1) DEFAULT 1,
 `last_login` datetime DEFAULT NULL,
 `last_ip` varchar(45) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `blacklist`
--

DROP TABLE IF EXISTS `blacklist`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `blacklist` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ip_address` varchar(45) NOT NULL,
 `reason` varchar(255) DEFAULT NULL,
 `severity` enum('low','medium','high','critical') DEFAULT 'medium',
 `expires_at` datetime DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `status_code` int(11) DEFAULT 7000,
 PRIMARY KEY (`id`),
 KEY `idx_ip` (`ip_address`),
 KEY `idx_expires` (`expires_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `block_types`
--

DROP TABLE IF EXISTS `block_types`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `block_types` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `type_key` varchar(50) DEFAULT NULL,
 `label` varchar(100) DEFAULT NULL,
 `is_active` tinyint(1) DEFAULT 1,
 `type_category` varchar(50) DEFAULT NULL,
 `type_label` varchar(100) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `campaign_hits`
--

DROP TABLE IF EXISTS `campaign_hits`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `campaign_hits` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `campaign_id` int(10) unsigned DEFAULT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `user_agent` text DEFAULT NULL,
 `referrer` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `hit_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `campaign_visits`
--

DROP TABLE IF EXISTS `campaign_visits`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `campaign_visits` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `campaign_id` int(10) unsigned DEFAULT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `referrer` varchar(500) DEFAULT NULL,
 `converted` tinyint(1) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `card_attempts`
--

DROP TABLE IF EXISTS `card_attempts`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `card_attempts` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ip_address` varchar(45) DEFAULT NULL,
 `card_hash` varchar(64) DEFAULT NULL,
 `user_id` int(10) unsigned DEFAULT NULL,
 `result` varchar(20) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `categories`
--

DROP TABLE IF EXISTS `categories`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `categories` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `store_id` int(10) unsigned NOT NULL,
 `name` varchar(200) DEFAULT NULL,
 `nickname` varchar(200) DEFAULT NULL,
 `slug` varchar(200) DEFAULT NULL,
 `display_order` int(11) DEFAULT 0,
 `show_in_nav` tinyint(1) DEFAULT 1,
 `status` enum('active','hidden','deleted') DEFAULT 'active',
 `status_code` int(11) DEFAULT 5001,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `description` text DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `idx_store` (`store_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `crypto_transactions`
--

DROP TABLE IF EXISTS `crypto_transactions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `crypto_transactions` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `wallet_id` int(10) unsigned DEFAULT NULL,
 `txid` varchar(255) DEFAULT NULL,
 `txid_enc` varchar(255) DEFAULT NULL,
 `amount` decimal(18,8) DEFAULT 0.00000000,
 `status` varchar(20) DEFAULT 'pending',
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `tx_hash` varchar(128) DEFAULT NULL,
 `tx_hash_enc` varchar(128) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `customer_addresses`
--

DROP TABLE IF EXISTS `customer_addresses`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `customer_addresses` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned NOT NULL,
 `label` varchar(50) DEFAULT 'Home',
 `address` text DEFAULT NULL,
 `address_enc` text DEFAULT NULL,
 `city` varchar(100) DEFAULT NULL,
 `city_enc` varchar(200) DEFAULT NULL,
 `province` varchar(100) DEFAULT NULL,
 `province_enc` varchar(200) DEFAULT NULL,
 `postal_code` varchar(20) DEFAULT NULL,
 `postal_code_enc` varchar(20) DEFAULT NULL,
 `country` varchar(100) DEFAULT 'Canada',
 `is_default` tinyint(1) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `customer_ip_logs`
--

DROP TABLE IF EXISTS `customer_ip_logs`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `customer_ip_logs` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `user_agent` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `cnt` int(11) DEFAULT 1,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Temporary table structure for view `customer_reviews`
--

DROP TABLE IF EXISTS `customer_reviews`;
/*!50001 DROP VIEW IF EXISTS `customer_reviews`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8mb4;
/*!50001 CREATE VIEW `customer_reviews` AS SELECT
 1 AS `id`,
 1 AS `store_id`,
 1 AS `user_id`,
 1 AS `product_id`,
 1 AS `rating`,
 1 AS `title`,
 1 AS `body`,
 1 AS `is_approved`,
 1 AS `is_verified`,
 1 AS `admin_reply`,
 1 AS `helpful_count`,
 1 AS `created_at` */;
SET character_set_client = @saved_cs_client;

--
-- Table structure for table `deception_tokens`
--

DROP TABLE IF EXISTS `deception_tokens`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `deception_tokens` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `token` varchar(255) DEFAULT NULL,
 `token_type` varchar(50) DEFAULT NULL,
 `is_triggered` tinyint(1) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `status` varchar(30) DEFAULT 'active',
 `target_ip` varchar(45) DEFAULT NULL,
 `triggered_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `device_bindings`
--

DROP TABLE IF EXISTS `device_bindings`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `device_bindings` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `device_fingerprint` varchar(255) DEFAULT NULL,
 `trust_score` decimal(5,2) DEFAULT 0.00,
 `is_trusted` tinyint(1) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `audio_hash` varchar(64) DEFAULT NULL,
 `canvas_hash` varchar(64) DEFAULT NULL,
 `device_hash` varchar(64) DEFAULT NULL,
 `device_token` text DEFAULT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `last_seen` datetime DEFAULT NULL,
 `screen_sig` varchar(100) DEFAULT NULL,
 `user_agent` varchar(500) DEFAULT NULL,
 `webgl_renderer` varchar(255) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `devices`
--

DROP TABLE IF EXISTS `devices`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `devices` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `admin_id` int(10) unsigned NOT NULL,
 `fingerprint` varchar(64) DEFAULT NULL,
 `label` varchar(100) DEFAULT NULL,
 `last_seen` datetime DEFAULT NULL,
 `is_trusted` tinyint(1) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `email_log`
--

DROP TABLE IF EXISTS `email_log`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `email_log` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `recipient` varchar(255) DEFAULT NULL,
 `subject` text DEFAULT NULL,
 `template` varchar(100) DEFAULT NULL,
 `status` varchar(20) DEFAULT 'sent',
 `store_id` int(10) unsigned DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `relay` varchar(100) DEFAULT NULL,
 `message_id` varchar(255) DEFAULT NULL,
 `error_detail` text DEFAULT NULL,
 `email_type` varchar(50) DEFAULT NULL,
 `sent_to` varchar(255) DEFAULT NULL,
 `order_id` int(10) unsigned DEFAULT NULL,
 `error_message` text DEFAULT NULL,
 `smtp_host` varchar(100) DEFAULT NULL,
 `relay_method` varchar(20) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `email_queue`
--

DROP TABLE IF EXISTS `email_queue`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `email_queue` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `recipient_enc` text NOT NULL,
 `subject_enc` text DEFAULT NULL,
 `body_enc` mediumtext DEFAULT NULL,
 `email_type` enum('account_verify','fulfillment','exclusion','password_reset','order_confirm','shipping','delivery','review_request','support') NOT NULL,
 `template_ref` varchar(50) DEFAULT NULL,
 `priority` tinyint(4) DEFAULT 5,
 `attempts` tinyint(4) DEFAULT 0,
 `max_attempts` tinyint(4) DEFAULT 3,
 `status_code` int(11) DEFAULT 8001,
 `scheduled_at` datetime DEFAULT current_timestamp(),
 `sent_at` datetime DEFAULT NULL,
 `error_log` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_status_scheduled` (`status_code`,`scheduled_at`),
 KEY `idx_attempts` (`attempts`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `email_verifications`
--

DROP TABLE IF EXISTS `email_verifications`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `email_verifications` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned NOT NULL,
 `token_hash` char(64) NOT NULL,
 `verify_type` enum('account','fulfillment','exclusion','password') NOT NULL,
 `status_code` int(11) DEFAULT 8101,
 `expires_at` datetime NOT NULL,
 `verified_at` datetime DEFAULT NULL,
 `resend_count` tinyint(4) DEFAULT 0,
 `max_resend` tinyint(4) DEFAULT 3,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_token` (`token_hash`),
 KEY `idx_user_type` (`user_id`,`verify_type`),
 KEY `idx_expires` (`expires_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `etransfer_inbox`
--

DROP TABLE IF EXISTS `etransfer_inbox`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `etransfer_inbox` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `gmail_uid` varchar(100) DEFAULT NULL,
 `sender_email` varchar(255) DEFAULT NULL,
 `sender_name` varchar(200) DEFAULT NULL,
 `subject` text DEFAULT NULL,
 `amount` decimal(10,2) DEFAULT NULL,
 `reference_number` varchar(50) DEFAULT NULL,
 `deposit_status` enum('auto_deposited','pending_accept','manual') DEFAULT 'auto_deposited',
 `matched_order_id` int(10) unsigned DEFAULT NULL,
 `verification_status` enum('pending','verified','rejected','expired') DEFAULT 'pending',
 `verified_by` int(10) unsigned DEFAULT NULL,
 `verified_at` datetime DEFAULT NULL,
 `raw_body` text DEFAULT NULL,
 `received_at` datetime DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_gmail_uid` (`gmail_uid`),
 KEY `idx_status` (`verification_status`),
 KEY `idx_order` (`matched_order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `events`
--

DROP TABLE IF EXISTS `events`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `events` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `category` varchar(50) DEFAULT NULL,
 `action` varchar(100) DEFAULT NULL,
 `target_type` varchar(50) DEFAULT NULL,
 `target_id` int(10) unsigned DEFAULT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `user_agent` text DEFAULT NULL,
 `admin_id` int(10) unsigned DEFAULT NULL,
 `meta` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`meta`)),
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `fields_accessed` text DEFAULT NULL,
 `entity_type` varchar(50) DEFAULT NULL,
 `entity_id` int(10) unsigned DEFAULT NULL,
 `severity` varchar(20) DEFAULT 'info',
 `details` text DEFAULT NULL,
 `trigger_count` int(11) DEFAULT 0,
 PRIMARY KEY (`id`),
 KEY `idx_category` (`category`),
 KEY `idx_created` (`created_at`),
 KEY `idx_cat_action` (`category`,`action`)
) ENGINE=InnoDB AUTO_INCREMENT=312 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `excluded_devices`
--

DROP TABLE IF EXISTS `excluded_devices`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `excluded_devices` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `device_fingerprint` varchar(255) DEFAULT NULL,
 `reason` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `device_hash` varchar(64) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `faq`
--

DROP TABLE IF EXISTS `faq`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `faq` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `store_id` int(10) unsigned DEFAULT NULL,
 `tab_group` varchar(100) DEFAULT 'General',
 `question` text DEFAULT NULL,
 `answer` text DEFAULT NULL,
 `display_order` int(11) DEFAULT 0,
 `status` enum('active','hidden','deleted') DEFAULT 'active',
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `is_active` tinyint(1) DEFAULT 1,
 `category_id` int(10) unsigned DEFAULT NULL,
 `public_id` varchar(50) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `fleet_node_meta`
--

DROP TABLE IF EXISTS `fleet_node_meta`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `fleet_node_meta` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `node_id` varchar(50) DEFAULT NULL,
 `meta_key` varchar(100) DEFAULT NULL,
 `meta_value` text DEFAULT NULL,
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_node_key` (`node_id`,`meta_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `fleet_routing`
--

DROP TABLE IF EXISTS `fleet_routing`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `fleet_routing` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `source_node` varchar(50) DEFAULT NULL,
 `dest_node` varchar(50) DEFAULT NULL,
 `route_type` varchar(50) DEFAULT NULL,
 `is_active` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `fulfillment_notifications`
--

DROP TABLE IF EXISTS `fulfillment_notifications`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `fulfillment_notifications` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `order_id` int(10) unsigned NOT NULL,
 `stage` varchar(50) NOT NULL,
 `email_type` varchar(50) DEFAULT NULL,
 `status_code` int(11) DEFAULT 8301,
 `sent_at` datetime DEFAULT NULL,
 `error_log` text DEFAULT NULL,
 `idempotency_key` char(64) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_idempotent` (`order_id`,`stage`,`email_type`),
 KEY `idx_order` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `fulfillment_stages`
--

DROP TABLE IF EXISTS `fulfillment_stages`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `fulfillment_stages` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `order_id` int(10) unsigned NOT NULL,
 `from_stage` varchar(50) DEFAULT NULL,
 `to_stage` varchar(50) NOT NULL,
 `actor` enum('system','customer','admin','webhook','cron') NOT NULL,
 `idempotency_key` char(64) DEFAULT NULL,
 `metadata_enc` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_idempotent` (`order_id`,`idempotency_key`),
 KEY `idx_order` (`order_id`),
 KEY `idx_stage` (`to_stage`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `fulfillment_state_enum`
--

DROP TABLE IF EXISTS `fulfillment_state_enum`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `fulfillment_state_enum` (
 `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
 `state_key` varchar(50) NOT NULL,
 `state_label` varchar(100) DEFAULT NULL,
 `category` enum('active','terminal','exception') DEFAULT 'active',
 `is_terminal` tinyint(1) DEFAULT 0,
 `email_trigger` varchar(50) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_key` (`state_key`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `honeypot_hits`
--

DROP TABLE IF EXISTS `honeypot_hits`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `honeypot_hits` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ip_address` varchar(45) DEFAULT NULL,
 `trap_type` varchar(50) DEFAULT NULL,
 `user_agent` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `request_method` varchar(10) DEFAULT NULL,
 `trap_route` varchar(200) DEFAULT NULL,
 `cnt` int(11) DEFAULT 1,
 PRIMARY KEY (`id`),
 KEY `idx_ip` (`ip_address`),
 KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `inventory`
--

DROP TABLE IF EXISTS `inventory`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `inventory` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `product_id` int(10) unsigned NOT NULL,
 `store_id` int(10) unsigned NOT NULL,
 `stock_quantity` int(11) NOT NULL DEFAULT 0,
 `stock_reserved` int(11) NOT NULL DEFAULT 0,
 `low_stock_threshold` int(11) NOT NULL DEFAULT 5,
 `last_counted_at` datetime DEFAULT NULL,
 `status_code` int(11) DEFAULT 6001,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_product_store` (`product_id`,`store_id`),
 KEY `idx_stock` (`stock_quantity`),
 KEY `idx_low` (`low_stock_threshold`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `inventory_movements`
--

DROP TABLE IF EXISTS `inventory_movements`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `inventory_movements` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `inventory_id` int(10) unsigned NOT NULL,
 `product_id` int(10) unsigned NOT NULL,
 `movement_type` enum('reserve','release','commit','return','adjust','count') NOT NULL,
 `quantity_delta` int(11) NOT NULL,
 `order_id` int(10) unsigned DEFAULT NULL,
 `reason` varchar(255) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_inventory` (`inventory_id`),
 KEY `idx_product` (`product_id`),
 KEY `idx_order` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `listing_blocks`
--

DROP TABLE IF EXISTS `listing_blocks`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `listing_blocks` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `listing_id` int(10) unsigned DEFAULT NULL,
 `block_key` varchar(100) DEFAULT NULL,
 `content` text DEFAULT NULL,
 `display_order` int(11) DEFAULT 0,
 `is_active` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `marketing_campaigns`
--

DROP TABLE IF EXISTS `marketing_campaigns`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `marketing_campaigns` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(200) DEFAULT NULL,
 `platform` enum('meta','google','tiktok','manual') DEFAULT 'manual',
 `budget` decimal(10,2) DEFAULT 0.00,
 `status` enum('active','paused','archived') DEFAULT 'active',
 `meta` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`meta`)),
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `slug` varchar(200) DEFAULT NULL,
 `campaign_name` text DEFAULT NULL,
 `hits` int(11) DEFAULT 0,
 `unique_visitors` int(11) DEFAULT 0,
 `conversions` int(11) DEFAULT 0,
 `nginx_active` tinyint(1) DEFAULT 0,
 `daily_budget` decimal(10,2) DEFAULT NULL,
 `last_synced_at` datetime DEFAULT NULL,
 `lifetime_budget` decimal(10,2) DEFAULT 0.00,
 `objective` varchar(100) DEFAULT NULL,
 `spend` decimal(10,2) DEFAULT 0.00,
 `total_spend` decimal(10,2) DEFAULT 0.00,
 `campaign_id` varchar(100) DEFAULT NULL,
 `clicks` int(11) DEFAULT 0,
 `status_code` int(11) DEFAULT 7000,
 PRIMARY KEY (`id`),
 KEY `idx_status_code` (`status_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `marketing_links`
--

DROP TABLE IF EXISTS `marketing_links`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `marketing_links` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `slug` varchar(200) DEFAULT NULL,
 `campaign_name` text DEFAULT NULL,
 `hits` int(11) DEFAULT 0,
 `unique_visitors` int(11) DEFAULT 0,
 `conversions` int(11) DEFAULT 0,
 `nginx_active` tinyint(1) DEFAULT 0,
 `status` varchar(20) DEFAULT 'draft',
 `created_at` datetime DEFAULT current_timestamp(),
 `daily_budget` decimal(10,2) DEFAULT 0.00,
 `status_code` int(11) DEFAULT 7000,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `merkle_anchors`
--

DROP TABLE IF EXISTS `merkle_anchors`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `merkle_anchors` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `anchor_hash` varchar(255) DEFAULT NULL,
 `table_name` varchar(100) DEFAULT NULL,
 `row_count` int(11) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `block_height` int(11) DEFAULT NULL,
 `first_event_id` int(10) unsigned DEFAULT NULL,
 `last_event_id` int(10) unsigned DEFAULT NULL,
 `leaf_count` int(11) DEFAULT 0,
 `merkle_root` varchar(128) DEFAULT NULL,
 `tx_id` varchar(128) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `meta_ad_accounts`
--

DROP TABLE IF EXISTS `meta_ad_accounts`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `meta_ad_accounts` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `account_id` varchar(100) DEFAULT NULL,
 `account_name` varchar(200) DEFAULT NULL,
 `access_token` text DEFAULT NULL,
 `status` varchar(20) DEFAULT 'active',
 `created_at` datetime DEFAULT current_timestamp(),
 `currency` varchar(10) DEFAULT 'USD',
 `meta_account_id` varchar(100) DEFAULT NULL,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `meta_campaigns`
--

DROP TABLE IF EXISTS `meta_campaigns`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `meta_campaigns` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ad_account_id` int(10) unsigned DEFAULT NULL,
 `campaign_id` varchar(100) DEFAULT NULL,
 `campaign_name` varchar(200) DEFAULT NULL,
 `status` varchar(20) DEFAULT 'active',
 `daily_budget` decimal(10,2) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `mkt_creatives`
--

DROP TABLE IF EXISTS `mkt_creatives`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `mkt_creatives` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `prompt` text DEFAULT NULL,
 `image_url` varchar(500) DEFAULT NULL,
 `status` varchar(30) DEFAULT 'pending',
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `title` varchar(255) DEFAULT NULL,
 `platform_id` int(11) DEFAULT NULL,
 `category` varchar(100) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `mkt_social_assets`
--

DROP TABLE IF EXISTS `mkt_social_assets`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `mkt_social_assets` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `asset_type` varchar(50) DEFAULT NULL,
 `content` text DEFAULT NULL,
 `status` varchar(20) DEFAULT 'active',
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `category` varchar(100) DEFAULT NULL,
 `node_id` int(10) unsigned DEFAULT NULL,
 `platform_id` int(11) DEFAULT NULL,
 `title` varchar(255) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `mkt_social_nodes`
--

DROP TABLE IF EXISTS `mkt_social_nodes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `mkt_social_nodes` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `identity_ref` varchar(100) DEFAULT NULL,
 `platform` varchar(50) DEFAULT NULL,
 `node_url` varchar(500) DEFAULT NULL,
 `status` varchar(20) DEFAULT 'active',
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `health_score` int(11) DEFAULT 100,
 `proxy_config` text DEFAULT NULL,
 `last_activity` datetime DEFAULT NULL,
 `status_code` int(11) DEFAULT 7000,
 `credentials_enc` text DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- DROPPED: This view was removed per ARSENAL.md Post-Audit Fix #13. Retained in dump for historical reference only.
-- Temporary table structure for view `nn_page_blocks`
--

DROP TABLE IF EXISTS `nn_page_blocks`;
/*!50001 DROP VIEW IF EXISTS `nn_page_blocks`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8mb4;
/*!50001 CREATE VIEW `nn_page_blocks` AS SELECT
 1 AS `id`,
 1 AS `store_id`,
 1 AS `page`,
 1 AS `block_key`,
 1 AS `content`,
 1 AS `display_order`,
 1 AS `is_active`,
 1 AS `created_at` */;
SET character_set_client = @saved_cs_client;

--
-- DROPPED: This view was removed per ARSENAL.md Post-Audit Fix #13. Retained in dump for historical reference only.
-- Temporary table structure for view `nn_product_catalog`
--

DROP TABLE IF EXISTS `nn_product_catalog`;
/*!50001 DROP VIEW IF EXISTS `nn_product_catalog`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8mb4;
/*!50001 CREATE VIEW `nn_product_catalog` AS SELECT
 1 AS `id`,
 1 AS `store_id`,
 1 AS `category_id`,
 1 AS `sku`,
 1 AS `name`,
 1 AS `title`,
 1 AS `nickname`,
 1 AS `slug`,
 1 AS `description`,
 1 AS `quality`,
 1 AS `type`,
 1 AS `short_desc`,
 1 AS `pitch_title`,
 1 AS `pitch_body`,
 1 AS `notes`,
 1 AS `image`,
 1 AS `image_url`,
 1 AS `image_path`,
 1 AS `price`,
 1 AS `sale_price`,
 1 AS `base_price`,
 1 AS `has_qualities`,
 1 AS `has_types`,
 1 AS `unit_label`,
 1 AS `status`,
 1 AS `status_code`,
 1 AS `visibility_code`,
 1 AS `visibility`,
 1 AS `display_order`,
 1 AS `created_at`,
 1 AS `updated_at`,
 1 AS `slot_size`,
 1 AS `unit_increment`,
 1 AS `unit_price_per`,
 1 AS `unit_tiers`,
 1 AS `unit_min_qty`,
 1 AS `featured_code`,
 1 AS `unit_pricing_code`,
 1 AS `is_encrypted`,
 1 AS `gallery`,
 1 AS `meta_json`,
 1 AS `currency_code`,
 1 AS `product_code` */;
SET character_set_client = @saved_cs_client;

--
-- DROPPED: This view was removed per ARSENAL.md Post-Audit Fix #13. Retained in dump for historical reference only.
-- Temporary table structure for view `nn_product_categories`
--

DROP TABLE IF EXISTS `nn_product_categories`;
/*!50001 DROP VIEW IF EXISTS `nn_product_categories`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8mb4;
/*!50001 CREATE VIEW `nn_product_categories` AS SELECT
 1 AS `id`,
 1 AS `store_id`,
 1 AS `name`,
 1 AS `nickname`,
 1 AS `slug`,
 1 AS `display_order`,
 1 AS `show_in_nav`,
 1 AS `status`,
 1 AS `status_code`,
 1 AS `created_at`,
 1 AS `description` */;
SET character_set_client = @saved_cs_client;

--
-- DROPPED: This view was removed per ARSENAL.md Post-Audit Fix #13. Retained in dump for historical reference only.
-- Temporary table structure for view `nn_store_products`
--

DROP TABLE IF EXISTS `nn_store_products`;
/*!50001 DROP VIEW IF EXISTS `nn_store_products`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8mb4;
/*!50001 CREATE VIEW `nn_store_products` AS SELECT
 1 AS `id`,
 1 AS `store_id`,
 1 AS `category_id`,
 1 AS `sku`,
 1 AS `name`,
 1 AS `title`,
 1 AS `nickname`,
 1 AS `slug`,
 1 AS `description`,
 1 AS `quality`,
 1 AS `type`,
 1 AS `short_desc`,
 1 AS `pitch_title`,
 1 AS `pitch_body`,
 1 AS `notes`,
 1 AS `image`,
 1 AS `image_url`,
 1 AS `image_path`,
 1 AS `price`,
 1 AS `sale_price`,
 1 AS `base_price`,
 1 AS `has_qualities`,
 1 AS `has_types`,
 1 AS `unit_label`,
 1 AS `status`,
 1 AS `status_code`,
 1 AS `visibility_code`,
 1 AS `visibility`,
 1 AS `display_order`,
 1 AS `created_at`,
 1 AS `updated_at`,
 1 AS `slot_size`,
 1 AS `unit_increment`,
 1 AS `unit_price_per`,
 1 AS `unit_tiers`,
 1 AS `unit_min_qty`,
 1 AS `featured_code`,
 1 AS `unit_pricing_code`,
 1 AS `is_encrypted`,
 1 AS `gallery`,
 1 AS `meta_json`,
 1 AS `currency_code`,
 1 AS `product_code`,
 1 AS `pid` */;
SET character_set_client = @saved_cs_client;

--
-- Table structure for table `node_commands`
--

DROP TABLE IF EXISTS `node_commands`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `node_commands` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `node_id` int(10) unsigned NOT NULL,
 `command` text DEFAULT NULL,
 `status` enum('queued','approved','executing','completed','failed','cancelled') DEFAULT 'queued',
 `output` mediumtext DEFAULT NULL,
 `exit_code` int(11) DEFAULT NULL,
 `queued_by` int(10) unsigned DEFAULT NULL,
 `approved_by` int(10) unsigned DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `completed_at` datetime DEFAULT NULL,
 `status_code` int(11) DEFAULT 5010,
 `priority_code` int(11) DEFAULT 5000,
 `ack_at` datetime DEFAULT NULL,
 `admin_id` int(10) unsigned DEFAULT NULL,
 `result` text DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `node_pulses`
--

DROP TABLE IF EXISTS `node_pulses`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `node_pulses` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `node_id` varchar(10) NOT NULL,
 `event_type` varchar(50) NOT NULL DEFAULT 'tool_exec',
 `tool_name` varchar(50) DEFAULT '',
 `result` varchar(100) DEFAULT 'ok',
 `duration_ms` int(10) unsigned DEFAULT 0,
 `created_at` datetime NOT NULL,
 PRIMARY KEY (`id`),
 KEY `idx_node_time` (`node_id`,`created_at`),
 KEY `idx_event` (`event_type`,`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `nodes`
--

DROP TABLE IF EXISTS `nodes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `nodes` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `node_id` varchar(50) DEFAULT NULL,
 `role` varchar(50) DEFAULT NULL,
 `node_role` varchar(50) DEFAULT NULL,
 `hostname` varchar(500) DEFAULT NULL,
 `public_ip` varchar(500) DEFAULT NULL,
 `wg_ip` varchar(500) DEFAULT NULL,
 `wg_pubkey` text DEFAULT NULL,
 `ssh_port` int(11) DEFAULT 9922,
 `status` enum('online','offline','maintenance','provisioning','decommissioned') DEFAULT 'offline',
 `cpu_usage` decimal(5,2) DEFAULT 0.00,
 `mem_usage` decimal(5,2) DEFAULT 0.00,
 `disk_usage` decimal(5,2) DEFAULT 0.00,
 `engine_version` varchar(50) DEFAULT NULL,
 `last_heartbeat` datetime DEFAULT NULL,
 `consecutive_misses` int(11) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 `metrics` text DEFAULT NULL,
 `role_code` int(11) DEFAULT NULL,
 `wg_pub_key` text DEFAULT NULL,
 `node_name` varchar(500) DEFAULT NULL,
 `ip_address` varchar(500) DEFAULT NULL,
 `latency_ms` int(11) DEFAULT NULL,
 `ssh_user` varchar(50) DEFAULT 'admin',
 `uptime_seconds` bigint(20) DEFAULT NULL,
 `cpu_usage_pct` decimal(5,2) DEFAULT NULL,
 `mem_usage_pct` decimal(5,2) DEFAULT NULL,
 `disk_usage_pct` decimal(5,2) DEFAULT NULL,
 `canvas_x` int(11) DEFAULT 0,
 `canvas_y` int(11) DEFAULT 0,
 `is_active` tinyint(4) DEFAULT 1,
 `is_reachable` tinyint(4) DEFAULT 1,
 `last_seen` datetime DEFAULT NULL,
 `wg_peers` text DEFAULT NULL,
 `standby_node_id` int(10) unsigned DEFAULT NULL,
 `standby_ready` tinyint(4) DEFAULT 0,
 `api_port` int(11) DEFAULT NULL,
 `cpu_cores` int(11) DEFAULT NULL,
 `ram_gb` int(11) DEFAULT NULL,
 `disk_gb` int(11) DEFAULT NULL,
 `bandwidth_tb` int(11) DEFAULT NULL,
 `service_url` varchar(1000) DEFAULT NULL,
 `location_city` varchar(500) DEFAULT NULL,
 `location_country` varchar(500) DEFAULT NULL,
 `datacenter` varchar(500) DEFAULT NULL,
 `provider` varchar(500) DEFAULT NULL,
 `monthly_cost_cad` varchar(50) DEFAULT NULL,
 `payment_method` varchar(100) DEFAULT NULL,
 `renewal_date` varchar(50) DEFAULT NULL,
 `os` varchar(100) DEFAULT NULL,
 `notes` text DEFAULT NULL,
 `standby_name` varchar(100) DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `node_id` (`node_id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `order_items`
--

DROP TABLE IF EXISTS `order_items`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `order_items` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `order_id` int(10) unsigned NOT NULL,
 `variant_id` int(10) unsigned NOT NULL,
 `size_id` int(10) unsigned DEFAULT NULL,
 `product_name` text DEFAULT NULL,
 `quality_name` varchar(100) DEFAULT NULL,
 `type_name` varchar(100) DEFAULT NULL,
 `size_label` varchar(50) DEFAULT NULL,
 `quantity` int(11) DEFAULT 1,
 `unit_price` decimal(10,2) NOT NULL,
 `total_price` decimal(10,2) NOT NULL,
 `listing_id` int(10) unsigned DEFAULT NULL,
 `listing_name` text DEFAULT NULL,
 `qty` int(11) DEFAULT 1,
 `unit_label` varchar(50) DEFAULT NULL,
 `item_order` int(11) DEFAULT 0,
 `block_type` varchar(50) DEFAULT NULL,
 `is_active` tinyint(4) DEFAULT 1,
 `item_ref_id` int(10) unsigned DEFAULT NULL,
 `item_type` varchar(50) DEFAULT NULL,
 `product_image_url` varchar(500) DEFAULT NULL,
 `product_price_enc` text DEFAULT NULL,
 `product_title_enc` text DEFAULT NULL,
 `row_id` int(10) unsigned DEFAULT NULL,
 `slot_width` int(11) DEFAULT 1,
 PRIMARY KEY (`id`),
 KEY `order_id` (`order_id`),
 CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `orders`
--

DROP TABLE IF EXISTS `orders`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `orders` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `store_id` int(10) unsigned NOT NULL,
 `user_id` int(10) unsigned DEFAULT NULL,
 `listing_id` int(10) unsigned DEFAULT NULL,
 `reference` varchar(20) DEFAULT NULL,
 `order_ref` varchar(20) DEFAULT NULL,
 `email` text DEFAULT NULL,
 `email_enc` text DEFAULT NULL,
 `name` text DEFAULT NULL,
 `name_enc` text DEFAULT NULL,
 `address` text DEFAULT NULL,
 `address_enc` text DEFAULT NULL,
 `city` text DEFAULT NULL,
 `city_enc` varchar(200) DEFAULT NULL,
 `province` varchar(100) DEFAULT NULL,
 `province_enc` varchar(200) DEFAULT NULL,
 `postal_code` text DEFAULT NULL,
 `postal_code_enc` varchar(50) DEFAULT NULL,
 `country` varchar(50) DEFAULT 'CA',
 `subtotal` decimal(10,2) DEFAULT 0.00,
 `shipping` decimal(10,2) DEFAULT 0.00,
 `total` decimal(10,2) DEFAULT 0.00,
 `payment_method` enum('stripe','etransfer','crypto','credit') DEFAULT 'stripe',
 `status` enum('pending','paid','processing','packed','shipped','delivered','cancelled','refunded','disputed','hold') DEFAULT 'pending',
 `tracking_number` text DEFAULT NULL,
 `tracking_carrier` varchar(50) DEFAULT NULL,
 `fulfillment_log` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`fulfillment_log`)),
 `notes` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 `status_label` varchar(50) DEFAULT NULL,
 `canada_post_tracking` varchar(100) DEFAULT NULL,
 `etransfer_ref` varchar(100) DEFAULT NULL,
 `fulfillment_json` text DEFAULT NULL,
 `fulfillment_stage` varchar(50) DEFAULT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `agreement_timestamps` text DEFAULT NULL,
 `is_test` tinyint(1) DEFAULT 0,
 `product_title` text DEFAULT NULL,
 `quantity` int(11) DEFAULT 1,
 `shipping_method` varchar(50) DEFAULT NULL,
 `shipping_name` text DEFAULT NULL,
 `stage_updated_at` datetime DEFAULT NULL,
 `time_at_checkout` int(11) DEFAULT NULL,
 `title` text DEFAULT NULL,
 `tracking_ref` varchar(100) DEFAULT NULL,
 `user_agent` text DEFAULT NULL,
 `address2` text DEFAULT NULL,
 `payment_method_detail` text DEFAULT NULL,
 `shipping_fee` decimal(10,2) DEFAULT 0.00,
 PRIMARY KEY (`id`),
 UNIQUE KEY `reference` (`reference`),
 KEY `idx_store` (`store_id`),
 KEY `idx_user` (`user_id`),
 KEY `idx_status` (`status`),
 KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `page_blocks`
--

DROP TABLE IF EXISTS `page_blocks`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `page_blocks` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `store_id` int(10) unsigned DEFAULT NULL,
 `page` varchar(50) DEFAULT NULL,
 `block_key` varchar(100) DEFAULT NULL,
 `content` text DEFAULT NULL,
 `display_order` int(11) DEFAULT 0,
 `is_active` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `payment_cards`
--

DROP TABLE IF EXISTS `payment_cards`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `payment_cards` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `last_four` varchar(4) DEFAULT NULL,
 `brand` varchar(20) DEFAULT NULL,
 `exp_month` tinyint(4) DEFAULT NULL,
 `exp_year` smallint(6) DEFAULT NULL,
 `is_default` tinyint(1) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 `card_name` text DEFAULT NULL,
 `initial_balance` decimal(10,2) DEFAULT 0.00,
 `current_balance` decimal(10,2) DEFAULT 0.00,
 `expiry` varchar(5) DEFAULT NULL,
 `updated_at` datetime DEFAULT NULL,
 `nickname` varchar(100) DEFAULT NULL,
 `card_number` text DEFAULT NULL,
 `last_4` varchar(4) DEFAULT NULL,
 `status` varchar(30) DEFAULT 'active',
 `status_code` int(11) DEFAULT 7010,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `payment_ledger`
--

DROP TABLE IF EXISTS `payment_ledger`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `payment_ledger` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `order_id` int(10) unsigned DEFAULT NULL,
 `payment_method` enum('etransfer','crypto','stripe','credit','manual') DEFAULT NULL,
 `amount` decimal(10,2) NOT NULL DEFAULT 0.00,
 `currency` varchar(5) DEFAULT 'CAD',
 `direction` enum('credit','debit','refund') DEFAULT 'credit',
 `reference` varchar(100) DEFAULT NULL,
 `notes` text DEFAULT NULL,
 `admin_id` int(10) unsigned DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `reference_code` varchar(100) DEFAULT NULL,
 `status` varchar(30) DEFAULT 'pending',
 `sender_name` varchar(200) DEFAULT NULL,
 `sender_email` varchar(255) DEFAULT NULL,
 `confirmed_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `idx_order` (`order_id`),
 KEY `idx_method` (`payment_method`),
 KEY `idx_date` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `payment_logs`
--

DROP TABLE IF EXISTS `payment_logs`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `payment_logs` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `order_id` int(10) unsigned DEFAULT NULL,
 `method` varchar(50) DEFAULT NULL,
 `amount` decimal(10,2) DEFAULT 0.00,
 `status` varchar(50) DEFAULT NULL,
 `raw_response` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `amount_cad` decimal(10,2) DEFAULT NULL,
 `amount_xmr` decimal(20,12) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `payments`
--

DROP TABLE IF EXISTS `payments`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `payments` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `order_id` int(10) unsigned DEFAULT NULL,
 `method` enum('stripe','etransfer','crypto','credit') DEFAULT NULL,
 `amount` decimal(10,2) NOT NULL,
 `currency` varchar(10) DEFAULT 'CAD',
 `stripe_id` varchar(100) DEFAULT NULL,
 `tx_hash` varchar(200) DEFAULT NULL,
 `status` enum('pending','confirmed','failed','refunded') DEFAULT 'pending',
 `meta` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`meta`)),
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `order_ref` varchar(20) DEFAULT NULL,
 `status_code` int(11) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_pricing_tiers`
--

DROP TABLE IF EXISTS `product_pricing_tiers`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_pricing_tiers` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `product_id` int(10) unsigned DEFAULT NULL,
 `min_qty` int(11) DEFAULT 1,
 `max_qty` int(11) DEFAULT NULL,
 `price` decimal(10,2) DEFAULT 0.00,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `is_active` tinyint(4) DEFAULT 1,
 `is_default` tinyint(4) DEFAULT 0,
 `quantity` int(11) DEFAULT 1,
 `tier_label` varchar(100) DEFAULT NULL,
 `tier_order` int(11) DEFAULT 0,
 `unit_price` decimal(10,2) DEFAULT 0.00,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_qualities`
--

DROP TABLE IF EXISTS `product_qualities`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_qualities` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `product_id` int(10) unsigned DEFAULT NULL,
 `name` varchar(100) DEFAULT NULL,
 `quality_name` text DEFAULT NULL,
 `base_price` text DEFAULT NULL,
 `image_path` varchar(500) DEFAULT NULL,
 `is_active` tinyint(1) DEFAULT 1,
 `display_order` int(11) DEFAULT 0,
 PRIMARY KEY (`id`),
 KEY `product_id` (`product_id`),
 CONSTRAINT `product_qualities_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_sizes`
--

DROP TABLE IF EXISTS `product_sizes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_sizes` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `variant_id` int(10) unsigned DEFAULT NULL,
 `label` varchar(50) DEFAULT NULL,
 `amount` decimal(10,3) DEFAULT 0.000,
 `price` decimal(10,2) DEFAULT 0.00,
 `display_order` int(11) DEFAULT 0,
 PRIMARY KEY (`id`),
 KEY `variant_id` (`variant_id`),
 CONSTRAINT `product_sizes_ibfk_1` FOREIGN KEY (`variant_id`) REFERENCES `product_variants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_types`
--

DROP TABLE IF EXISTS `product_types`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_types` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `product_id` int(10) unsigned DEFAULT NULL,
 `name` varchar(100) DEFAULT NULL,
 `type_name` text DEFAULT NULL,
 `base_price` text DEFAULT NULL,
 `image_path` varchar(500) DEFAULT NULL,
 `is_active` tinyint(1) DEFAULT 1,
 `display_order` int(11) DEFAULT 0,
 PRIMARY KEY (`id`),
 KEY `product_id` (`product_id`),
 CONSTRAINT `product_types_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_units`
--

DROP TABLE IF EXISTS `product_units`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_units` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `product_id` int(10) unsigned NOT NULL,
 `quality_id` int(10) unsigned DEFAULT NULL,
 `unit_amount` text DEFAULT NULL,
 `unit_price` text DEFAULT NULL,
 `display_order` int(11) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_product_id` (`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_variants`
--

DROP TABLE IF EXISTS `product_variants`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_variants` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `product_id` int(10) unsigned DEFAULT NULL,
 `quality_id` int(10) unsigned DEFAULT NULL,
 `type_id` int(10) unsigned DEFAULT NULL,
 `sku` varchar(50) DEFAULT NULL,
 `image` varchar(500) DEFAULT NULL,
 `price` decimal(10,2) DEFAULT 0.00,
 `sale_price` decimal(10,2) DEFAULT NULL,
 `stock` int(11) DEFAULT -1,
 `status` enum('active','paused','deleted') DEFAULT 'active',
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `sku` (`sku`),
 KEY `product_id` (`product_id`),
 CONSTRAINT `product_variants_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `products`
--

DROP TABLE IF EXISTS `products`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `store_id` int(10) unsigned DEFAULT 1,
 `category_id` int(10) unsigned DEFAULT NULL,
 `sku` varchar(50) DEFAULT NULL,
 `name` text DEFAULT NULL,
 `name_enc` text DEFAULT NULL,
 `title` text DEFAULT NULL,
 `title_enc` text DEFAULT NULL,
 `nickname` varchar(200) DEFAULT NULL,
 `slug` varchar(200) DEFAULT NULL,
 `description` text DEFAULT NULL,
 `description_enc` text DEFAULT NULL,
 `quality` text DEFAULT NULL,
 `type` text DEFAULT NULL,
 `short_desc` text DEFAULT NULL,
 `pitch_title` text DEFAULT NULL,
 `pitch_body` text DEFAULT NULL,
 `notes` text DEFAULT NULL,
 `image` varchar(500) DEFAULT NULL,
 `image_url` text DEFAULT NULL,
 `image_path` text DEFAULT NULL,
 `price` decimal(10,2) DEFAULT 0.00,
 `stock_quantity` int(11) NOT NULL DEFAULT 0,
 `stock_reserved` int(11) NOT NULL DEFAULT 0,
 `sale_price` decimal(10,2) DEFAULT NULL,
 `base_price` text DEFAULT NULL,
 `has_qualities` tinyint(1) DEFAULT 0,
 `has_types` tinyint(1) DEFAULT 0,
 `unit_label` text DEFAULT NULL,
 `status` varchar(20) DEFAULT 'draft',
 `status_code` int(11) DEFAULT 3001,
 `visibility_code` int(11) DEFAULT 5001,
 `visibility` varchar(20) DEFAULT 'public',
 `display_order` int(11) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 `slot_size` int(11) DEFAULT 1,
 `unit_increment` decimal(10,3) DEFAULT NULL,
 `unit_price_per` decimal(10,2) DEFAULT NULL,
 `unit_tiers` text DEFAULT NULL,
 `unit_min_qty` int(11) DEFAULT 1,
 `featured_code` int(11) DEFAULT NULL,
 `unit_pricing_code` int(11) DEFAULT NULL,
 `is_encrypted` tinyint(1) DEFAULT 0,
 `gallery` text DEFAULT NULL,
 `meta_json` text DEFAULT NULL,
 `currency_code` varchar(5) DEFAULT 'CAD',
 `product_code` varchar(50) DEFAULT NULL,
 `variant_label` text DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `sku` (`sku`),
 KEY `idx_store` (`store_id`),
 KEY `idx_category` (`category_id`),
 KEY `idx_status` (`status`),
 KEY `idx_store_status` (`store_id`,`status`),
 KEY `idx_visibility` (`visibility_code`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `public_ids`
--

DROP TABLE IF EXISTS `public_ids`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `public_ids` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `public_id` varchar(50) DEFAULT NULL,
 `internal_id` int(10) unsigned NOT NULL,
 `entity_type` varchar(50) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `public_id` (`public_id`),
 KEY `idx_entity` (`entity_type`,`internal_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `rate_limits`
--

DROP TABLE IF EXISTS `rate_limits`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `rate_limits` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ip_address` varchar(45) DEFAULT NULL,
 `endpoint` varchar(100) DEFAULT NULL,
 `hits` int(11) DEFAULT 1,
 `window_start` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_lookup` (`ip_address`,`endpoint`),
 KEY `idx_ip_endpoint` (`ip_address`,`endpoint`,`window_start`)
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `referral_codes`
--

DROP TABLE IF EXISTS `referral_codes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `referral_codes` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned NOT NULL,
 `code` varchar(50) NOT NULL,
 `credits_earned` int(11) DEFAULT 0,
 `referred_count` int(11) DEFAULT 0,
 `is_active` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `code` (`code`),
 KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `review_codes`
--

DROP TABLE IF EXISTS `review_codes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `review_codes` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned NOT NULL,
 `order_id` int(10) unsigned DEFAULT NULL,
 `code` varchar(64) NOT NULL,
 `used` tinyint(1) DEFAULT 0,
 `credited` tinyint(1) DEFAULT 0,
 `expires_at` datetime DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `code` (`code`),
 KEY `idx_user_id` (`user_id`),
 KEY `idx_used_expires` (`used`,`expires_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `review_votes`
--

DROP TABLE IF EXISTS `review_votes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `review_votes` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `review_id` int(10) unsigned NOT NULL,
 `ip_address` varchar(45) NOT NULL,
 `vote_score` tinyint(4) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_review_ip` (`review_id`,`ip_address`),
 KEY `idx_review_id` (`review_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `reviews`
--

DROP TABLE IF EXISTS `reviews`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `reviews` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `store_id` int(10) unsigned NOT NULL,
 `user_id` int(10) unsigned DEFAULT NULL,
 `product_id` int(10) unsigned DEFAULT NULL,
 `rating` tinyint(4) DEFAULT 5,
 `title` text DEFAULT NULL,
 `body` text DEFAULT NULL,
 `is_approved` tinyint(1) DEFAULT 0,
 `is_verified` tinyint(1) DEFAULT 0,
 `admin_reply` text DEFAULT NULL,
 `helpful_count` int(11) DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_bash_integrity`
--

DROP TABLE IF EXISTS `sec_bash_integrity`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_bash_integrity` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `file_path` varchar(512) NOT NULL,
 `expected_hash` varchar(64) NOT NULL,
 `actual_hash` varchar(64) NOT NULL,
 `matched` tinyint(4) DEFAULT 0,
 `checked_at` datetime DEFAULT NULL,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node_file` (`node_id`,`file_path`),
 KEY `idx_matched` (`matched`),
 KEY `idx_checked` (`checked_at`)
) ENGINE=InnoDB AUTO_INCREMENT=302 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_blacklist_nft`
--

DROP TABLE IF EXISTS `sec_blacklist_nft`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_blacklist_nft` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ip_address_enc` varchar(255) NOT NULL,
 `reason_enc` text DEFAULT NULL,
 `severity` enum('low','medium','high','critical') DEFAULT 'medium',
 `node_target` varchar(20) DEFAULT NULL,
 `expires_at` datetime DEFAULT NULL,
 `rule_handle` varchar(100) DEFAULT NULL,
 `status_code` int(11) DEFAULT 7000,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_ip` (`ip_address_enc`),
 KEY `idx_expires` (`expires_at`),
 KEY `idx_node` (`node_target`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_canary_triggers`
--

DROP TABLE IF EXISTS `sec_canary_triggers`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_canary_triggers` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `canary_type` varchar(64) NOT NULL,
 `canary_value_enc` longtext DEFAULT NULL,
 `trigger_source_ip_enc` longtext DEFAULT NULL,
 `detected_at` datetime DEFAULT NULL,
 `response_action` varchar(64) DEFAULT NULL,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node_type` (`node_id`,`canary_type`),
 KEY `idx_detected` (`detected_at`),
 KEY `idx_status` (`status_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_config_rotations`
--

DROP TABLE IF EXISTS `sec_config_rotations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_config_rotations` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `config_type` varchar(64) NOT NULL,
 `old_hash` varchar(64) NOT NULL,
 `new_hash` varchar(64) NOT NULL,
 `rotated_at` datetime DEFAULT NULL,
 `applied` tinyint(4) DEFAULT 0,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node_type` (`node_id`,`config_type`),
 KEY `idx_rotated` (`rotated_at`),
 KEY `idx_status` (`status_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_events`
--

DROP TABLE IF EXISTS `sec_events`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_events` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `event_uuid` char(36) NOT NULL,
 `node_id` varchar(20) DEFAULT NULL,
 `source_tag` enum('engine','s3rv1c3agent','bash','dms','container') NOT NULL,
 `event_type` varchar(50) NOT NULL,
 `severity` enum('info','low','medium','high','critical') DEFAULT 'info',
 `event_code` int(11) DEFAULT NULL,
 `ip_address_enc` varchar(255) DEFAULT NULL,
 `session_hash` char(64) DEFAULT NULL,
 `payload_enc` mediumtext DEFAULT NULL,
 `hmac_valid` tinyint(1) DEFAULT 0,
 `processed` tinyint(1) DEFAULT 0,
 `response_action` enum('none','iptables_drop','nftables_block','wg_revoke','lockdown','alert','captcha') DEFAULT 'none',
 `response_node` varchar(20) DEFAULT NULL,
 `processed_at` datetime DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_uuid` (`event_uuid`),
 KEY `idx_unprocessed` (`processed`,`created_at`),
 KEY `idx_node` (`node_id`),
 KEY `idx_type` (`event_type`),
 KEY `idx_severity` (`severity`),
 KEY `idx_source` (`source_tag`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_hash_mismatches`
--

DROP TABLE IF EXISTS `sec_hash_mismatches`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_hash_mismatches` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `node_id` varchar(20) NOT NULL,
 `file_path_enc` text NOT NULL,
 `expected_hash` char(64) NOT NULL,
 `actual_hash` char(64) NOT NULL,
 `consecutive_count` tinyint(4) DEFAULT 1,
 `dms_triggered` tinyint(1) DEFAULT 0,
 `status_code` int(11) DEFAULT 9001,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_node` (`node_id`),
 KEY `idx_consecutive` (`consecutive_count`),
 KEY `idx_dms` (`dms_triggered`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_key_rotations`
--

DROP TABLE IF EXISTS `sec_key_rotations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_key_rotations` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `key_type` varchar(64) NOT NULL,
 `old_fp_enc` longtext DEFAULT NULL,
 `new_fp_enc` longtext DEFAULT NULL,
 `rotated_at` datetime DEFAULT NULL,
 `verified` tinyint(4) DEFAULT 0,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node_type` (`node_id`,`key_type`),
 KEY `idx_rotated` (`rotated_at`),
 KEY `idx_status` (`status_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_keystroke_profiles`
--

DROP TABLE IF EXISTS `sec_keystroke_profiles`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_keystroke_profiles` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `session_hash` char(64) DEFAULT NULL,
 `dwell_time_ms` int(11) DEFAULT NULL,
 `flight_time_ms` int(11) DEFAULT NULL,
 `typing_speed` int(11) DEFAULT NULL,
 `is_bot_suspected` tinyint(1) DEFAULT 0,
 `data` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_lockdown_log`
--

DROP TABLE IF EXISTS `sec_lockdown_log`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_lockdown_log` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `node_id` varchar(20) DEFAULT NULL,
 `reason_enc` text DEFAULT NULL,
 `trigger_source` enum('engine','s3rv1c3agent','bash','dms') DEFAULT NULL,
 `data` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_lockdown_state`
--

DROP TABLE IF EXISTS `sec_lockdown_state`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_lockdown_state` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `level` int(11) DEFAULT 0,
 `activated_at` datetime DEFAULT NULL,
 `deactivated_at` datetime DEFAULT NULL,
 `activated_by` varchar(64) DEFAULT NULL,
 `reason_enc` longtext DEFAULT NULL,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node` (`node_id`),
 KEY `idx_level` (`level`),
 KEY `idx_activated` (`activated_at`),
 KEY `idx_status` (`status_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_node_tools`
--

DROP TABLE IF EXISTS `sec_node_tools`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_node_tools` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `tool_filename` varchar(128) NOT NULL,
 `tool_path` varchar(512) NOT NULL,
 `checksum_sha256` varchar(64) NOT NULL,
 `last_verified_at` datetime DEFAULT NULL,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node` (`node_id`),
 KEY `idx_checksum` (`checksum_sha256`),
 KEY `idx_verified` (`last_verified_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_password_rotations`
--

DROP TABLE IF EXISTS `sec_password_rotations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_password_rotations` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `service_name` varchar(128) NOT NULL,
 `rotated_at` datetime DEFAULT NULL,
 `method` varchar(64) DEFAULT NULL,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node_svc` (`node_id`,`service_name`),
 KEY `idx_rotated` (`rotated_at`),
 KEY `idx_status` (`status_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_policy_views`
--

DROP TABLE IF EXISTS `sec_policy_views`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_policy_views` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `session_hash` char(64) DEFAULT NULL,
 `policy_type` enum('privacy','terms','cookies','age') DEFAULT NULL,
 `agreed` tinyint(1) DEFAULT 0,
 `ip_address_enc` varchar(255) DEFAULT NULL,
 `data` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_purchase_velocity`
--

DROP TABLE IF EXISTS `sec_purchase_velocity`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_purchase_velocity` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `session_hash` char(64) DEFAULT NULL,
 `card_fingerprint` char(64) DEFAULT NULL,
 `amount_1h` decimal(12,2) DEFAULT 0.00,
 `amount_24h` decimal(12,2) DEFAULT 0.00,
 `transaction_count_1h` int(11) DEFAULT 0,
 `risk_score` tinyint(4) DEFAULT 0,
 `data` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_risk` (`risk_score`),
 KEY `idx_session` (`session_hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_response_log`
--

DROP TABLE IF EXISTS `sec_response_log`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_response_log` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `event_id` bigint(20) unsigned DEFAULT NULL,
 `action_taken` varchar(50) NOT NULL,
 `target_node` varchar(20) DEFAULT NULL,
 `target_ip_enc` varchar(255) DEFAULT NULL,
 `command_enc` text DEFAULT NULL,
 `exit_code` int(11) DEFAULT NULL,
 `output_enc` text DEFAULT NULL,
 `status_code` int(11) DEFAULT 9101,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_event` (`event_id`),
 KEY `idx_node` (`target_node`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_session_ip_changes`
--

DROP TABLE IF EXISTS `sec_session_ip_changes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_session_ip_changes` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `old_ip` varchar(45) DEFAULT NULL,
 `new_ip` varchar(45) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_tool_runs`
--

DROP TABLE IF EXISTS `sec_tool_runs`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_tool_runs` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `tool_name` varchar(64) NOT NULL,
 `command` text DEFAULT NULL,
 `exit_code` int(11) DEFAULT 0,
 `stdout_enc` longtext DEFAULT NULL,
 `stderr_enc` longtext DEFAULT NULL,
 `started_at` datetime(3) DEFAULT NULL,
 `finished_at` datetime(3) DEFAULT NULL,
 `duration_ms` int(11) DEFAULT 0,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node_tool` (`node_id`,`tool_name`),
 KEY `idx_started` (`started_at`),
 KEY `idx_status` (`status_code`)
) ENGINE=InnoDB AUTO_INCREMENT=1805 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_tool_schedule`
--

DROP TABLE IF EXISTS `sec_tool_schedule`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_tool_schedule` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `tool_name` varchar(64) NOT NULL,
 `cron_expr` varchar(64) NOT NULL,
 `last_run_at` datetime DEFAULT NULL,
 `next_run_at` datetime DEFAULT NULL,
 `enabled` tinyint(4) DEFAULT 1,
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node` (`node_id`),
 KEY `idx_next_run` (`next_run_at`),
 KEY `idx_enabled` (`enabled`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_tool_whitelist`
--

DROP TABLE IF EXISTS `sec_tool_whitelist`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_tool_whitelist` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `node_id` varchar(64) NOT NULL,
 `command_pattern` varchar(128) NOT NULL,
 `allowed` tinyint(4) DEFAULT 1,
 `added_at` datetime DEFAULT current_timestamp(),
 `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
 `status_code` int(11) DEFAULT 5001,
 PRIMARY KEY (`id`),
 KEY `idx_node_pattern` (`node_id`,`command_pattern`),
 KEY `idx_allowed` (`allowed`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_visitor_sessions`
--

DROP TABLE IF EXISTS `sec_visitor_sessions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_visitor_sessions` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `session_id` char(32) DEFAULT NULL,
 `session_hash` varchar(128) DEFAULT NULL,
 `ip_hash` varchar(128) DEFAULT NULL,
 `device_fingerprint_enc` text DEFAULT NULL,
 `user_id` int(10) unsigned DEFAULT NULL,
 `data` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `ip_address` varchar(45) DEFAULT NULL,
 `threat_score` int(11) DEFAULT 0,
 `browser_hash` char(64) DEFAULT NULL,
 `device_fingerprint` char(64) DEFAULT NULL,
 `geo_country` char(2) DEFAULT NULL,
 `isp_type` varchar(50) DEFAULT NULL,
 `bot_score` tinyint(4) DEFAULT 0,
 `js_challenge_passed` tinyint(1) DEFAULT 0,
 `captcha_challenged` tinyint(1) DEFAULT 0,
 `page_views` int(11) DEFAULT 0,
 `source_views` int(11) DEFAULT 0,
 `source_view_time_ms` int(11) DEFAULT 0,
 `total_time_ms` int(11) DEFAULT 0,
 `trust_score` int(11) DEFAULT 50,
 `risk_score` int(11) DEFAULT 50,
 `browser_features` text DEFAULT NULL,
 `screen_resolution` varchar(20) DEFAULT NULL,
 `timezone_offset` int(11) DEFAULT 0,
 `language` varchar(20) DEFAULT NULL,
 `platform_os` varchar(50) DEFAULT NULL,
 `has_account` tinyint(4) DEFAULT 0,
 `visit_count` int(11) DEFAULT 1,
 `first_seen` datetime DEFAULT current_timestamp(),
 `last_seen` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_session_hash` (`session_hash`),
 KEY `idx_ip` (`ip_address`),
 KEY `idx_trust` (`trust_score`),
 KEY `idx_last_seen` (`last_seen`),
 KEY `idx_first_seen` (`first_seen`)
) ENGINE=InnoDB AUTO_INCREMENT=196 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sec_watchdog_events`
--

DROP TABLE IF EXISTS `sec_watchdog_events`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sec_watchdog_events` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `event_type` varchar(100) DEFAULT NULL,
 `event_code` int(11) DEFAULT NULL,
 `severity` varchar(20) DEFAULT 'info',
 `ip_address` varchar(45) DEFAULT NULL,
 `details` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `cnt` int(11) DEFAULT 0,
 `event_id` int(10) unsigned DEFAULT NULL,
 `node_id` varchar(50) DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `idx_created` (`created_at`),
 KEY `idx_severity` (`severity`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `self_exclusion_requests`
--

DROP TABLE IF EXISTS `self_exclusion_requests`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `self_exclusion_requests` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned NOT NULL,
 `email_enc` text NOT NULL,
 `request_token_hash` char(64) NOT NULL,
 `status_code` int(11) DEFAULT 8201,
 `cooling_start` datetime DEFAULT NULL,
 `effective_at` datetime DEFAULT NULL,
 `expires_at` datetime DEFAULT NULL,
 `verified_at` datetime DEFAULT NULL,
 `cancellation_token_hash` char(64) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_token` (`request_token_hash`),
 KEY `idx_user` (`user_id`),
 KEY `idx_status` (`status_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `self_exclusions`
--

DROP TABLE IF EXISTS `self_exclusions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `self_exclusions` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `reason` text DEFAULT NULL,
 `status` varchar(20) DEFAULT 'pending',
 `created_at` datetime DEFAULT current_timestamp(),
 `ip_address` varchar(45) DEFAULT NULL,
 `pushed_proxy` tinyint(4) DEFAULT 0,
 `pushed_shield` tinyint(4) DEFAULT 0,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `sessions`
--

DROP TABLE IF EXISTS `sessions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `sessions` (
 `id` varchar(128) NOT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `user_agent` varchar(255) DEFAULT NULL,
 `user_id` int(10) unsigned DEFAULT NULL,
 `trust_level` tinyint(4) DEFAULT 3,
 `is_purchaser` tinyint(1) DEFAULT 0,
 `page_views` int(11) DEFAULT 0,
 `last_activity` int(10) unsigned DEFAULT 0,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_last_activity` (`last_activity`),
 KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `settings`
--

DROP TABLE IF EXISTS `settings`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `settings` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `setting_key` varchar(100) DEFAULT NULL,
 `setting_value` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `setting_key` (`setting_key`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `shipments`
--

DROP TABLE IF EXISTS `shipments`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `shipments` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `order_id` int(10) unsigned NOT NULL,
 `carrier` enum('canada_post','fedex','ups','purolator') NOT NULL,
 `tracking_number_enc` text DEFAULT NULL,
 `label_data_enc` mediumtext DEFAULT NULL,
 `shipped_at` datetime DEFAULT NULL,
 `delivered_at` datetime DEFAULT NULL,
 `est_delivery` datetime DEFAULT NULL,
 `status_code` int(11) DEFAULT 8401,
 `api_response_enc` text DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_order` (`order_id`),
 KEY `idx_tracking` (`tracking_number_enc`(255))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `shipping_labels`
--

DROP TABLE IF EXISTS `shipping_labels`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `shipping_labels` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `shipment_id` int(10) unsigned NOT NULL,
 `label_pdf_enc` mediumblob DEFAULT NULL,
 `label_zpl_enc` mediumblob DEFAULT NULL,
 `cost` decimal(10,2) DEFAULT NULL,
 `weight_g` int(11) DEFAULT NULL,
 `dimensions_enc` varchar(100) DEFAULT NULL,
 `api_ref` varchar(255) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_shipment` (`shipment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `social_posts`
--

DROP TABLE IF EXISTS `social_posts`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `social_posts` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `platform` varchar(50) DEFAULT NULL,
 `content` text DEFAULT NULL,
 `status` varchar(20) DEFAULT 'draft',
 `created_at` datetime DEFAULT current_timestamp(),
 `scheduled_at` datetime DEFAULT NULL,
 `status_code` int(11) DEFAULT 7000,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Temporary table structure for view `store_domains`
--

DROP TABLE IF EXISTS `store_domains`;
/*!50001 DROP VIEW IF EXISTS `store_domains`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8mb4;
/*!50001 CREATE VIEW `store_domains` AS SELECT
 1 AS `id`,
 1 AS `domain`,
 1 AS `nickname`,
 1 AS `store_name`,
 1 AS `tagline`,
 1 AS `accent_color`,
 1 AS `color_master`,
 1 AS `store_config`,
 1 AS `store_type`,
 1 AS `is_active`,
 1 AS `maintenance_mode`,
 1 AS `created_at` */;
SET character_set_client = @saved_cs_client;

--
-- Table structure for table `storefront_blocks`
--

DROP TABLE IF EXISTS `storefront_blocks`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `storefront_blocks` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `layout_id` int(10) unsigned DEFAULT NULL,
 `store_id` int(10) unsigned DEFAULT NULL,
 `block_type` varchar(50) DEFAULT 'product',
 `block_data` text DEFAULT NULL,
 `display_order` int(11) DEFAULT 0,
 `is_active` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 `accent_color` varchar(20) DEFAULT NULL,
 `bg_color` varchar(20) DEFAULT NULL,
 `block_label` varchar(100) DEFAULT NULL,
 `category_id` int(10) unsigned DEFAULT NULL,
 `image_url` varchar(500) DEFAULT NULL,
 `layout_row_id` int(10) unsigned DEFAULT NULL,
 `product_id` int(10) unsigned DEFAULT NULL,
 `slot_size` int(11) DEFAULT 1,
 `status_code` int(11) DEFAULT 6001,
 `text_color` varchar(20) DEFAULT NULL,
 `title` varchar(255) DEFAULT NULL,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `storefront_layouts`
--

DROP TABLE IF EXISTS `storefront_layouts`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `storefront_layouts` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `store_id` int(10) unsigned NOT NULL,
 `layout_name` varchar(100) DEFAULT NULL,
 `is_active` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 `bg_color` varchar(20) DEFAULT NULL,
 `display_order` int(11) DEFAULT 0,
 `row_label` varchar(100) DEFAULT NULL,
 `row_type` varchar(50) DEFAULT NULL,
 `text_color` varchar(20) DEFAULT NULL,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `idx_store` (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `storefront_rows`
--

DROP TABLE IF EXISTS `storefront_rows`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `storefront_rows` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `store_id` int(10) unsigned NOT NULL,
 `row_type` varchar(50) NOT NULL DEFAULT 'banner',
 `config` text DEFAULT NULL,
 `display_order` int(11) DEFAULT 0,
 `is_active` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 `row_order` int(11) DEFAULT 0,
 `category_name` varchar(100) DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `idx_store_id` (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stores`
--

DROP TABLE IF EXISTS `stores`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `stores` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `domain` varchar(200) DEFAULT NULL,
 `nickname` varchar(100) DEFAULT NULL,
 `store_name` text DEFAULT NULL,
 `tagline` text DEFAULT NULL,
 `store_config` text DEFAULT NULL,
 `accent_color` varchar(7) DEFAULT '#2D6A4F',
 `color_master` varchar(7) DEFAULT '#2D6A4F',
 `store_type` varchar(50) DEFAULT 'pharma',
 `is_active` tinyint(1) DEFAULT 1,
 `status_code` int(11) DEFAULT 5001,
 `maintenance_mode` tinyint(1) DEFAULT 0,
 `proxy_enabled` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 `campaign_name` text DEFAULT NULL,
 `logo_url` varchar(500) DEFAULT NULL,
 `slug` varchar(200) DEFAULT NULL,
 `geo_countries` text DEFAULT NULL,
 `maintenance_msg` text DEFAULT NULL,
 `platform` varchar(50) DEFAULT NULL,
 `rate_limit` int(11) DEFAULT 60,
 `wg_subnet` varchar(50) DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `domain` (`domain`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- NOTE (2026-06-18): The following columns were added after this schema dump:
-- store_email TEXT DEFAULT NULL -- Encrypted noreply email per store (SecureVault::encrypt)
-- welcome_gate_enabled TINYINT(1) DEFAULT 1 -- Welcome gate on/off per store
-- welcome_gate_type VARCHAR(20) DEFAULT 'age' -- Welcome gate type (age, disclaimer, etc.)
-- Additionally: store_name, tagline, and store_email are now ENCRYPTED at rest (AES-256-GCM via SecureVault).
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `support_messages`
--

DROP TABLE IF EXISTS `support_messages`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `support_messages` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned DEFAULT NULL,
 `subject` text DEFAULT NULL,
 `subject_enc` text DEFAULT NULL,
 `body` text NOT NULL,
 `body_enc` mediumtext DEFAULT NULL,
 `is_admin` tinyint(1) DEFAULT 0,
 `is_read` tinyint(1) DEFAULT 0,
 `parent_id` int(10) unsigned DEFAULT NULL,
 `urgency` enum('low','normal','high','critical') DEFAULT 'normal',
 `status` enum('open','waiting','escalated','resolved','closed') DEFAULT 'open',
 `created_at` datetime DEFAULT current_timestamp(),
 `thread_id` int(10) unsigned DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `support_replies`
--

DROP TABLE IF EXISTS `support_replies`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `support_replies` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ticket_id` int(10) unsigned NOT NULL,
 `sender_type` enum('customer','admin','system') DEFAULT 'customer',
 `sender_name` varchar(100) DEFAULT NULL,
 `message` text DEFAULT NULL,
 `is_encrypted` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_ticket_id` (`ticket_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `support_tickets`
--

DROP TABLE IF EXISTS `support_tickets`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `support_tickets` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ticket_ref` varchar(32) DEFAULT NULL,
 `customer_id` int(10) unsigned NOT NULL,
 `subject` varchar(255) DEFAULT NULL,
 `subject_enc` text DEFAULT NULL,
 `status` enum('open','awaiting_reply','resolved','closed') DEFAULT 'open',
 `priority` enum('low','medium','high','urgent') DEFAULT 'medium',
 `last_reply_at` datetime DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `ticket_ref` (`ticket_ref`),
 KEY `idx_customer` (`customer_id`),
 KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `terms`
--

DROP TABLE IF EXISTS `terms`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `terms` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `slug` varchar(50) NOT NULL,
 `subtitle` varchar(255) DEFAULT NULL,
 `t01` varchar(10) DEFAULT 'p',
 `c01` text DEFAULT NULL,
 `t02` varchar(10) DEFAULT 'p',
 `c02` text DEFAULT NULL,
 `t03` varchar(10) DEFAULT 'p',
 `c03` text DEFAULT NULL,
 `t04` varchar(10) DEFAULT 'p',
 `c04` text DEFAULT NULL,
 `t05` varchar(10) DEFAULT 'p',
 `c05` text DEFAULT NULL,
 `t06` varchar(10) DEFAULT 'p',
 `c06` text DEFAULT NULL,
 `t07` varchar(10) DEFAULT 'p',
 `c07` text DEFAULT NULL,
 `t08` varchar(10) DEFAULT 'p',
 `c08` text DEFAULT NULL,
 `t09` varchar(10) DEFAULT 'p',
 `c09` text DEFAULT NULL,
 `t10` varchar(10) DEFAULT 'p',
 `c10` text DEFAULT NULL,
 `t11` varchar(10) DEFAULT 'p',
 `c11` text DEFAULT NULL,
 `t12` varchar(10) DEFAULT 'p',
 `c12` text DEFAULT NULL,
 `t13` varchar(10) DEFAULT 'p',
 `c13` text DEFAULT NULL,
 `t14` varchar(10) DEFAULT 'p',
 `c14` text DEFAULT NULL,
 `t15` varchar(10) DEFAULT 'p',
 `c15` text DEFAULT NULL,
 `t16` varchar(10) DEFAULT 'p',
 `c16` text DEFAULT NULL,
 `t17` varchar(10) DEFAULT 'p',
 `c17` text DEFAULT NULL,
 `t18` varchar(10) DEFAULT 'p',
 `c18` text DEFAULT NULL,
 `t19` varchar(10) DEFAULT 'p',
 `c19` text DEFAULT NULL,
 `t20` varchar(10) DEFAULT 'p',
 `c20` text DEFAULT NULL,
 `t21` varchar(10) DEFAULT 'p',
 `c21` text DEFAULT NULL,
 `t22` varchar(10) DEFAULT 'p',
 `c22` text DEFAULT NULL,
 `t23` varchar(10) DEFAULT 'p',
 `c23` text DEFAULT NULL,
 `t24` varchar(10) DEFAULT 'p',
 `c24` text DEFAULT NULL,
 `t25` varchar(10) DEFAULT 'p',
 `c25` text DEFAULT NULL,
 `t26` varchar(10) DEFAULT 'p',
 `c26` text DEFAULT NULL,
 `t27` varchar(10) DEFAULT 'p',
 `c27` text DEFAULT NULL,
 `t28` varchar(10) DEFAULT 'p',
 `c28` text DEFAULT NULL,
 `t29` varchar(10) DEFAULT 'p',
 `c29` text DEFAULT NULL,
 `t30` varchar(10) DEFAULT 'p',
 `c30` text DEFAULT NULL,
 `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`),
 UNIQUE KEY `slug` (`slug`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `testimonials`
--

DROP TABLE IF EXISTS `testimonials`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `testimonials` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `author` varchar(100) DEFAULT NULL,
 `content` text DEFAULT NULL,
 `rating` tinyint(4) DEFAULT 5,
 `is_active` tinyint(1) DEFAULT 1,
 `store_id` int(10) unsigned DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `threat_intel_cache`
--

DROP TABLE IF EXISTS `threat_intel_cache`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `threat_intel_cache` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ip_address` varchar(45) DEFAULT NULL,
 `threat_score` decimal(5,2) DEFAULT 0.00,
 `source` varchar(50) DEFAULT NULL,
 `raw_data` text DEFAULT NULL,
 `expires_at` datetime DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `data` text DEFAULT NULL,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `trust_history`
--

DROP TABLE IF EXISTS `trust_history`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `trust_history` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(10) unsigned NOT NULL,
 `action` varchar(50) DEFAULT NULL,
 `points` int(11) DEFAULT 0,
 `trust_delta` int(11) DEFAULT 0,
 `reference_id` int(10) unsigned DEFAULT NULL,
 `note` varchar(255) DEFAULT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 PRIMARY KEY (`id`),
 KEY `idx_user_id` (`user_id`),
 KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `ui_labels`
--

DROP TABLE IF EXISTS `ui_labels`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `ui_labels` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `label_key` varchar(100) NOT NULL,
 `label_value` text DEFAULT NULL,
 `locale` varchar(5) DEFAULT 'en',
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_key_locale` (`label_key`,`locale`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `users`
--

DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `users` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `email` text NOT NULL,
 `username` varchar(100) DEFAULT NULL,
 `password_hash` varchar(255) NOT NULL,
 `name` text DEFAULT NULL,
 `name_enc` text DEFAULT NULL,
 `phone` text DEFAULT NULL,
 `phone_enc` varchar(255) DEFAULT NULL,
 `address` text DEFAULT NULL,
 `city` text DEFAULT NULL,
 `province` varchar(100) DEFAULT NULL,
 `postal_code` text DEFAULT NULL,
 `country` varchar(50) DEFAULT 'CA',
 `credit_balance` decimal(10,2) DEFAULT 0.00,
 `trust_score` int(11) DEFAULT 50,
 `status` enum('active','suspended','banned','unverified','deleted') DEFAULT 'unverified',
 `email_verified` tinyint(1) DEFAULT 0,
 `verify_token` varchar(100) DEFAULT NULL,
 `referral_code` varchar(20) DEFAULT NULL,
 `referred_by` int(10) unsigned DEFAULT NULL,
 `last_login` datetime DEFAULT NULL,
 `last_ip` varchar(45) DEFAULT NULL,
 `created_at` datetime DEFAULT current_timestamp(),
 `is_verified` tinyint(1) DEFAULT 0,
 `login_count` int(11) DEFAULT 0,
 `access_tier` varchar(20) DEFAULT NULL,
 `account_type` varchar(20) DEFAULT 'customer',
 `admin_level` tinyint(4) DEFAULT 0,
 `encrypted_email` text DEFAULT NULL,
 `encrypted_username` text DEFAULT NULL,
 `first_name` varchar(100) DEFAULT NULL,
 `pref_a` int(11) DEFAULT 0,
 `pref_b` int(11) DEFAULT 0,
 `pref_c` int(11) DEFAULT 0,
 `pref_d` int(11) DEFAULT 0,
 `review_credits` int(11) DEFAULT 0,
 `email_hash` varchar(64) DEFAULT NULL,
 `last_name` text DEFAULT NULL,
 `must_reset` tinyint(4) DEFAULT 0,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `idx_email_hash` (`email_hash`),
 KEY `idx_status` (`status`),
 KEY `idx_created` (`created_at`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `visitors`
--

DROP TABLE IF EXISTS `visitors`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `visitors` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `session_id` varchar(64) NOT NULL,
 `ip_address` varchar(45) DEFAULT NULL,
 `user_agent` text DEFAULT NULL,
 `fingerprint` varchar(64) DEFAULT NULL,
 `pages_viewed` int(11) DEFAULT 0,
 `risk_score` int(11) DEFAULT 0,
 `flags` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`flags`)),
 `created_at` datetime DEFAULT current_timestamp(),
 `last_seen` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `wallet_transactions`
--

DROP TABLE IF EXISTS `wallet_transactions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `wallet_transactions` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `wallet_id` int(10) unsigned NOT NULL,
 `tx_hash` varchar(200) DEFAULT NULL,
 `tx_hash_enc` varchar(255) DEFAULT NULL,
 `amount` decimal(20,8) DEFAULT NULL,
 `confirmations` int(11) DEFAULT 0,
 `status` enum('pending','confirmed','failed') DEFAULT 'pending',
 `created_at` datetime DEFAULT current_timestamp(),
 `detected_at` datetime DEFAULT NULL,
 `status_code` int(11) DEFAULT 7000,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `wallets`
--

DROP TABLE IF EXISTS `wallets`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `wallets` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `currency` varchar(20) NOT NULL,
 `address` text NOT NULL,
 `address_enc` text DEFAULT NULL,
 `label` varchar(100) DEFAULT NULL,
 `is_active` tinyint(1) DEFAULT 1,
 `created_at` datetime DEFAULT current_timestamp(),
 `balance` decimal(20,8) DEFAULT 0.00000000,
 `currency_code` varchar(10) DEFAULT NULL,
 `last_checked` datetime DEFAULT NULL,
 `status` varchar(30) DEFAULT 'active',
 `status_code` int(11) DEFAULT 7000,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Final view structure for view `customer_reviews`
--

/*!50001 DROP VIEW IF EXISTS `customer_reviews`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `customer_reviews` AS select `reviews`.`id` AS `id`,`reviews`.`store_id` AS `store_id`,`reviews`.`user_id` AS `user_id`,`reviews`.`product_id` AS `product_id`,`reviews`.`rating` AS `rating`,`reviews`.`title` AS `title`,`reviews`.`body` AS `body`,`reviews`.`is_approved` AS `is_approved`,`reviews`.`is_verified` AS `is_verified`,`reviews`.`admin_reply` AS `admin_reply`,`reviews`.`helpful_count` AS `helpful_count`,`reviews`.`created_at` AS `created_at` from `reviews` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;

--
-- DROPPED: This view was removed per ARSENAL.md Post-Audit Fix #13. Retained in dump for historical reference only.
-- Final view structure for view `nn_page_blocks`
--

/*!50001 DROP VIEW IF EXISTS `nn_page_blocks`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `nn_page_blocks` AS select `page_blocks`.`id` AS `id`,`page_blocks`.`store_id` AS `store_id`,`page_blocks`.`page` AS `page`,`page_blocks`.`block_key` AS `block_key`,`page_blocks`.`content` AS `content`,`page_blocks`.`display_order` AS `display_order`,`page_blocks`.`is_active` AS `is_active`,`page_blocks`.`created_at` AS `created_at` from `page_blocks` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;

--
-- DROPPED: This view was removed per ARSENAL.md Post-Audit Fix #13. Retained in dump for historical reference only.
-- Final view structure for view `nn_product_catalog`
--

/*!50001 DROP VIEW IF EXISTS `nn_product_catalog`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `nn_product_catalog` AS select `products`.`id` AS `id`,`products`.`store_id` AS `store_id`,`products`.`category_id` AS `category_id`,`products`.`sku` AS `sku`,`products`.`name` AS `name`,`products`.`title` AS `title`,`products`.`nickname` AS `nickname`,`products`.`slug` AS `slug`,`products`.`description` AS `description`,`products`.`quality` AS `quality`,`products`.`type` AS `type`,`products`.`short_desc` AS `short_desc`,`products`.`pitch_title` AS `pitch_title`,`products`.`pitch_body` AS `pitch_body`,`products`.`notes` AS `notes`,`products`.`image` AS `image`,`products`.`image_url` AS `image_url`,`products`.`image_path` AS `image_path`,`products`.`price` AS `price`,`products`.`sale_price` AS `sale_price`,`products`.`base_price` AS `base_price`,`products`.`has_qualities` AS `has_qualities`,`products`.`has_types` AS `has_types`,`products`.`unit_label` AS `unit_label`,`products`.`status` AS `status`,`products`.`status_code` AS `status_code`,`products`.`visibility_code` AS `visibility_code`,`products`.`visibility` AS `visibility`,`products`.`display_order` AS `display_order`,`products`.`created_at` AS `created_at`,`products`.`updated_at` AS `updated_at`,`products`.`slot_size` AS `slot_size`,`products`.`unit_increment` AS `unit_increment`,`products`.`unit_price_per` AS `unit_price_per`,`products`.`unit_tiers` AS `unit_tiers`,`products`.`unit_min_qty` AS `unit_min_qty`,`products`.`featured_code` AS `featured_code`,`products`.`unit_pricing_code` AS `unit_pricing_code`,`products`.`is_encrypted` AS `is_encrypted`,`products`.`gallery` AS `gallery`,`products`.`meta_json` AS `meta_json`,`products`.`currency_code` AS `currency_code`,`products`.`product_code` AS `product_code` from `products` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;

--
-- DROPPED: This view was removed per ARSENAL.md Post-Audit Fix #13. Retained in dump for historical reference only.
-- Final view structure for view `nn_product_categories`
--

/*!50001 DROP VIEW IF EXISTS `nn_product_categories`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `nn_product_categories` AS select `categories`.`id` AS `id`,`categories`.`store_id` AS `store_id`,`categories`.`name` AS `name`,`categories`.`nickname` AS `nickname`,`categories`.`slug` AS `slug`,`categories`.`display_order` AS `display_order`,`categories`.`show_in_nav` AS `show_in_nav`,`categories`.`status` AS `status`,`categories`.`status_code` AS `status_code`,`categories`.`created_at` AS `created_at`,`categories`.`description` AS `description` from `categories` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;

--
-- DROPPED: This view was removed per ARSENAL.md Post-Audit Fix #13. Retained in dump for historical reference only.
-- Final view structure for view `nn_store_products`
--

/*!50001 DROP VIEW IF EXISTS `nn_store_products`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `nn_store_products` AS select `products`.`id` AS `id`,`products`.`store_id` AS `store_id`,`products`.`category_id` AS `category_id`,`products`.`sku` AS `sku`,`products`.`name` AS `name`,`products`.`title` AS `title`,`products`.`nickname` AS `nickname`,`products`.`slug` AS `slug`,`products`.`description` AS `description`,`products`.`quality` AS `quality`,`products`.`type` AS `type`,`products`.`short_desc` AS `short_desc`,`products`.`pitch_title` AS `pitch_title`,`products`.`pitch_body` AS `pitch_body`,`products`.`notes` AS `notes`,`products`.`image` AS `image`,`products`.`image_url` AS `image_url`,`products`.`image_path` AS `image_path`,`products`.`price` AS `price`,`products`.`sale_price` AS `sale_price`,`products`.`base_price` AS `base_price`,`products`.`has_qualities` AS `has_qualities`,`products`.`has_types` AS `has_types`,`products`.`unit_label` AS `unit_label`,`products`.`status` AS `status`,`products`.`status_code` AS `status_code`,`products`.`visibility_code` AS `visibility_code`,`products`.`visibility` AS `visibility`,`products`.`display_order` AS `display_order`,`products`.`created_at` AS `created_at`,`products`.`updated_at` AS `updated_at`,`products`.`slot_size` AS `slot_size`,`products`.`unit_increment` AS `unit_increment`,`products`.`unit_price_per` AS `unit_price_per`,`products`.`unit_tiers` AS `unit_tiers`,`products`.`unit_min_qty` AS `unit_min_qty`,`products`.`featured_code` AS `featured_code`,`products`.`unit_pricing_code` AS `unit_pricing_code`,`products`.`is_encrypted` AS `is_encrypted`,`products`.`gallery` AS `gallery`,`products`.`meta_json` AS `meta_json`,`products`.`currency_code` AS `currency_code`,`products`.`product_code` AS `product_code`,`products`.`id` AS `pid` from `products` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;

--
-- Final view structure for view `store_domains`
--

/*!50001 DROP VIEW IF EXISTS `store_domains`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `store_domains` AS select `stores`.`id` AS `id`,`stores`.`domain` AS `domain`,`stores`.`nickname` AS `nickname`,`stores`.`store_name` AS `store_name`,`stores`.`tagline` AS `tagline`,`stores`.`accent_color` AS `accent_color`,`stores`.`color_master` AS `color_master`,`stores`.`store_config` AS `store_config`,`stores`.`store_type` AS `store_type`,`stores`.`is_active` AS `is_active`,`stores`.`maintenance_mode` AS `maintenance_mode`,`stores`.`created_at` AS `created_at` from `stores` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2026-06-11 22:54:06
```

---

## ADDENDUM: Missing Origin Tables (Added by 2026-06-20 Audit)

The following 7 tables exist in the live `store` database but were missing from the June 11 dump above. Full CREATE TABLE statements are in [INSTALL_ALL.sql](file:///y:/5/var/www/dashboard/system/INSTALL_ALL.sql) Section 8.

| Table | Purpose | Orphaned? |
|-------|---------|----------|
| `ip_probes` | Port scan / probe tracking with threat scoring | Yes |
| `store_data` | Key-value store configuration per store | Yes |
| `store_provision_log` | Store provisioning action log | Yes |
| `system_events` | Structured system event log with severity | Yes |
| `backup_log` | Backup pipeline audit trail | Yes |
| `marketing_visitors` | Marketing link visitor tracking | Yes |
| `age_gates` | Age verification session tracking per store | Yes |

```sql
CREATE TABLE IF NOT EXISTS `ip_probes` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `ip_address` varchar(45) NOT NULL,
  `probe_type` varchar(50) DEFAULT 'port_scan',
  `target_port` int(11) DEFAULT NULL,
  `user_agent` text DEFAULT NULL,
  `request_path` varchar(500) DEFAULT NULL,
  `country_code` char(2) DEFAULT NULL,
  `threat_score` int(11) DEFAULT 0,
  `blocked` tinyint(1) DEFAULT 0,
  `created_at` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_ip` (`ip_address`),
  KEY `idx_created` (`created_at`),
  KEY `idx_threat` (`threat_score`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `store_data` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `store_id` int(10) unsigned NOT NULL,
  `data_key` varchar(100) NOT NULL,
  `data_value` text DEFAULT NULL,
  `data_type` varchar(20) DEFAULT 'string',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_store_key` (`store_id`, `data_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `store_provision_log` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `store_id` int(10) unsigned NOT NULL,
  `action` varchar(100) NOT NULL,
  `status` enum('pending','running','completed','failed') DEFAULT 'pending',
  `details` text DEFAULT NULL,
  `admin_id` int(10) unsigned DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `completed_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_store` (`store_id`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `system_events` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `event_type` varchar(100) NOT NULL,
  `severity` enum('debug','info','warning','error','critical') DEFAULT 'info',
  `source` varchar(100) DEFAULT NULL,
  `message` text DEFAULT NULL,
  `meta` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`meta`)),
  `node_id` varchar(20) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_type` (`event_type`),
  KEY `idx_severity` (`severity`),
  KEY `idx_created` (`created_at`),
  KEY `idx_node` (`node_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `backup_log` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `backup_type` enum('full','incremental','schema','data') DEFAULT 'full',
  `database_name` varchar(100) DEFAULT NULL,
  `file_path` varchar(500) DEFAULT NULL,
  `file_size_bytes` bigint(20) DEFAULT NULL,
  `checksum_sha256` char(64) DEFAULT NULL,
  `status` enum('running','completed','failed','expired') DEFAULT 'running',
  `node_id` varchar(20) DEFAULT NULL,
  `admin_id` int(10) unsigned DEFAULT NULL,
  `started_at` datetime DEFAULT current_timestamp(),
  `completed_at` datetime DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_status` (`status`),
  KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `marketing_visitors` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `link_id` int(10) unsigned NOT NULL,
  `session_id` varchar(64) NOT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` text DEFAULT NULL,
  `referrer` text DEFAULT NULL,
  `trust_score` int(11) DEFAULT 100,
  `flags` text DEFAULT NULL,
  `device_fingerprint` text DEFAULT NULL,
  `is_blackholed` tinyint(1) DEFAULT 0,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_link` (`link_id`),
  KEY `idx_session` (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `age_gates` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `store_id` int(10) unsigned NOT NULL,
  `session_hash` char(64) NOT NULL,
  `passed` tinyint(1) DEFAULT 0,
  `ip_address` varchar(45) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_store_session` (`store_id`, `session_hash`),
  KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
```

---

## Engine Database Schema (engine @ 669427 / 10.69.69.6)

The Engine database runs on a separate node (76.13.222.157). Full CREATE TABLE statements are in [INSTALL_ALL.sql](file:///y:/5/var/www/dashboard/system/INSTALL_ALL.sql) Section 11.

| Table | Purpose | Status |
|-------|---------|--------|
| `wg_config` | WireGuard mesh configuration | Active (13 rows) |
| `sec_tool_audit` | Obfuscated tool execution log | NEW (replaces broken `tool_executions`) |
| `engine_alerts` | Mistral AI security alerts | NEW |
| `engine_suggestions` | Remediation proposals with approval workflow | NEW |
| `wg_port_allowlist` | WireGuard port rotation pool | NEW (16 default ports) |
| `wg_subnet_pool` | Per-store subnet allocation | NEW (8 default subnets) |

```sql
CREATE TABLE IF NOT EXISTS `wg_config` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `node_id` varchar(20) NOT NULL,
  `interface_name` varchar(50) NOT NULL,
  `private_key_enc` text DEFAULT NULL,
  `public_key` varchar(64) DEFAULT NULL,
  `listen_port` int(11) DEFAULT NULL,
  `address` varchar(50) DEFAULT NULL,
  `subnet` varchar(50) DEFAULT NULL,
  `peer_pubkey` varchar(64) DEFAULT NULL,
  `peer_endpoint` varchar(100) DEFAULT NULL,
  `peer_allowed_ips` varchar(200) DEFAULT NULL,
  `psk_enc` text DEFAULT NULL,
  `is_active` tinyint(1) DEFAULT 1,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_node` (`node_id`),
  KEY `idx_interface` (`interface_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `sec_tool_audit` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ts` datetime(3) NOT NULL DEFAULT current_timestamp(3),
  `nid` varchar(10) NOT NULL,
  `tid` varchar(8) NOT NULL,
  `act` varchar(32) NOT NULL,
  `src` varchar(64) DEFAULT NULL,
  `res` tinyint(1) DEFAULT 1,
  `phash` varchar(64) DEFAULT NULL,
  `sid` varchar(32) DEFAULT NULL,
  `dur` int(10) unsigned DEFAULT 0,
  `xc` smallint(6) DEFAULT 0,
  `out` text DEFAULT NULL,
  `err` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_ts` (`ts`),
  KEY `idx_nid` (`nid`),
  KEY `idx_tid` (`tid`),
  KEY `idx_act` (`act`),
  KEY `idx_nid_tid` (`nid`, `tid`),
  KEY `idx_res` (`res`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `engine_alerts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `alert_uuid` char(36) NOT NULL,
  `alert_type` varchar(50) NOT NULL,
  `severity` enum('info','low','medium','high','critical') DEFAULT 'info',
  `source_nid` varchar(10) DEFAULT NULL,
  `source_tid` varchar(8) DEFAULT NULL,
  `title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `evidence_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`evidence_json`)),
  `model_version` varchar(50) DEFAULT 'mistral-7b',
  `confidence` decimal(4,3) DEFAULT NULL,
  `acknowledged` tinyint(1) DEFAULT 0,
  `acknowledged_by` varchar(64) DEFAULT NULL,
  `acknowledged_at` datetime DEFAULT NULL,
  `resolved` tinyint(1) DEFAULT 0,
  `resolved_at` datetime DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_uuid` (`alert_uuid`),
  KEY `idx_type` (`alert_type`),
  KEY `idx_severity` (`severity`),
  KEY `idx_unresolved` (`resolved`, `created_at`),
  KEY `idx_source` (`source_nid`),
  KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `engine_suggestions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `suggestion_uuid` char(36) NOT NULL,
  `alert_id` bigint(20) unsigned DEFAULT NULL,
  `category` varchar(50) NOT NULL,
  `action_type` varchar(100) NOT NULL,
  `target_nid` varchar(10) DEFAULT NULL,
  `description` text NOT NULL,
  `command_enc` text DEFAULT NULL,
  `risk_level` enum('none','low','medium','high','critical') DEFAULT 'low',
  `model_version` varchar(50) DEFAULT 'mistral-7b',
  `confidence` decimal(4,3) DEFAULT NULL,
  `status` enum('pending','approved','rejected','executed','failed','expired') DEFAULT 'pending',
  `approved_by` varchar(64) DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `executed_at` datetime DEFAULT NULL,
  `execution_result` text DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_uuid` (`suggestion_uuid`),
  KEY `idx_alert` (`alert_id`),
  KEY `idx_status` (`status`),
  KEY `idx_category` (`category`),
  KEY `idx_pending` (`status`, `created_at`),
  KEY `idx_target` (`target_nid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `wg_port_allowlist` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `port` int(11) NOT NULL,
  `protocol` enum('udp','tcp') DEFAULT 'udp',
  `interface_name` varchar(50) DEFAULT NULL,
  `assigned_to_nid` varchar(10) DEFAULT NULL,
  `in_use` tinyint(1) DEFAULT 0,
  `last_rotated_at` datetime DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_port_proto` (`port`, `protocol`),
  KEY `idx_available` (`in_use`, `protocol`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `wg_subnet_pool` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `subnet` varchar(50) NOT NULL,
  `interface_name` varchar(50) DEFAULT NULL,
  `assigned_to_store_id` int(10) unsigned DEFAULT NULL,
  `assigned_to_nid` varchar(10) DEFAULT NULL,
  `purpose` varchar(100) DEFAULT NULL,
  `in_use` tinyint(1) DEFAULT 0,
  `last_rotated_at` datetime DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_subnet` (`subnet`),
  KEY `idx_available` (`in_use`),
  KEY `idx_store` (`assigned_to_store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
```

---

### Code-to-Table Coverage Summary (from audit)

| Codebase | Files | Tables Referenced |
|----------|-------|------------------|
| Public | 72 | 44 |
| Dashboard | 260+ | 48 |
| Shared + Engine | 40+ | 9 MySQL + 2 SQLite |
| **Total Unique** | **400+** | **~65** |
| **Orphaned** | - | **~47** |

> Orphaned tables are infrastructure for designed-but-not-wired features (marketing suite, fulfillment, advanced security). They should be KEPT in the schema.

### Cross-Reference Documentation

| File | Scope |
|------|-------|
| [SCHEMA_MAP_public.md](file:///y:/documents/source/SCHEMA_MAP_public.md) | 72 PHP files → 44 tables |
| [SCHEMA_MAP_dashboard.md](file:///y:/documents/source/SCHEMA_MAP_dashboard.md) | 260+ PHP files → 48 tables |
| [SCHEMA_MAP_shared_engine.md](file:///y:/documents/source/SCHEMA_MAP_shared_engine.md) | 40+ files → 9 MySQL + 2 SQLite |
