[
  {
    "type": "create_table",
    "description": "Create demo_sessions table in kiosk_demo for demo access management",
    "database": "kiosk_demo",
    "check_query": "SHOW TABLES LIKE 'demo_sessions'",
    "sql": "CREATE TABLE `demo_sessions` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `email` varchar(255) NOT NULL COMMENT 'Demo user email for lead capture',\n  `magicLinkTokenHash` varchar(64) NOT NULL COMMENT 'SHA-256 hash of magic link token',\n  `magicLinkExpiresAt` datetime NOT NULL COMMENT 'Magic link expiration (5 minutes)',\n  `magicLinkUsedAt` datetime DEFAULT NULL COMMENT 'When magic link was clicked',\n  `sessionTokenHash` varchar(64) DEFAULT NULL COMMENT 'SHA-256 hash of session token (set after first click)',\n  `concept` enum('pc','ou','se') DEFAULT NULL COMMENT 'Store concept: Platos Closet, Once Upon A Child, Style Encore',\n  `sourceQrId` varchar(50) DEFAULT NULL COMMENT 'Event/campaign tracking ID from QR code',\n  `createdAt` datetime NOT NULL DEFAULT current_timestamp(),\n  `sessionExpiresAt` datetime DEFAULT NULL COMMENT 'Session expiration (24 hours after activation)',\n  `lastAccessedAt` datetime DEFAULT NULL COMMENT 'Last activity timestamp',\n  `tourProgress` json DEFAULT NULL COMMENT 'Tour step progress: {\"section\": \"workbook\", \"step\": 3}',\n  PRIMARY KEY (`id`),\n  KEY `idx_magic_link_token` (`magicLinkTokenHash`),\n  KEY `idx_session_token` (`sessionTokenHash`),\n  KEY `idx_email` (`email`),\n  KEY `idx_magic_link_expires` (`magicLinkExpiresAt`),\n  KEY `idx_session_expires` (`sessionExpiresAt`),\n  KEY `idx_source_qr` (`sourceQrId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Demo environment session management with magic link authentication'"
  },
  {
    "type": "create_table",
    "description": "Create demo_leads table in kiosk_demo for sales lead capture",
    "database": "kiosk_demo",
    "check_query": "SHOW TABLES LIKE 'demo_leads'",
    "sql": "CREATE TABLE `demo_leads` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `sessionId` int(10) unsigned NOT NULL COMMENT 'Reference to demo_sessions.id',\n  `email` varchar(255) NOT NULL COMMENT 'Lead email address',\n  `companyName` varchar(255) DEFAULT NULL COMMENT 'Company/franchise name',\n  `phone` varchar(50) DEFAULT NULL COMMENT 'Contact phone number',\n  `sourceQrId` varchar(50) DEFAULT NULL COMMENT 'Event/campaign tracking from QR code',\n  `ctaClicked` varchar(50) DEFAULT NULL COMMENT 'Which CTA triggered the contact form',\n  `createdAt` datetime NOT NULL DEFAULT current_timestamp(),\n  `contactedAt` datetime DEFAULT NULL COMMENT 'When sales followed up',\n  `notes` text DEFAULT NULL COMMENT 'Sales notes',\n  PRIMARY KEY (`id`),\n  KEY `idx_email` (`email`),\n  KEY `idx_source` (`sourceQrId`),\n  KEY `idx_session` (`sessionId`),\n  KEY `idx_created` (`createdAt`),\n  CONSTRAINT `fk_demo_leads_session` FOREIGN KEY (`sessionId`) REFERENCES `demo_sessions` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Sales leads captured from demo environment CTAs'"
  },
  {
    "type": "create_table",
    "description": "Create demo_analytics_events table in kiosk_demo for tracking demo behavior",
    "database": "kiosk_demo",
    "check_query": "SHOW TABLES LIKE 'demo_analytics_events'",
    "sql": "CREATE TABLE `demo_analytics_events` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `sessionId` int(10) unsigned NOT NULL COMMENT 'Reference to demo_sessions.id',\n  `eventType` varchar(50) NOT NULL COMMENT 'Event type: page_view, feature_click, tour_step, cta_click',\n  `eventData` json NOT NULL COMMENT 'Event-specific data payload',\n  `pagePath` varchar(255) DEFAULT NULL COMMENT 'Page URL path where event occurred',\n  `createdAt` datetime NOT NULL DEFAULT current_timestamp(),\n  PRIMARY KEY (`id`),\n  KEY `idx_session` (`sessionId`),\n  KEY `idx_type_time` (`eventType`, `createdAt`),\n  KEY `idx_created` (`createdAt`),\n  CONSTRAINT `fk_demo_analytics_session` FOREIGN KEY (`sessionId`) REFERENCES `demo_sessions` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Analytics events for demo user behavior tracking'"
  },
  {
    "type": "create_table",
    "description": "Create demo_rate_limits table in kiosk_demo for magic link request limits",
    "database": "kiosk_demo",
    "check_query": "SHOW TABLES LIKE 'demo_rate_limits'",
    "sql": "CREATE TABLE `demo_rate_limits` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `identifier` varchar(255) NOT NULL COMMENT 'IP address or email for rate limiting',\n  `identifierType` enum('ip','email') NOT NULL DEFAULT 'ip',\n  `attempts` int(10) unsigned NOT NULL DEFAULT 1,\n  `windowStart` datetime NOT NULL COMMENT 'Start of rate limit window',\n  `createdAt` datetime NOT NULL DEFAULT current_timestamp(),\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `uk_identifier_type` (`identifier`, `identifierType`),\n  KEY `idx_window` (`windowStart`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Rate limiting for demo magic link requests (5 per 5 minutes per IP)'"
  }
]
