CREATE TABLE `act_sponsor_photos` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `acts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `no_of_perticipant` int(11) NOT NULL,
  `image` varchar(255) NOT NULL,
  `video` varchar(255) DEFAULT NULL,
  `added_by` bigint(20) unsigned DEFAULT NULL,
  `deleted_by` bigint(20) unsigned DEFAULT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `is_deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'allow only 0 / 1 for true and false',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `acts_event_id_foreign` (`event_id`),
  KEY `acts_added_by_foreign` (`added_by`),
  KEY `acts_deleted_by_foreign` (`deleted_by`),
  CONSTRAINT `acts_added_by_foreign` FOREIGN KEY (`added_by`) REFERENCES `users` (`id`),
  CONSTRAINT `acts_deleted_by_foreign` FOREIGN KEY (`deleted_by`) REFERENCES `users` (`id`),
  CONSTRAINT `acts_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `admin_permissions` (
  `admin_id` bigint(20) unsigned NOT NULL,
  `permission_id` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`admin_id`,`permission_id`),
  KEY `idx_admin_id` (`admin_id`),
  CONSTRAINT `admin_permissions_admin_id_foreign` FOREIGN KEY (`admin_id`) REFERENCES `admins` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `admin_roles` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `display_name` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `permissions` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`permissions`)),
  `is_system` tinyint(1) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `admin_roles_name_unique` (`name`),
  KEY `admin_roles_is_active_index` (`is_active`),
  KEY `admin_roles_is_system_index` (`is_system`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `archived_event_artist` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `archived_event_id` bigint(20) unsigned NOT NULL,
  `artist_id` bigint(20) unsigned NOT NULL,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `role` varchar(100) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_archived_event_artist` (`archived_event_id`,`artist_id`),
  KEY `archived_event_artist_archived_event_id_index` (`archived_event_id`),
  KEY `archived_event_artist_artist_id_index` (`artist_id`),
  CONSTRAINT `archived_event_artist_archived_event_id_foreign` FOREIGN KEY (`archived_event_id`) REFERENCES `archived_events` (`id`) ON DELETE CASCADE,
  CONSTRAINT `archived_event_artist_artist_id_foreign` FOREIGN KEY (`artist_id`) REFERENCES `artists` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `archived_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(191) NOT NULL,
  `slug` varchar(191) NOT NULL,
  `subtitle` varchar(191) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `venue_name` varchar(500) DEFAULT NULL,
  `venue_city` varchar(100) NOT NULL DEFAULT 'London',
  `venue_country` varchar(100) NOT NULL DEFAULT 'United Kingdom',
  `event_date` date DEFAULT NULL,
  `event_year` year(4) DEFAULT NULL,
  `is_published` tinyint(1) NOT NULL DEFAULT 1,
  `is_featured` tinyint(1) NOT NULL DEFAULT 0,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `legacy_event_id` int(10) unsigned DEFAULT NULL,
  `legacy_metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`legacy_metadata`)),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `archived_events_slug_unique` (`slug`),
  UNIQUE KEY `archived_events_legacy_event_id_unique` (`legacy_event_id`),
  KEY `archived_events_slug_index` (`slug`),
  KEY `archived_events_event_year_index` (`event_year`),
  KEY `archived_events_is_published_display_order_index` (`is_published`,`display_order`),
  KEY `archived_events_legacy_event_id_index` (`legacy_event_id`),
  KEY `archived_events_is_featured_index` (`is_featured`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `artist_event` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `artist_id` bigint(20) unsigned NOT NULL,
  `event_id` bigint(20) unsigned NOT NULL,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `role` varchar(50) NOT NULL DEFAULT 'performer',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `artist_event_artist_id_event_id_unique` (`artist_id`,`event_id`),
  KEY `artist_event_event_id_display_order_index` (`event_id`,`display_order`),
  CONSTRAINT `artist_event_artist_id_foreign` FOREIGN KEY (`artist_id`) REFERENCES `artists` (`id`) ON DELETE CASCADE,
  CONSTRAINT `artist_event_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `artists` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `legacy_artist_id` int(10) unsigned DEFAULT NULL COMMENT 'ID from legacy globalgala_inspect.infrecord table',
  `name` varchar(191) NOT NULL,
  `name_arabic` varchar(191) DEFAULT NULL COMMENT 'Artist name in Arabic',
  `slug` varchar(191) NOT NULL,
  `bio` text DEFAULT NULL,
  `bio_arabic` text DEFAULT NULL COMMENT 'Biography in Arabic',
  `profile_image` varchar(500) DEFAULT NULL,
  `website_url` varchar(500) DEFAULT NULL,
  `instagram_url` varchar(500) DEFAULT NULL,
  `twitter_url` varchar(500) DEFAULT NULL,
  `facebook_url` varchar(500) DEFAULT NULL,
  `youtube_url` varchar(500) DEFAULT NULL,
  `spotify_url` varchar(500) DEFAULT NULL,
  `legacy_metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'JSON storage for legacy system data (dates, fields, etc.)' CHECK (json_valid(`legacy_metadata`)),
  `is_published` tinyint(1) NOT NULL DEFAULT 0,
  `is_featured` tinyint(1) NOT NULL DEFAULT 0,
  `is_legacy` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Indicates if artist migrated from legacy system',
  `display_order` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Manual sorting order for artist listings',
  `status` varchar(50) NOT NULL DEFAULT 'active',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `artists_slug_unique` (`slug`),
  KEY `artists_slug_index` (`slug`),
  KEY `artists_status_index` (`status`),
  KEY `artists_is_published_index` (`is_published`),
  KEY `artists_legacy_artist_id_index` (`legacy_artist_id`),
  KEY `artists_is_legacy_index` (`is_legacy`),
  KEY `artists_display_order_index` (`display_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `banners` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `image` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `status` int(11) NOT NULL DEFAULT 1,
  `order` int(11) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `batch_jobs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` char(36) NOT NULL,
  `name` varchar(255) NOT NULL,
  `status` enum('initializing','processing','completed','failed','cancelled') NOT NULL DEFAULT 'initializing',
  `total_items` int(11) NOT NULL DEFAULT 0,
  `processed_items` int(11) NOT NULL DEFAULT 0,
  `failed_items` int(11) NOT NULL DEFAULT 0,
  `chunk_size` int(11) NOT NULL DEFAULT 100,
  `progress_percentage` decimal(5,2) NOT NULL DEFAULT 0.00,
  `options` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`options`)),
  `error_message` text DEFAULT NULL,
  `started_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `cancelled_at` timestamp NULL DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `result_summary` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`result_summary`)),
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `batch_jobs_batch_id_unique` (`batch_id`),
  KEY `batch_jobs_batch_id_index` (`batch_id`),
  KEY `batch_jobs_status_index` (`status`),
  KEY `batch_jobs_created_at_index` (`created_at`),
  KEY `batch_jobs_status_created_at_index` (`status`,`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `blog_categories` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `status` int(11) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `blogs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL,
  `sub_category_id` int(11) DEFAULT NULL,
  `title` varchar(255) NOT NULL,
  `slug` varchar(250) NOT NULL,
  `image` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `is_published` int(11) NOT NULL,
  `show_on_homepage` int(11) NOT NULL,
  `blog_views` int(11) NOT NULL DEFAULT 0,
  `status` int(11) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `booking_access_codes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(191) NOT NULL COMMENT '8-char unpredictable code',
  `event_id` bigint(20) unsigned DEFAULT NULL COMMENT 'NULL = works for all events',
  `max_sessions` tinyint(3) unsigned NOT NULL DEFAULT 2 COMMENT 'Max different sessions allowed',
  `expires_at` timestamp NULL DEFAULT NULL COMMENT 'NULL = never expires',
  `created_by` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin user ID',
  `notes` text DEFAULT NULL COMMENT 'Admin reference notes',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `booking_access_codes_code_unique` (`code`),
  KEY `booking_access_codes_code_index` (`code`),
  KEY `booking_access_codes_expires_at_index` (`expires_at`),
  KEY `booking_access_codes_event_id_index` (`event_id`),
  KEY `booking_access_codes_created_by_foreign` (`created_by`),
  CONSTRAINT `booking_access_codes_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `booking_access_codes_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `bulk_ticket_status_batches` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` char(36) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `operation_type` enum('block','unblock','shadow_sold','activate') NOT NULL,
  `status` enum('initializing','processing','completed','failed','cancelled') NOT NULL DEFAULT 'initializing',
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `total_seats` int(11) NOT NULL DEFAULT 0,
  `processed_seats` int(11) NOT NULL DEFAULT 0,
  `successful_seats` int(11) NOT NULL DEFAULT 0,
  `failed_seats` int(11) NOT NULL DEFAULT 0,
  `failed_seat_ids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`failed_seat_ids`)),
  `errors` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`errors`)),
  `csv_filename` varchar(255) DEFAULT NULL,
  `started_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `bulk_ticket_status_batches_batch_id_unique` (`batch_id`),
  KEY `bulk_ticket_status_batches_created_at_index` (`created_at`),
  KEY `bulk_ticket_status_batches_status_created_at_index` (`status`,`created_at`),
  KEY `bulk_ticket_status_batches_operation_type_index` (`operation_type`),
  KEY `bulk_ticket_status_batches_status_index` (`status`),
  KEY `bulk_ticket_status_batches_event_id_index` (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `campaign_audit_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `campaign_name` varchar(191) NOT NULL,
  `event_type` enum('created','started','paused','resumed','cancelled','completed','settings_modified','invitation_sent','invitation_failed') NOT NULL COMMENT 'Type of campaign event',
  `user_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin user ID',
  `user_email` varchar(191) DEFAULT NULL COMMENT 'Admin email for reference',
  `timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
  `details` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Event-specific data' CHECK (json_valid(`details`)),
  PRIMARY KEY (`id`),
  KEY `idx_audit_campaign_name` (`campaign_name`),
  KEY `idx_event_type` (`event_type`),
  KEY `idx_timestamp` (`timestamp`),
  KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `carts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) DEFAULT NULL,
  `ip` varchar(250) NOT NULL,
  `user_id` varchar(250) NOT NULL,
  `seat_id` varchar(250) NOT NULL,
  `seat` varchar(250) NOT NULL,
  `quantity` int(11) NOT NULL DEFAULT 1,
  `amount` varchar(250) NOT NULL,
  `zone` varchar(250) DEFAULT NULL,
  `category` varchar(250) NOT NULL,
  `sub_cat` varchar(250) DEFAULT NULL,
  `seat_color` varchar(250) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_cart_seat` (`event_id`,`seat_id`,`seat`),
  KEY `idx_user_event` (`user_id`,`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `chargebacks` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) unsigned NOT NULL,
  `payment_transaction_id` bigint(20) unsigned DEFAULT NULL,
  `chargeback_amount` decimal(10,2) NOT NULL,
  `chargeback_reason` text DEFAULT NULL,
  `dispute_status` enum('needs_response','received','under_review','evidence_required','evidence_submitted','won','lost','accepted','withdrawn') DEFAULT 'received',
  `gateway` varchar(50) NOT NULL,
  `gateway_dispute_id` varchar(255) DEFAULT NULL,
  `gateway_charge_id` varchar(255) DEFAULT NULL,
  `gateway_payment_intent_id` varchar(255) DEFAULT NULL,
  `evidence_submitted_at` timestamp NULL DEFAULT NULL,
  `evidence_due_by` timestamp NULL DEFAULT NULL,
  `admin_notified_at` timestamp NULL DEFAULT NULL,
  `resolved_at` timestamp NULL DEFAULT NULL,
  `resolution_outcome` enum('won','lost','accepted','withdrawn') DEFAULT NULL,
  `gateway_response` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`gateway_response`)),
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `chargebacks_order_id_dispute_status_index` (`order_id`,`dispute_status`),
  KEY `chargebacks_payment_transaction_id_index` (`payment_transaction_id`),
  KEY `chargebacks_gateway_dispute_id_index` (`gateway_dispute_id`),
  KEY `chargebacks_dispute_status_index` (`dispute_status`),
  KEY `chargebacks_created_at_index` (`created_at`),
  KEY `chargebacks_gateway_payment_intent_id_index` (`gateway_payment_intent_id`),
  CONSTRAINT `chargebacks_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chargebacks_payment_transaction_id_foreign` FOREIGN KEY (`payment_transaction_id`) REFERENCES `payment_transactions` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `clubs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `contact_name` varchar(255) NOT NULL,
  `contact_email` varchar(255) NOT NULL,
  `contact_phone` varchar(255) NOT NULL,
  `treasurer` varchar(255) NOT NULL,
  `logo` varchar(255) NOT NULL,
  `bank_details` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `is_active` tinyint(4) NOT NULL DEFAULT 1 COMMENT 'allow only 0 / 1 for true and false',
  `is_deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'allow only 0 / 1 for true and false',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `cms_files` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `filename` varchar(191) NOT NULL,
  `stored_filename` varchar(191) NOT NULL,
  `path` varchar(191) NOT NULL,
  `file_path` varchar(500) DEFAULT NULL,
  `public_url` varchar(500) DEFAULT NULL,
  `file_size` bigint(20) unsigned DEFAULT NULL,
  `mime_type` varchar(100) NOT NULL,
  `is_image` tinyint(1) DEFAULT 0,
  `is_video` tinyint(1) DEFAULT 0,
  `size` bigint(20) unsigned NOT NULL,
  `category` enum('email','blog','general') NOT NULL DEFAULT 'general',
  `tags` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`tags`)),
  `description` text DEFAULT NULL,
  `is_public` tinyint(1) NOT NULL DEFAULT 1,
  `uploaded_by` bigint(20) unsigned DEFAULT NULL,
  `usage_count` int(10) unsigned NOT NULL DEFAULT 0,
  `last_accessed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `cms_files_stored_filename_unique` (`stored_filename`),
  KEY `cms_files_category_index` (`category`),
  KEY `cms_files_mime_type_index` (`mime_type`),
  KEY `cms_files_is_public_index` (`is_public`),
  KEY `cms_files_uploaded_by_index` (`uploaded_by`),
  KEY `cms_files_created_at_index` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `content_pages` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `slug` varchar(255) NOT NULL,
  `content` longtext NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `display_section` enum('header','footer','event_info','standalone') NOT NULL DEFAULT 'footer',
  `meta_title` varchar(255) DEFAULT NULL,
  `meta_description` text DEFAULT NULL,
  `meta_keywords` varchar(255) DEFAULT NULL,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `content_pages_slug_unique` (`slug`),
  KEY `content_pages_is_active_sort_order_index` (`is_active`,`sort_order`),
  KEY `content_pages_display_section_index` (`display_section`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `coupon_usage` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `coupon_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Which coupon was used (nullable to preserve audit trail if coupon deleted)',
  `order_id` varchar(255) NOT NULL COMMENT 'Order ID (alphanumeric string from orders.order_id)',
  `customer_email` varchar(191) NOT NULL COMMENT 'Customer email (for per-customer limit tracking)',
  `discount_applied` decimal(10,2) NOT NULL COMMENT 'Actual discount amount applied to this order',
  `original_subtotal` decimal(10,2) NOT NULL COMMENT 'Order subtotal before discount',
  `final_subtotal` decimal(10,2) NOT NULL COMMENT 'Order subtotal after discount',
  `event_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Which event this order was for',
  `seats_count` int(11) NOT NULL COMMENT 'Number of seats/tickets in this order',
  `used_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'When coupon was redeemed',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_coupon_order_unique` (`coupon_id`,`order_id`),
  KEY `coupon_usage_event_id_foreign` (`event_id`),
  KEY `idx_coupon` (`coupon_id`),
  KEY `idx_order` (`order_id`),
  KEY `idx_customer` (`customer_email`),
  KEY `idx_coupon_customer` (`coupon_id`,`customer_email`),
  KEY `idx_used_at` (`used_at`),
  CONSTRAINT `coupon_usage_coupon_id_foreign` FOREIGN KEY (`coupon_id`) REFERENCES `coupons` (`id`) ON DELETE SET NULL,
  CONSTRAINT `coupon_usage_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `coupons` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL COMMENT 'Coupon code: uppercase alphanumeric + hyphens only',
  `description` text DEFAULT NULL COMMENT 'Admin description of coupon purpose',
  `discount_type` enum('percentage','fixed') NOT NULL COMMENT 'percentage: % off subtotal, fixed: € off subtotal',
  `discount_value` decimal(10,2) NOT NULL COMMENT 'Percentage (0-100) or fixed amount in euros',
  `applies_to` enum('all_events','specific_event') NOT NULL DEFAULT 'all_events' COMMENT 'Whether coupon applies globally or to specific event',
  `event_id` bigint(20) unsigned DEFAULT NULL COMMENT 'If applies_to=specific_event, which event',
  `max_uses` int(11) DEFAULT NULL COMMENT 'Maximum total uses (NULL = unlimited)',
  `uses_count` int(11) NOT NULL DEFAULT 0 COMMENT 'Current usage count (incremented on each redemption)',
  `max_uses_per_customer` int(11) NOT NULL DEFAULT 1 COMMENT 'Maximum uses per customer email',
  `min_order_value` decimal(10,2) DEFAULT NULL COMMENT 'Minimum subtotal required to apply coupon',
  `valid_from` datetime DEFAULT NULL COMMENT 'Coupon valid from this datetime (NULL = valid immediately)',
  `valid_until` datetime DEFAULT NULL COMMENT 'Coupon expires at this datetime (NULL = never expires)',
  `status` enum('active','inactive','expired') NOT NULL DEFAULT 'active' COMMENT 'active: can be used, inactive: disabled by admin, expired: past valid_until',
  `created_by` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin user ID who created this coupon',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `coupons_code_unique` (`code`),
  KEY `coupons_created_by_foreign` (`created_by`),
  KEY `idx_code` (`code`),
  KEY `idx_status` (`status`),
  KEY `idx_valid_dates` (`valid_from`,`valid_until`),
  KEY `idx_event` (`event_id`),
  CONSTRAINT `coupons_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `admins` (`id`) ON DELETE SET NULL,
  CONSTRAINT `coupons_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `customers` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `preferred_payment_method` varchar(255) DEFAULT NULL,
  `loyalty_points` int(11) NOT NULL DEFAULT 0,
  `membership_tier` varchar(255) DEFAULT NULL,
  `date_of_birth` date DEFAULT NULL,
  `preferences` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`preferences`)),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `customers_user_id_index` (`user_id`),
  KEY `customers_membership_tier_index` (`membership_tier`),
  CONSTRAINT `customers_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `donation_amounts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `amount` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `email_accounts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `email` varchar(255) NOT NULL,
  `display_name` varchar(255) NOT NULL,
  `purpose` varchar(100) NOT NULL COMMENT 'transactional, support, finance, system, etc.',
  `daily_send_limit` int(11) NOT NULL DEFAULT 500,
  `hourly_send_limit` int(11) NOT NULL DEFAULT 50,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `auto_response` text DEFAULT NULL,
  `reply_to_email` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_accounts_email_unique` (`email`),
  KEY `email_accounts_is_active_index` (`is_active`),
  KEY `email_accounts_purpose_is_active_index` (`purpose`,`is_active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `email_inbox` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `account_email` varchar(255) NOT NULL,
  `message_id` varchar(255) NOT NULL,
  `thread_id` varchar(255) DEFAULT NULL,
  `from_email` varchar(255) NOT NULL,
  `from_name` varchar(255) DEFAULT NULL,
  `subject` varchar(500) NOT NULL,
  `body_text` text DEFAULT NULL,
  `body_html` longtext DEFAULT NULL,
  `received_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `is_read` tinyint(1) NOT NULL DEFAULT 0,
  `is_replied` tinyint(1) NOT NULL DEFAULT 0,
  `linked_order_id` varchar(50) DEFAULT NULL,
  `linked_ticket_id` bigint(20) unsigned DEFAULT NULL,
  `assigned_to_admin_id` bigint(20) unsigned DEFAULT NULL,
  `priority` enum('low','normal','high','urgent') NOT NULL DEFAULT 'normal',
  `status` enum('new','open','pending','resolved','closed') NOT NULL DEFAULT 'new',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_inbox_message_id_unique` (`message_id`),
  KEY `email_inbox_account_email_received_at_index` (`account_email`,`received_at`),
  KEY `email_inbox_thread_id_index` (`thread_id`),
  KEY `email_inbox_status_priority_index` (`status`,`priority`),
  KEY `email_inbox_linked_order_id_index` (`linked_order_id`),
  KEY `email_inbox_assigned_to_admin_id_foreign` (`assigned_to_admin_id`),
  CONSTRAINT `email_inbox_assigned_to_admin_id_foreign` FOREIGN KEY (`assigned_to_admin_id`) REFERENCES `admins` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `email_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `message_id` varchar(255) DEFAULT NULL,
  `template_id` bigint(20) unsigned DEFAULT NULL,
  `email_type` varchar(50) DEFAULT NULL COMMENT 'order, ticket, receipt, notification, etc.',
  `recipient_email` varchar(255) NOT NULL,
  `recipient_name` varchar(255) DEFAULT NULL,
  `from_email` varchar(255) DEFAULT NULL,
  `subject` varchar(255) NOT NULL,
  `body_html` text NOT NULL,
  `body_text` text DEFAULT NULL,
  `status` varchar(255) NOT NULL DEFAULT 'pending',
  `send_rate_hour` int(11) NOT NULL DEFAULT 0,
  `error_message` text DEFAULT NULL,
  `bounce_type` varchar(50) DEFAULT NULL,
  `spam_score` decimal(3,2) DEFAULT NULL,
  `delivery_time_ms` int(11) DEFAULT NULL,
  `sent_at` timestamp NULL DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `sent_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_logs_message_id_unique` (`message_id`),
  KEY `email_logs_recipient_email_status_index` (`recipient_email`,`status`),
  KEY `email_logs_template_id_sent_at_index` (`template_id`,`sent_at`),
  KEY `email_logs_status_created_at_index` (`status`,`created_at`),
  KEY `idx_sent_at_account` (`sent_at`,`from_email`),
  KEY `idx_status_type` (`status`,`email_type`),
  CONSTRAINT `email_logs_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `email_templates` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `email_rate_tracking` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `account_email` varchar(255) NOT NULL,
  `hour_timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'Rounded to hour for rate tracking',
  `emails_sent` int(11) NOT NULL DEFAULT 0,
  `emails_bounced` int(11) NOT NULL DEFAULT 0,
  `emails_spam_reported` int(11) NOT NULL DEFAULT 0,
  `avg_delivery_time_ms` int(11) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_hour` (`account_email`,`hour_timestamp`),
  KEY `email_rate_tracking_account_email_hour_timestamp_index` (`account_email`,`hour_timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `email_reputation` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `account_email` varchar(255) NOT NULL,
  `date` date NOT NULL,
  `emails_sent` int(11) NOT NULL DEFAULT 0,
  `emails_delivered` int(11) NOT NULL DEFAULT 0,
  `emails_bounced` int(11) NOT NULL DEFAULT 0,
  `emails_failed` int(11) NOT NULL DEFAULT 0,
  `hard_bounces` int(11) NOT NULL DEFAULT 0,
  `soft_bounces` int(11) NOT NULL DEFAULT 0,
  `spam_reports` int(11) NOT NULL DEFAULT 0,
  `unsubscribes` int(11) NOT NULL DEFAULT 0,
  `bounce_rate` decimal(5,2) NOT NULL DEFAULT 0.00 COMMENT 'Percentage',
  `spam_rate` decimal(5,2) NOT NULL DEFAULT 0.00 COMMENT 'Percentage',
  `delivery_rate` decimal(5,2) NOT NULL DEFAULT 0.00 COMMENT 'Percentage',
  `health_score` decimal(5,2) NOT NULL DEFAULT 100.00 COMMENT '0-100 score',
  `status` enum('good','warning','critical') NOT NULL DEFAULT 'good',
  `alert_sent` tinyint(1) NOT NULL DEFAULT 0,
  `alert_sent_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_reputation_account_email_date_unique` (`account_email`,`date`),
  KEY `email_reputation_date_status_index` (`date`,`status`),
  KEY `email_reputation_account_email_date_status_index` (`account_email`,`date`,`status`),
  KEY `email_reputation_account_email_index` (`account_email`),
  KEY `email_reputation_date_index` (`date`),
  CONSTRAINT `email_reputation_account_email_foreign` FOREIGN KEY (`account_email`) REFERENCES `email_accounts` (`email`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `email_template_versions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `email_template_id` bigint(20) unsigned NOT NULL,
  `version` int(11) NOT NULL,
  `subject` varchar(255) NOT NULL,
  `html_content` text NOT NULL,
  `text_content` text DEFAULT NULL,
  `variables` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`variables`)),
  `attachments` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`attachments`)),
  `settings` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`settings`)),
  `changed_by` varchar(255) DEFAULT NULL,
  `change_notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_template_versions_email_template_id_version_unique` (`email_template_id`,`version`),
  KEY `email_template_versions_version_index` (`version`),
  CONSTRAINT `email_template_versions_email_template_id_foreign` FOREIGN KEY (`email_template_id`) REFERENCES `email_templates` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `email_templates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `slug` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL DEFAULT 'system',
  `sender_name` varchar(255) NOT NULL,
  `sender_email` varchar(255) NOT NULL,
  `subject` varchar(255) NOT NULL,
  `body_html` text NOT NULL,
  `body_text` text DEFAULT NULL,
  `placeholders` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`placeholders`)),
  `attachments` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`attachments`)),
  `version` int(11) NOT NULL DEFAULT 1,
  `description` text DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_system` tinyint(1) NOT NULL DEFAULT 0,
  `include_event_reminder` tinyint(1) NOT NULL DEFAULT 1,
  `include_venue_directions` tinyint(1) NOT NULL DEFAULT 1,
  `include_support_contact` tinyint(1) NOT NULL DEFAULT 1,
  `attach_pdf_ticket` tinyint(1) NOT NULL DEFAULT 1,
  `times_used` int(11) NOT NULL DEFAULT 0,
  `last_used_at` timestamp NULL DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_templates_slug_unique` (`slug`),
  KEY `email_templates_type_is_active_index` (`type`,`is_active`),
  KEY `email_templates_slug_index` (`slug`),
  KEY `email_templates_slug_is_active_index` (`slug`,`is_active`),
  KEY `email_templates_type_index` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `eod_reports` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `report_date` date NOT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `currency` varchar(3) NOT NULL DEFAULT 'GBP',
  `expected_cash` decimal(12,2) NOT NULL DEFAULT 0.00,
  `expected_card` decimal(12,2) NOT NULL DEFAULT 0.00,
  `expected_total` decimal(12,2) NOT NULL DEFAULT 0.00,
  `actual_cash` decimal(12,2) NOT NULL DEFAULT 0.00,
  `actual_card` decimal(12,2) NOT NULL DEFAULT 0.00,
  `actual_total` decimal(12,2) NOT NULL DEFAULT 0.00,
  `cash_variance` decimal(12,2) NOT NULL DEFAULT 0.00,
  `card_variance` decimal(12,2) NOT NULL DEFAULT 0.00,
  `total_variance` decimal(12,2) NOT NULL DEFAULT 0.00,
  `total_variance_percent` decimal(8,4) NOT NULL DEFAULT 0.0000,
  `status` enum('pending','approved','flagged') NOT NULL DEFAULT 'pending',
  `staff_id` bigint(20) unsigned NOT NULL,
  `manager_id` bigint(20) unsigned DEFAULT NULL,
  `signed_off_at` timestamp NULL DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `manager_comments` text DEFAULT NULL,
  `investigation_reason` text DEFAULT NULL,
  `audit_reference` varchar(50) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `eod_reports_audit_reference_unique` (`audit_reference`),
  UNIQUE KEY `eod_reports_date_event_unique` (`report_date`,`event_id`),
  KEY `eod_reports_report_date_event_id_index` (`report_date`,`event_id`),
  KEY `eod_reports_status_report_date_index` (`status`,`report_date`),
  KEY `eod_reports_staff_id_index` (`staff_id`),
  KEY `eod_reports_manager_id_index` (`manager_id`),
  KEY `eod_reports_event_id_foreign` (`event_id`),
  CONSTRAINT `eod_reports_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE SET NULL,
  CONSTRAINT `eod_reports_manager_id_foreign` FOREIGN KEY (`manager_id`) REFERENCES `admins` (`id`) ON DELETE SET NULL,
  CONSTRAINT `eod_reports_staff_id_foreign` FOREIGN KEY (`staff_id`) REFERENCES `admins` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `event_categories` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `slug` varchar(100) NOT NULL,
  `description` text DEFAULT NULL,
  `icon` varchar(50) DEFAULT NULL,
  `color` varchar(7) DEFAULT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `event_categories_name_unique` (`name`),
  UNIQUE KEY `event_categories_slug_unique` (`slug`),
  KEY `event_categories_slug_index` (`slug`),
  KEY `event_categories_is_active_index` (`is_active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `event_images` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `imageable_id` bigint(20) unsigned NOT NULL,
  `imageable_type` varchar(191) NOT NULL,
  `role` varchar(50) NOT NULL DEFAULT 'gallery',
  `filename` varchar(191) NOT NULL,
  `storage_path` varchar(500) NOT NULL,
  `thumbnail_path` varchar(500) DEFAULT NULL,
  `large_path` varchar(500) DEFAULT NULL,
  `title` varchar(191) DEFAULT NULL,
  `caption` text DEFAULT NULL,
  `alt_text` varchar(191) DEFAULT NULL,
  `width` int(11) DEFAULT NULL,
  `height` int(11) DEFAULT NULL,
  `file_size` int(11) DEFAULT NULL,
  `mime_type` varchar(100) DEFAULT NULL,
  `is_featured` tinyint(1) NOT NULL DEFAULT 0,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `legacy_image_id` int(10) unsigned DEFAULT NULL,
  `download_status` enum('pending','downloaded','failed') NOT NULL DEFAULT 'downloaded',
  `download_error` text DEFAULT NULL,
  `migrated_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_imageable` (`imageable_type`,`imageable_id`),
  KEY `event_images_legacy_image_id_index` (`legacy_image_id`),
  KEY `event_images_is_featured_index` (`is_featured`),
  KEY `event_images_download_status_index` (`download_status`),
  KEY `event_images_role_index` (`role`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `event_photos` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `file_name` varchar(100) NOT NULL,
  `event_id` bigint(20) unsigned NOT NULL,
  `is_featured` tinyint(4) NOT NULL DEFAULT 0,
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `event_photos_event_id_foreign` (`event_id`),
  CONSTRAINT `event_photos_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `event_venues` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned NOT NULL,
  `venue_template_id` bigint(20) unsigned NOT NULL,
  `pricing_overrides` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`pricing_overrides`)),
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_event_venue_template` (`event_id`,`venue_template_id`),
  KEY `idx_event_venues_event_id` (`event_id`),
  KEY `idx_event_venues_venue_template_id` (`venue_template_id`),
  KEY `idx_event_venues_event_active` (`event_id`,`is_active`),
  CONSTRAINT `fk_event_venues_event_id` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_event_venues_venue_template_id` FOREIGN KEY (`venue_template_id`) REFERENCES `venue_templates` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `event_wise_seat_categories` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) NOT NULL,
  `seats` varchar(255) NOT NULL,
  `ticket_category` varchar(255) NOT NULL,
  `price` decimal(10,2) DEFAULT NULL,
  `zone` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `event_wise_seat_categories_seats_event_id_index` (`seats`,`event_id`),
  KEY `event_wise_seat_categories_event_id_index` (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `legacy_event_id` int(10) unsigned DEFAULT NULL COMMENT 'Original event ID from legacy globalgala system',
  `theme_id` bigint(20) unsigned DEFAULT NULL,
  `venue_id` bigint(20) unsigned DEFAULT NULL,
  `club_id` bigint(20) unsigned NOT NULL,
  `organizer_name` varchar(255) NOT NULL,
  `organizer_email` varchar(255) NOT NULL,
  `organizer_phone` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `sub_title` varchar(191) DEFAULT NULL,
  `event_type` varchar(255) NOT NULL,
  `category` enum('concert','conference','convention','exhibition','festival','party','performance','other') DEFAULT NULL COMMENT 'Event category for Revolut industry_data (improves acceptance rates)',
  `market` enum('primary','secondary') NOT NULL DEFAULT 'primary' COMMENT 'Ticket distribution type: primary (organizer) or secondary (reseller)',
  `event_image_url` varchar(255) DEFAULT NULL,
  `event_url` varchar(255) NOT NULL,
  `page_name` varchar(191) DEFAULT NULL,
  `start_date` date NOT NULL,
  `event_year` int(10) unsigned DEFAULT NULL COMMENT 'Year for archival grouping (especially for legacy events with missing dates)',
  `end_date` date NOT NULL,
  `supplier_payment_date` datetime DEFAULT NULL COMMENT 'Date when funds released to supplier (default: event_date + 7 days)',
  `start_time` time NOT NULL,
  `doors_open_time` time DEFAULT NULL,
  `timezone` varchar(255) NOT NULL DEFAULT 'UTC',
  `voting_end_time` datetime NOT NULL,
  `description` text NOT NULL,
  `map_banner_text` text DEFAULT NULL,
  `booking_banner_image` varchar(255) DEFAULT NULL,
  `inquiry_poll` text DEFAULT NULL,
  `event_email_thankyou_text` text DEFAULT NULL,
  `event_support_thankyou_text` text DEFAULT NULL,
  `meta_description` text DEFAULT NULL,
  `is_featured` tinyint(1) NOT NULL DEFAULT 0,
  `meta_title` varchar(191) DEFAULT NULL,
  `meta_keyword` varchar(191) DEFAULT NULL,
  `is_published` tinyint(1) NOT NULL DEFAULT 0,
  `is_legacy` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Indicates if event is from legacy archive (not bookable)',
  `display_order` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Manual sorting order for event listings',
  `is_test_mode` tinyint(1) NOT NULL DEFAULT 0,
  `publish_website` tinyint(1) NOT NULL DEFAULT 0,
  `slug` varchar(255) NOT NULL,
  `currency` varchar(10) NOT NULL DEFAULT '£',
  `max_no_of_tickets` int(11) NOT NULL,
  `ticket_template_id` bigint(20) unsigned DEFAULT NULL,
  `bracelet_template_id` bigint(20) unsigned DEFAULT NULL,
  `label_template_id` bigint(20) unsigned DEFAULT NULL,
  `no_of_raffle_ticket` int(11) DEFAULT NULL,
  `raffle_ticket_price` double(8,2) DEFAULT NULL,
  `video` varchar(255) DEFAULT NULL,
  `main_page_banner` varchar(191) DEFAULT NULL,
  `centered_banner` varchar(191) DEFAULT NULL,
  `baner_wide` varchar(191) DEFAULT NULL,
  `banner_tablet` varchar(191) DEFAULT NULL,
  `banner_phone` varchar(191) DEFAULT NULL,
  `destaque_home` varchar(191) DEFAULT NULL,
  `imagem_poster` varchar(191) DEFAULT NULL,
  `buttom_banner_frame` varchar(191) DEFAULT NULL,
  `address` varchar(255) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `legacy_metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'JSON storage for legacy system data (original status, notes, etc.)' CHECK (json_valid(`legacy_metadata`)),
  `enable_booking_fee` tinyint(1) NOT NULL DEFAULT 0,
  `enable_vat` tinyint(1) NOT NULL DEFAULT 0,
  `booking_fee_rate` decimal(5,4) DEFAULT NULL,
  `booking_fee_min` decimal(8,2) DEFAULT NULL,
  `booking_fee_max` decimal(8,2) DEFAULT NULL,
  `vat_rate` decimal(5,4) DEFAULT NULL,
  `ticket_code_type` enum('qr','barcode','both') NOT NULL DEFAULT 'qr' COMMENT 'Primary code type for tickets (qr, barcode, or both)',
  `email_code_type` enum('qr','barcode') NOT NULL DEFAULT 'qr' COMMENT 'Code type to display in emails (qr or barcode only)',
  `wristband_code_type` enum('qr','barcode') NOT NULL DEFAULT 'barcode' COMMENT 'Code type for wristband printing (usually barcode)',
  `pdf_code_type` enum('qr','barcode','both') NOT NULL DEFAULT 'qr' COMMENT 'Code type for PDF tickets',
  `enable_wristband_printing` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Enable wristband printing for this event',
  `wristband_printer_id` varchar(50) DEFAULT NULL COMMENT 'Zebra printer identifier for this event',
  `wristband_printing_enabled_at` timestamp NULL DEFAULT NULL COMMENT 'Timestamp when wristband printing was enabled',
  `scanner_config` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Scanner configuration (allowed code types, duplicate window, etc.)' CHECK (json_valid(`scanner_config`)),
  `is_deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'allow only 0 / 1 for true and false',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `sell_start_date` date DEFAULT NULL,
  `sell_start_time` time DEFAULT NULL,
  `sell_end_date` date DEFAULT NULL,
  `sell_end_time` time DEFAULT NULL,
  `publish_start_date` date DEFAULT NULL,
  `publish_start_time` time DEFAULT NULL,
  `publish_end_date` date DEFAULT NULL,
  `publish_end_time` time DEFAULT NULL,
  `include_booking_fee` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Whether booking fee (2.5%) is included for public bookings',
  `include_tax` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Whether tax (21% VAT) is included for public bookings',
  `video_url` varchar(2083) DEFAULT NULL COMMENT 'Bunny CDN video embed URL',
  `video_thumbnail_url` varchar(2083) DEFAULT NULL COMMENT 'Bunny CDN video thumbnail/poster URL',
  `video_collection_id` varchar(36) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `events_slug_unique` (`slug`),
  KEY `events_slug_index` (`slug`),
  KEY `events_venue_id_foreign` (`venue_id`),
  KEY `events_page_name_index` (`page_name`),
  KEY `events_is_published_index` (`is_published`),
  KEY `events_is_featured_index` (`is_featured`),
  KEY `events_theme_id_foreign` (`theme_id`),
  KEY `events_category_index` (`category`),
  KEY `events_market_index` (`market`),
  KEY `idx_events_public_filtering` (`is_deleted`,`is_published`,`is_test_mode`,`start_date`),
  KEY `idx_events_featured_published` (`is_deleted`,`is_featured`,`is_published`),
  KEY `idx_events_wristband_printing` (`enable_wristband_printing`),
  KEY `events_legacy_event_id_index` (`legacy_event_id`),
  KEY `events_is_legacy_index` (`is_legacy`),
  KEY `events_event_year_index` (`event_year`),
  KEY `events_display_order_index` (`display_order`),
  CONSTRAINT `events_theme_id_foreign` FOREIGN KEY (`theme_id`) REFERENCES `venue_themes` (`id`) ON DELETE SET NULL,
  CONSTRAINT `events_venue_id_foreign` FOREIGN KEY (`venue_id`) REFERENCES `venues` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `failed_invitation_attempts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `invitation_id` bigint(20) unsigned NOT NULL,
  `campaign_name` varchar(191) NOT NULL,
  `email` varchar(191) NOT NULL,
  `failure_type` enum('invalid_email','server_error','timeout','hard_bounce','soft_bounce','unknown') NOT NULL COMMENT 'Categorized failure reason',
  `failure_reason` text DEFAULT NULL COMMENT 'Human-readable failure description',
  `failed_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `retry_count` int(11) NOT NULL DEFAULT 0 COMMENT 'Number of retry attempts',
  `can_retry` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Whether retry is allowed',
  `last_error` text DEFAULT NULL COMMENT 'Last SMTP or exception error',
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Additional failure context' CHECK (json_valid(`metadata`)),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_failed_invitation_id` (`invitation_id`),
  KEY `idx_failed_campaign_name` (`campaign_name`),
  KEY `idx_failure_type` (`failure_type`),
  KEY `idx_can_retry` (`can_retry`),
  KEY `idx_failed_at` (`failed_at`),
  KEY `idx_failed_campaign_type` (`campaign_name`,`failure_type`),
  CONSTRAINT `failed_invitation_attempts_invitation_id_foreign` FOREIGN KEY (`invitation_id`) REFERENCES `account_setup_invitations` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `failed_jobs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) NOT NULL,
  `connection` text NOT NULL,
  `queue` text NOT NULL,
  `payload` longtext NOT NULL,
  `exception` longtext NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `faqs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `question` varchar(500) NOT NULL,
  `answer` varchar(1000) NOT NULL,
  `priority` int(11) NOT NULL DEFAULT 0,
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `fee_waiver_audit_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `reservation_id` bigint(20) unsigned DEFAULT NULL,
  `admin_user_id` bigint(20) unsigned DEFAULT NULL,
  `waiver_type` enum('booking_fee','tax','both') NOT NULL,
  `reason` text DEFAULT NULL COMMENT 'Reason for waiver: VIP, promotion, tax-exempt, comp ticket, etc.',
  `waived_amount` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'Total amount of fees/tax waived in euros',
  `customer_email` varchar(255) DEFAULT NULL,
  `customer_name` varchar(255) DEFAULT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Additional context: seats, pricing breakdown, etc.' CHECK (json_valid(`metadata`)),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fee_waiver_audit_log_order_id_foreign` (`order_id`),
  KEY `fee_waiver_audit_log_reservation_id_foreign` (`reservation_id`),
  KEY `fee_waiver_audit_log_created_at_index` (`created_at`),
  KEY `fee_waiver_audit_log_admin_user_id_created_at_index` (`admin_user_id`,`created_at`),
  KEY `fee_waiver_audit_log_event_id_created_at_index` (`event_id`,`created_at`),
  KEY `fee_waiver_audit_log_waiver_type_index` (`waiver_type`),
  KEY `fee_waiver_audit_log_customer_email_index` (`customer_email`),
  CONSTRAINT `fee_waiver_audit_log_admin_user_id_foreign` FOREIGN KEY (`admin_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fee_waiver_audit_log_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fee_waiver_audit_log_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fee_waiver_audit_log_reservation_id_foreign` FOREIGN KEY (`reservation_id`) REFERENCES `seat_reservations` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `fire_marshal_access_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `token_id` bigint(20) unsigned NOT NULL COMMENT 'Fire marshal token ID',
  `event_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Event accessed',
  `ip_address` varchar(45) NOT NULL COMMENT 'IP address of access',
  `user_agent` text DEFAULT NULL COMMENT 'Browser user agent',
  `accessed_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'When report was accessed',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fire_marshal_access_logs_token_id_index` (`token_id`),
  KEY `fire_marshal_access_logs_event_id_index` (`event_id`),
  KEY `fire_marshal_access_logs_accessed_at_index` (`accessed_at`),
  KEY `fire_marshal_access_logs_ip_address_index` (`ip_address`),
  CONSTRAINT `fire_marshal_access_logs_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fire_marshal_access_logs_token_id_foreign` FOREIGN KEY (`token_id`) REFERENCES `fire_marshal_tokens` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Audit log of fire marshal report access';
CREATE TABLE `fundraising_profiles` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL,
  `name` varchar(250) NOT NULL,
  `title` varchar(250) NOT NULL,
  `profile_photo` varchar(255) NOT NULL DEFAULT 'avatar.png',
  `cover_photo` varchar(255) NOT NULL DEFAULT 'sample1.jpg',
  `story` longtext DEFAULT NULL,
  `goal` int(11) NOT NULL DEFAULT 0,
  `amount_raised` int(11) NOT NULL DEFAULT 0,
  `type` varchar(1) NOT NULL DEFAULT 'U' COMMENT 'U-User, T-Team',
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `fundraising_profiles_name_unique` (`name`),
  KEY `fundraising_profiles_user_id_foreign` (`user_id`),
  CONSTRAINT `fundraising_profiles_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `fundraising_transactions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `profile_id` bigint(20) unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `message` varchar(500) DEFAULT NULL,
  `amount` int(11) NOT NULL,
  `reference` varchar(500) DEFAULT NULL COMMENT 'Stripe ID',
  `anonymous` tinyint(4) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0-Created,1-Paid',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fundraising_transactions_profile_id_foreign` (`profile_id`),
  CONSTRAINT `fundraising_transactions_profile_id_foreign` FOREIGN KEY (`profile_id`) REFERENCES `fundraising_profiles` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `galleries` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `images` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`images`)),
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `galleries_is_active_display_order_index` (`is_active`,`display_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `gdpr_audit_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_type` varchar(255) NOT NULL COMMENT 'Type of GDPR event (export, anonymize, delete, access)',
  `entity_type` varchar(255) NOT NULL COMMENT 'Type of entity accessed (order, payment_transaction, user)',
  `entity_id` bigint(20) unsigned DEFAULT NULL COMMENT 'ID of the entity accessed',
  `user_id` bigint(20) unsigned DEFAULT NULL COMMENT 'User who initiated the action',
  `user_type` varchar(255) DEFAULT NULL COMMENT 'Type of user (customer, admin, system)',
  `user_email` varchar(255) DEFAULT NULL COMMENT 'Email of user who initiated action',
  `ip_address` varchar(45) DEFAULT NULL COMMENT 'IP address of requester',
  `user_agent` text DEFAULT NULL COMMENT 'Browser user agent',
  `request_method` varchar(255) DEFAULT NULL COMMENT 'HTTP method (GET, POST, etc.)',
  `request_url` text DEFAULT NULL COMMENT 'URL that was accessed',
  `description` text DEFAULT NULL COMMENT 'Human-readable description of action',
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Additional context data' CHECK (json_valid(`metadata`)),
  `status` varchar(255) NOT NULL DEFAULT 'success' COMMENT 'Status of the action (success, failed, pending)',
  `error_message` text DEFAULT NULL COMMENT 'Error message if action failed',
  `data_retention_until` timestamp NULL DEFAULT NULL COMMENT 'When this audit log should be deleted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `gdpr_audit_logs_event_type_index` (`event_type`),
  KEY `gdpr_audit_logs_entity_type_index` (`entity_type`),
  KEY `gdpr_audit_logs_entity_type_entity_id_index` (`entity_type`,`entity_id`),
  KEY `gdpr_audit_logs_user_id_index` (`user_id`),
  KEY `gdpr_audit_logs_created_at_index` (`created_at`),
  KEY `gdpr_audit_logs_data_retention_until_index` (`data_retention_until`),
  KEY `gdpr_audit_logs_event_type_created_at_index` (`event_type`,`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `homepage_sections` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `section_type` varchar(50) NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`content`)),
  `display_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_section_active_order` (`section_type`,`is_active`,`display_order`),
  KEY `homepage_sections_section_type_index` (`section_type`),
  KEY `homepage_sections_display_order_index` (`display_order`),
  KEY `homepage_sections_is_active_index` (`is_active`),
  KEY `idx_section_type_active_order` (`section_type`,`is_active`,`display_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `jobs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `queue` varchar(255) NOT NULL,
  `payload` longtext NOT NULL,
  `attempts` tinyint(3) unsigned NOT NULL,
  `reserved_at` int(10) unsigned DEFAULT NULL,
  `available_at` int(10) unsigned NOT NULL,
  `created_at` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `jobs_queue_index` (`queue`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `mbs_activity_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `staff_user_id` bigint(20) unsigned NOT NULL,
  `staff_user_name` varchar(255) DEFAULT NULL,
  `staff_user_email` varchar(255) DEFAULT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `event_name` varchar(255) DEFAULT NULL,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `order_reference` varchar(255) DEFAULT NULL,
  `seat_id` bigint(20) unsigned DEFAULT NULL,
  `seat_identifier` varchar(255) DEFAULT NULL,
  `action_type` varchar(100) NOT NULL,
  `action_category` varchar(50) NOT NULL,
  `action_description` text NOT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` varchar(255) DEFAULT NULL,
  `request_method` varchar(10) DEFAULT NULL,
  `request_url` varchar(255) DEFAULT NULL,
  `old_values` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`old_values`)),
  `new_values` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`new_values`)),
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `success` tinyint(1) NOT NULL DEFAULT 1,
  `error_message` text DEFAULT NULL,
  `correlation_id` varchar(36) DEFAULT NULL,
  `severity` enum('low','medium','high','critical') NOT NULL DEFAULT 'medium',
  `requires_review` tinyint(1) NOT NULL DEFAULT 0,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `mbs_activity_logs_staff_user_id_index` (`staff_user_id`),
  KEY `mbs_activity_logs_event_id_index` (`event_id`),
  KEY `mbs_activity_logs_order_id_index` (`order_id`),
  KEY `mbs_activity_logs_created_at_index` (`created_at`),
  KEY `mbs_activity_logs_action_type_created_at_index` (`action_type`,`created_at`),
  KEY `mbs_activity_logs_staff_user_id_created_at_index` (`staff_user_id`,`created_at`),
  KEY `mbs_activity_logs_event_id_created_at_index` (`event_id`,`created_at`),
  KEY `mbs_activity_logs_success_created_at_index` (`success`,`created_at`),
  KEY `mbs_activity_logs_requires_review_index` (`requires_review`),
  KEY `mbs_activity_logs_action_type_index` (`action_type`),
  KEY `mbs_activity_logs_action_category_index` (`action_category`),
  KEY `mbs_activity_logs_correlation_id_index` (`correlation_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `migrations` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) NOT NULL,
  `batch` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `newsletter_campaign_recipients` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `campaign_id` bigint(20) unsigned NOT NULL,
  `contact_id` bigint(20) unsigned NOT NULL,
  `status` enum('pending','sent','failed','bounced') NOT NULL DEFAULT 'pending',
  `sent_at` timestamp NULL DEFAULT NULL,
  `opened_at` timestamp NULL DEFAULT NULL,
  `clicked_at` timestamp NULL DEFAULT NULL,
  `open_count` int(11) NOT NULL DEFAULT 0,
  `click_count` int(11) NOT NULL DEFAULT 0,
  `error_message` varchar(255) DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `newsletter_campaign_recipients_campaign_id_contact_id_unique` (`campaign_id`,`contact_id`),
  KEY `newsletter_campaign_recipients_campaign_id_status_index` (`campaign_id`,`status`),
  KEY `newsletter_campaign_recipients_contact_id_campaign_id_index` (`contact_id`,`campaign_id`),
  CONSTRAINT `newsletter_campaign_recipients_campaign_id_foreign` FOREIGN KEY (`campaign_id`) REFERENCES `newsletter_campaigns` (`id`) ON DELETE CASCADE,
  CONSTRAINT `newsletter_campaign_recipients_contact_id_foreign` FOREIGN KEY (`contact_id`) REFERENCES `newsletter_contacts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `newsletter_campaigns` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `template_id` varchar(191) DEFAULT NULL COMMENT 'Template identifier (e.g., welcome, event-announcement)',
  `field_values` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'User-provided field values for the template' CHECK (json_valid(`field_values`)),
  `subject` varchar(255) NOT NULL,
  `preview_text` text DEFAULT NULL,
  `html_content` longtext NOT NULL,
  `text_content` longtext DEFAULT NULL,
  `template_components` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`template_components`)),
  `email_template_id` bigint(20) unsigned DEFAULT NULL,
  `template_data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`template_data`)),
  `audience_type` enum('all','active','new','custom','import_batch') NOT NULL DEFAULT 'all',
  `audience_filters` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`audience_filters`)),
  `target_import_batch_id` varchar(255) DEFAULT NULL,
  `status` enum('draft','scheduled','sending','sent','failed','cancelled') NOT NULL DEFAULT 'draft',
  `scheduled_at` timestamp NULL DEFAULT NULL,
  `started_sending_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `from_name` varchar(255) NOT NULL DEFAULT 'Global Gala',
  `from_email` varchar(255) NOT NULL DEFAULT 'info@showprima.com',
  `reply_to_email` varchar(255) DEFAULT NULL,
  `total_recipients` int(11) NOT NULL DEFAULT 0,
  `sent_count` int(11) NOT NULL DEFAULT 0,
  `failed_count` int(11) NOT NULL DEFAULT 0,
  `opened_count` int(11) NOT NULL DEFAULT 0,
  `clicked_count` int(11) NOT NULL DEFAULT 0,
  `unsubscribed_count` int(11) NOT NULL DEFAULT 0,
  `bounced_count` int(11) NOT NULL DEFAULT 0,
  `complained_count` int(11) NOT NULL DEFAULT 0,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `newsletter_campaigns_email_template_id_foreign` (`email_template_id`),
  KEY `newsletter_campaigns_status_index` (`status`),
  KEY `newsletter_campaigns_scheduled_at_index` (`scheduled_at`),
  KEY `newsletter_campaigns_created_by_index` (`created_by`),
  KEY `newsletter_campaigns_status_scheduled_at_index` (`status`,`scheduled_at`),
  CONSTRAINT `newsletter_campaigns_email_template_id_foreign` FOREIGN KEY (`email_template_id`) REFERENCES `email_templates` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `newsletter_subscription_history` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `contact_id` bigint(20) unsigned NOT NULL,
  `action` enum('subscribed','unsubscribed','resubscribed','bounced','complained') NOT NULL,
  `reason` varchar(255) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` varchar(255) DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `newsletter_subscription_history_contact_id_action_index` (`contact_id`,`action`),
  KEY `newsletter_subscription_history_created_at_index` (`created_at`),
  KEY `newsletter_subscription_history_action_index` (`action`),
  CONSTRAINT `newsletter_subscription_history_contact_id_foreign` FOREIGN KEY (`contact_id`) REFERENCES `newsletter_contacts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `newsletter_subscriptions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `contact_id` bigint(20) unsigned NOT NULL,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `subscription_type` enum('newsletter','event_updates','promotional','transactional') NOT NULL DEFAULT 'newsletter',
  `status` enum('active','paused','unsubscribed') NOT NULL DEFAULT 'active',
  `subscribed_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `unsubscribed_at` timestamp NULL DEFAULT NULL,
  `source` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `newsletter_subscriptions_contact_id_subscription_type_unique` (`contact_id`,`subscription_type`),
  KEY `newsletter_subscriptions_contact_id_subscription_type_index` (`contact_id`,`subscription_type`),
  KEY `newsletter_subscriptions_user_id_status_index` (`user_id`,`status`),
  CONSTRAINT `newsletter_subscriptions_contact_id_foreign` FOREIGN KEY (`contact_id`) REFERENCES `newsletter_contacts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `newsletter_subscriptions_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `order_audit_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` varchar(191) NOT NULL,
  `admin_user_id` bigint(20) unsigned NOT NULL,
  `action` varchar(50) NOT NULL,
  `old_value` text DEFAULT NULL,
  `new_value` text DEFAULT NULL,
  `reason` text DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` varchar(191) DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `order_audit_log_order_id_created_at_index` (`order_id`,`created_at`),
  KEY `order_audit_log_admin_user_id_created_at_index` (`admin_user_id`,`created_at`),
  KEY `order_audit_log_action_index` (`action`),
  KEY `order_audit_log_order_id_index` (`order_id`),
  CONSTRAINT `order_audit_log_admin_user_id_foreign` FOREIGN KEY (`admin_user_id`) REFERENCES `admins` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `order_items` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) NOT NULL,
  `event_id` bigint(20) NOT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `amount` decimal(10,2) NOT NULL,
  `seat` varchar(255) NOT NULL,
  `zone` varchar(255) DEFAULT NULL,
  `ticket_id` varchar(255) NOT NULL,
  `sub_cat` varchar(255) DEFAULT NULL,
  `category` varchar(255) DEFAULT NULL,
  `quantity` int(11) NOT NULL DEFAULT 1,
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `pdf_path` varchar(255) DEFAULT NULL,
  `pdf_generation_status` enum('pending','processing','ready','failed') NOT NULL DEFAULT 'pending',
  `pdf_generation_error` text DEFAULT NULL,
  `pdf_generated_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `order_items_event_id_seat_status_index` (`event_id`,`seat`,`status`),
  KEY `order_items_order_id_index` (`order_id`),
  KEY `order_items_user_id_index` (`user_id`),
  KEY `order_items_pdf_generation_status_index` (`pdf_generation_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `order_notes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) unsigned NOT NULL,
  `admin_id` bigint(20) unsigned NOT NULL,
  `note` text NOT NULL,
  `is_internal` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Internal staff notes vs customer-visible notes',
  `is_edited` tinyint(1) NOT NULL DEFAULT 0,
  `edited_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `order_notes_order_id_created_at_index` (`order_id`,`created_at`),
  KEY `order_notes_admin_id_index` (`admin_id`),
  CONSTRAINT `order_notes_admin_id_foreign` FOREIGN KEY (`admin_id`) REFERENCES `admins` (`id`),
  CONSTRAINT `order_notes_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `order_refunds` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) unsigned NOT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `refund_amount` decimal(10,2) NOT NULL,
  `refund_type` enum('full','partial') NOT NULL DEFAULT 'full',
  `refund_reason` text DEFAULT NULL,
  `payment_gateway` varchar(50) DEFAULT NULL,
  `gateway_refund_id` varchar(255) DEFAULT NULL,
  `gateway_response` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`gateway_response`)),
  `status` enum('pending','processing','completed','failed','cancelled') NOT NULL DEFAULT 'pending',
  `processed_by` bigint(20) unsigned DEFAULT NULL,
  `processed_at` timestamp NULL DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `order_refunds_event_id_foreign` (`event_id`),
  KEY `order_refunds_processed_by_foreign` (`processed_by`),
  KEY `order_refunds_order_id_status_index` (`order_id`,`status`),
  KEY `order_refunds_gateway_refund_id_index` (`gateway_refund_id`),
  KEY `order_refunds_created_at_index` (`created_at`),
  CONSTRAINT `order_refunds_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE SET NULL,
  CONSTRAINT `order_refunds_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  CONSTRAINT `order_refunds_processed_by_foreign` FOREIGN KEY (`processed_by`) REFERENCES `admins` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `order_status_audit_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) unsigned NOT NULL,
  `old_status` varchar(50) DEFAULT NULL,
  `new_status` varchar(50) NOT NULL,
  `changed_by_type` varchar(50) NOT NULL DEFAULT 'system',
  `changed_by_id` bigint(20) unsigned DEFAULT NULL,
  `trigger_source` varchar(100) DEFAULT NULL,
  `trigger_event_id` varchar(255) DEFAULT NULL,
  `reason` text DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `changed_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_audit_order_id` (`order_id`),
  KEY `idx_audit_new_status` (`new_status`),
  KEY `idx_audit_changed_at` (`changed_at`),
  KEY `idx_audit_order_timeline` (`order_id`,`changed_at`),
  CONSTRAINT `order_status_audit_logs_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ownership_transfer_requests` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ticket_id` varchar(191) NOT NULL,
  `order_id` bigint(20) unsigned NOT NULL,
  `event_id` bigint(20) unsigned NOT NULL,
  `current_owner_name` varchar(191) NOT NULL,
  `current_owner_email` varchar(191) NOT NULL,
  `new_owner_name` varchar(191) NOT NULL,
  `new_owner_email` varchar(191) NOT NULL,
  `reason` text NOT NULL,
  `status` enum('pending','approved','rejected','completed','cancelled') NOT NULL DEFAULT 'pending',
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `rejection_reason` text DEFAULT NULL,
  `seat_number` varchar(50) DEFAULT NULL,
  `event_name` varchar(191) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ownership_transfer_requests_reviewed_by_foreign` (`reviewed_by`),
  KEY `ownership_transfer_requests_ticket_id_index` (`ticket_id`),
  KEY `ownership_transfer_requests_order_id_index` (`order_id`),
  KEY `ownership_transfer_requests_event_id_index` (`event_id`),
  KEY `ownership_transfer_requests_current_owner_email_index` (`current_owner_email`),
  KEY `ownership_transfer_requests_new_owner_email_index` (`new_owner_email`),
  KEY `ownership_transfer_requests_status_index` (`status`),
  CONSTRAINT `ownership_transfer_requests_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE,
  CONSTRAINT `ownership_transfer_requests_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  CONSTRAINT `ownership_transfer_requests_reviewed_by_foreign` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `payment_audit_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `payment_transaction_id` bigint(20) unsigned DEFAULT NULL,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `action` varchar(100) NOT NULL,
  `old_status` varchar(50) DEFAULT NULL,
  `new_status` varchar(50) DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` varchar(500) DEFAULT NULL,
  `source` varchar(100) DEFAULT NULL,
  `trigger_event_id` varchar(255) DEFAULT NULL,
  `action_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_audit_payment_id` (`payment_transaction_id`),
  KEY `idx_audit_order_id` (`order_id`),
  KEY `idx_audit_user_id` (`user_id`),
  KEY `idx_audit_action` (`action`),
  KEY `idx_audit_new_status` (`new_status`),
  KEY `idx_audit_action_at` (`action_at`),
  KEY `idx_audit_payment_timeline` (`payment_transaction_id`,`action_at`),
  KEY `idx_audit_order_timeline` (`order_id`,`action_at`),
  CONSTRAINT `payment_audit_logs_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  CONSTRAINT `payment_audit_logs_payment_transaction_id_foreign` FOREIGN KEY (`payment_transaction_id`) REFERENCES `payment_transactions` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `payment_reconciliations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `reconciliation_date` date NOT NULL COMMENT 'Date being reconciled',
  `payment_gateway` varchar(50) NOT NULL COMMENT 'Payment gateway (stripe, paypal, etc.)',
  `total_database_transactions` int(11) NOT NULL DEFAULT 0 COMMENT 'Total transactions in database',
  `total_database_amount` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'Total amount in database',
  `total_gateway_transactions` int(11) NOT NULL DEFAULT 0 COMMENT 'Total transactions reported by gateway',
  `total_gateway_amount` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'Total amount reported by gateway',
  `transaction_count_difference` int(11) NOT NULL DEFAULT 0 COMMENT 'Difference in transaction counts',
  `amount_difference` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'Difference in amounts (database - gateway)',
  `discrepancies_found` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Whether discrepancies were found',
  `discrepancies_details` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'JSON array of specific discrepancies' CHECK (json_valid(`discrepancies_details`)),
  `status` enum('pending','processing','completed','failed','requires_review') NOT NULL DEFAULT 'pending',
  `report_file_path` varchar(255) DEFAULT NULL COMMENT 'Path to exported reconciliation report',
  `processed_by` bigint(20) unsigned DEFAULT NULL COMMENT 'User ID who processed',
  `processed_at` timestamp NULL DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `payment_reconciliations_reconciliation_date_index` (`reconciliation_date`),
  KEY `payment_reconciliations_payment_gateway_index` (`payment_gateway`),
  KEY `payment_reconciliations_status_index` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `payment_transactions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) unsigned NOT NULL,
  `payment_gateway` enum('stripe','paypal','revolut','cash','bank_transfer','comp') DEFAULT NULL COMMENT 'Payment gateway used',
  `transaction_id` varchar(255) NOT NULL COMMENT 'External payment gateway transaction ID',
  `amount` decimal(10,2) NOT NULL COMMENT 'Transaction amount',
  `currency` varchar(3) NOT NULL DEFAULT 'EUR' COMMENT 'ISO 4217 currency code',
  `status` enum('pending','processing','completed','failed','refunded','partially_refunded') NOT NULL DEFAULT 'pending',
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Additional transaction metadata' CHECK (json_valid(`metadata`)),
  `initiated_at` timestamp NULL DEFAULT NULL COMMENT 'When payment was initiated',
  `completed_at` timestamp NULL DEFAULT NULL COMMENT 'When payment completed successfully',
  `failed_at` timestamp NULL DEFAULT NULL COMMENT 'When payment failed',
  `failure_reason` text DEFAULT NULL COMMENT 'Reason for payment failure',
  `webhook_received_at` timestamp NULL DEFAULT NULL COMMENT 'When webhook notification was received',
  `refund_id` varchar(255) DEFAULT NULL COMMENT 'External refund transaction ID',
  `refunded_at` timestamp NULL DEFAULT NULL COMMENT 'When refund was processed',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `data_retention_until` timestamp NULL DEFAULT NULL COMMENT 'Date when this record should be anonymized/deleted per GDPR',
  `is_anonymized` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Whether personal data has been anonymized',
  `anonymized_at` timestamp NULL DEFAULT NULL COMMENT 'When the record was anonymized',
  `anonymized_reason` varchar(255) DEFAULT NULL COMMENT 'Reason for anonymization (e.g., retention_policy, user_request)',
  PRIMARY KEY (`id`),
  UNIQUE KEY `payment_transactions_transaction_id_unique` (`transaction_id`),
  KEY `payment_transactions_order_id_index` (`order_id`),
  KEY `payment_transactions_payment_gateway_index` (`payment_gateway`),
  KEY `payment_transactions_status_index` (`status`),
  KEY `payment_transactions_transaction_id_index` (`transaction_id`),
  KEY `payment_transactions_initiated_at_index` (`initiated_at`),
  KEY `payment_transactions_data_retention_until_index` (`data_retention_until`),
  KEY `payment_transactions_is_anonymized_data_retention_until_index` (`is_anonymized`,`data_retention_until`),
  CONSTRAINT `payment_transactions_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `permissions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `admin_id` int(11) DEFAULT NULL,
  `value` varchar(250) DEFAULT NULL,
  `parent` varchar(250) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `photos` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `file_name` varchar(100) NOT NULL,
  `user_id` bigint(20) unsigned NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `photos_user_id_foreign` (`user_id`),
  CONSTRAINT `photos_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `posts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(50) NOT NULL COMMENT 'News/Announcement/Notification',
  `title` varchar(500) NOT NULL,
  `image` varchar(255) NOT NULL DEFAULT 'sample-blog.png',
  `body` text NOT NULL,
  `footer` varchar(500) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `price_tiers` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `venue_template_id` bigint(20) unsigned NOT NULL,
  `color` varchar(50) NOT NULL,
  `price` decimal(10,2) NOT NULL,
  `seat_prefix` varchar(20) DEFAULT NULL COMMENT 'Optional prefix for seat names (e.g., VIP, BOOTH, VVIP)',
  `display_order` int(11) NOT NULL DEFAULT 0,
  `display_in_legend` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_tier` (`venue_template_id`,`color`),
  KEY `idx_venue_template` (`venue_template_id`),
  CONSTRAINT `price_tiers_venue_template_id_foreign` FOREIGN KEY (`venue_template_id`) REFERENCES `venue_templates` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `qr_validations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ticket_id` bigint(20) unsigned NOT NULL,
  `scanned_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `scanner_device` varchar(100) DEFAULT NULL,
  `location` varchar(100) DEFAULT NULL,
  `is_valid` tinyint(1) NOT NULL,
  `validation_result` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`validation_result`)),
  PRIMARY KEY (`id`),
  KEY `idx_ticket_scanned` (`ticket_id`,`scanned_at`),
  KEY `qr_validations_is_valid_index` (`is_valid`),
  CONSTRAINT `qr_validations_ticket_id_foreign` FOREIGN KEY (`ticket_id`) REFERENCES `tickets` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `queue_merge_acts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `act1` bigint(20) unsigned NOT NULL,
  `act2` bigint(20) unsigned NOT NULL,
  `new_act_name` varchar(255) NOT NULL,
  `new_act_slug` varchar(255) NOT NULL,
  `status` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `queue_monitor` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `job_id` varchar(255) DEFAULT NULL,
  `job_name` varchar(255) NOT NULL,
  `queue` varchar(255) DEFAULT NULL,
  `status` enum('pending','running','completed','failed','retrying') NOT NULL,
  `attempts` int(11) NOT NULL DEFAULT 0,
  `max_retries` int(11) NOT NULL DEFAULT 3,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`payload`)),
  `exception` longtext DEFAULT NULL,
  `exception_message` text DEFAULT NULL,
  `started_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `failed_at` timestamp NULL DEFAULT NULL,
  `execution_time_ms` int(11) DEFAULT NULL,
  `memory_peak` int(11) DEFAULT NULL,
  `retry_at` timestamp NULL DEFAULT NULL,
  `retry_delay_seconds` int(11) DEFAULT NULL,
  `retry_strategy` enum('fixed','exponential','custom') NOT NULL DEFAULT 'exponential',
  `alert_sent` tinyint(1) NOT NULL DEFAULT 0,
  `alert_sent_at` timestamp NULL DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `correlation_id` varchar(255) DEFAULT NULL,
  `batch_id` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `queue_monitor_job_id_index` (`job_id`),
  KEY `queue_monitor_job_name_index` (`job_name`),
  KEY `queue_monitor_queue_index` (`queue`),
  KEY `queue_monitor_status_index` (`status`),
  KEY `queue_monitor_created_at_index` (`created_at`),
  KEY `queue_monitor_failed_at_index` (`failed_at`),
  KEY `queue_monitor_status_queue_index` (`status`,`queue`),
  KEY `queue_monitor_job_name_status_index` (`job_name`,`status`),
  KEY `queue_monitor_correlation_id_index` (`correlation_id`),
  KEY `queue_monitor_batch_id_index` (`batch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `scanner_devices` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `device_uuid` varchar(191) NOT NULL COMMENT 'iOS identifierForVendor (UUID v4 format)',
  `device_name` varchar(255) DEFAULT NULL COMMENT 'Human-readable device name (e.g., "iPhone 12 Pro")',
  `device_info` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Device fingerprinting info (user agent, screen, timezone, etc.)' CHECK (json_valid(`device_info`)),
  `scanner_name` varchar(100) NOT NULL COMMENT 'Human-readable name (e.g., "Gate A Entrance")',
  `nickname` varchar(191) DEFAULT NULL,
  `current_operator` varchar(191) DEFAULT NULL,
  `operator_updated_at` timestamp NULL DEFAULT NULL,
  `operator_history` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`operator_history`)),
  `pin_code_hash` varchar(255) NOT NULL COMMENT 'Bcrypt hash of 4-6 digit PIN (NEVER plain text)',
  `staff_id` bigint(20) unsigned DEFAULT NULL COMMENT 'FK to admins.id (optional staff member assignment)',
  `zone_id` bigint(20) unsigned DEFAULT NULL COMMENT 'FK to scanner_zones.id (nullable for backward compatibility)',
  `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Active status (true=active, false=deactivated)',
  `deactivated_at` timestamp NULL DEFAULT NULL COMMENT 'When device was deactivated',
  `deactivation_reason` varchar(255) DEFAULT NULL COMMENT 'Reason for deactivation (e.g., "Device lost/stolen")',
  `last_used_at` timestamp NULL DEFAULT NULL COMMENT 'Last successful scan (updated on every ticket scan)',
  `first_seen_at` timestamp NULL DEFAULT NULL COMMENT 'When device first logged in to zone',
  `last_seen_at` timestamp NULL DEFAULT NULL COMMENT 'Last activity timestamp (updated on each scan)',
  `total_scans` int(11) NOT NULL DEFAULT 0 COMMENT 'Total number of tickets scanned by this device',
  `is_flagged` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Device flagged for suspicious activity',
  `flag_reason` varchar(255) DEFAULT NULL COMMENT 'Reason for flagging (e.g., "Idle too long", "Suspicious scan rate")',
  `failed_login_attempts` int(11) NOT NULL DEFAULT 0 COMMENT 'Count of failed login attempts (reset on success)',
  `last_failed_login_at` timestamp NULL DEFAULT NULL COMMENT 'Timestamp of last failed login',
  `notes` text DEFAULT NULL COMMENT 'Admin notes about device (e.g., "Main entrance scanner, iPhone 13")',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `scanner_devices_device_uuid_unique` (`device_uuid`),
  KEY `idx_device_uuid` (`device_uuid`),
  KEY `idx_is_active` (`is_active`),
  KEY `idx_staff_id` (`staff_id`),
  KEY `idx_last_used_at` (`last_used_at`),
  KEY `idx_scanner_devices_zone_id` (`zone_id`),
  KEY `idx_scanner_devices_is_flagged` (`is_flagged`),
  KEY `idx_scanner_devices_last_seen_at` (`last_seen_at`),
  CONSTRAINT `fk_scanner_devices_staff_id` FOREIGN KEY (`staff_id`) REFERENCES `admins` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_scanner_devices_zone_id` FOREIGN KEY (`zone_id`) REFERENCES `scanner_zones` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Scanner device registrations for ticket scanning auth';
CREATE TABLE `scanner_zones` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned NOT NULL COMMENT 'FK to events.id',
  `name` varchar(191) NOT NULL COMMENT 'Zone name (e.g., "Main Entrance", "VIP Door")',
  `pin_code` char(6) NOT NULL COMMENT '6-digit PIN code (stored plain for admin display)',
  `permissions` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'Array of permissions (e.g., ["scan:tickets", "scan:vip"])' CHECK (json_valid(`permissions`)),
  `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Zone active status',
  `active_from` timestamp NULL DEFAULT NULL COMMENT 'Zone activation start time',
  `active_until` timestamp NULL DEFAULT NULL COMMENT 'Zone activation end time',
  `pin_rotated_at` timestamp NULL DEFAULT NULL COMMENT 'Last PIN rotation timestamp',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_scanner_zones_event_id` (`event_id`),
  KEY `idx_scanner_zones_event_pin` (`event_id`,`pin_code`),
  KEY `idx_scanner_zones_is_active` (`is_active`),
  CONSTRAINT `fk_scanner_zones_event_id` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Scanner zones for event-based authentication';
CREATE TABLE `seat_reassignments` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_item_id` bigint(20) unsigned NOT NULL COMMENT 'Reference to order_items.id',
  `original_seat_id` varchar(255) NOT NULL COMMENT 'Original seat UUID from seats table',
  `new_seat_id` varchar(255) NOT NULL COMMENT 'New seat UUID from seats table',
  `reason` text NOT NULL COMMENT 'Reason for seat reassignment',
  `status` enum('pending','approved','rejected','cancelled') NOT NULL DEFAULT 'pending' COMMENT 'Reassignment approval status',
  `reassigned_by` bigint(20) unsigned NOT NULL COMMENT 'Admin ID who initiated reassignment',
  `reassigned_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'When reassignment was initiated',
  `approved_by` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin ID who approved/rejected',
  `approved_at` timestamp NULL DEFAULT NULL COMMENT 'When reassignment was approved/rejected',
  `approval_notes` text DEFAULT NULL COMMENT 'Notes from approver',
  `customer_notified` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Whether customer was notified',
  `customer_notified_at` timestamp NULL DEFAULT NULL COMMENT 'When customer was notified',
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Additional JSON metadata' CHECK (json_valid(`metadata`)),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `seat_reassignments_order_item_id_index` (`order_item_id`),
  KEY `seat_reassignments_original_seat_id_index` (`original_seat_id`),
  KEY `seat_reassignments_new_seat_id_index` (`new_seat_id`),
  KEY `seat_reassignments_status_index` (`status`),
  KEY `seat_reassignments_reassigned_by_index` (`reassigned_by`),
  KEY `seat_reassignments_approved_by_index` (`approved_by`),
  KEY `seat_reassignments_reassigned_at_index` (`reassigned_at`),
  KEY `seat_reassignments_status_reassigned_at_index` (`status`,`reassigned_at`),
  KEY `seat_reassignments_order_item_id_status_index` (`order_item_id`,`status`),
  CONSTRAINT `seat_reassignments_order_item_id_foreign` FOREIGN KEY (`order_item_id`) REFERENCES `order_items` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `seats` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `seat_id` varchar(255) NOT NULL,
  `parent_table_id` varchar(255) DEFAULT NULL,
  `event_id` bigint(20) unsigned NOT NULL,
  `row_letter` varchar(10) NOT NULL,
  `seat_number` varchar(10) NOT NULL,
  `seat_type` enum('individual','table','table_child') NOT NULL DEFAULT 'individual',
  `price` decimal(10,2) NOT NULL,
  `price_tier_id` bigint(20) unsigned DEFAULT NULL,
  `price_assigned_from_tier` decimal(10,2) DEFAULT NULL,
  `zone` varchar(50) NOT NULL,
  `parametric` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`parametric`)),
  `child_seats` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`child_seats`)),
  `position` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`position`)),
  `section_id` varchar(255) DEFAULT NULL,
  `is_accessible` tinyint(1) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `blocked_reason` varchar(255) DEFAULT NULL,
  `blocked_until` timestamp NULL DEFAULT NULL,
  `total_tables` int(11) NOT NULL DEFAULT 0,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `seats_event_id_seat_id_unique` (`event_id`,`seat_id`),
  UNIQUE KEY `seats_event_seat_unique` (`event_id`,`seat_id`),
  KEY `seats_event_id_is_active_index` (`event_id`,`is_active`),
  KEY `seats_seat_id_index` (`seat_id`),
  KEY `seats_event_id_index` (`event_id`),
  KEY `seats_event_id_seat_type_index` (`event_id`,`seat_type`),
  KEY `seats_event_id_section_id_index` (`event_id`,`section_id`),
  KEY `seats_parent_table_id_seat_type_index` (`parent_table_id`,`seat_type`),
  KEY `seats_parent_table_id_index` (`parent_table_id`),
  KEY `seats_section_id_index` (`section_id`),
  KEY `idx_seats_price` (`price`),
  KEY `idx_seats_event_price` (`event_id`,`price`),
  KEY `idx_price_tier` (`price_tier_id`),
  CONSTRAINT `seats_price_tier_id_foreign` FOREIGN KEY (`price_tier_id`) REFERENCES `price_tiers` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `special_messages` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `block` varchar(25) NOT NULL,
  `content` varchar(1000) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `stripe_webhook_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` varchar(255) NOT NULL,
  `event_type` varchar(255) NOT NULL,
  `payload` longtext NOT NULL,
  `received_at` timestamp NULL DEFAULT NULL,
  `processed_at` timestamp NULL DEFAULT NULL,
  `processing_result` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stripe_webhook_events_event_id_unique` (`event_id`),
  KEY `stripe_webhook_events_event_id_index` (`event_id`),
  KEY `stripe_webhook_events_event_type_index` (`event_type`),
  KEY `stripe_webhook_events_received_at_index` (`received_at`),
  KEY `stripe_webhook_events_processed_at_index` (`processed_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `support_conversation_labels` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `conversation_id` bigint(20) unsigned NOT NULL,
  `label_id` bigint(20) unsigned NOT NULL,
  `added_by_admin_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin who added this label',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_conversation_label` (`conversation_id`,`label_id`),
  KEY `support_conversation_labels_added_by_admin_id_foreign` (`added_by_admin_id`),
  KEY `support_conversation_labels_label_id_index` (`label_id`),
  CONSTRAINT `support_conversation_labels_added_by_admin_id_foreign` FOREIGN KEY (`added_by_admin_id`) REFERENCES `admins` (`id`) ON DELETE SET NULL,
  CONSTRAINT `support_conversation_labels_conversation_id_foreign` FOREIGN KEY (`conversation_id`) REFERENCES `support_conversations` (`id`) ON DELETE CASCADE,
  CONSTRAINT `support_conversation_labels_label_id_foreign` FOREIGN KEY (`label_id`) REFERENCES `support_labels` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `support_conversations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `customer_phone` varchar(20) NOT NULL,
  `subject` varchar(191) DEFAULT NULL,
  `status` enum('open','closed','pending') NOT NULL DEFAULT 'open',
  `last_customer_message_at` timestamp NULL DEFAULT NULL COMMENT 'Last message from customer',
  `last_agent_message_at` timestamp NULL DEFAULT NULL COMMENT 'Last message from agent',
  `window_expires_at` timestamp NULL DEFAULT NULL COMMENT '24-hour window expiry',
  `is_window_active` tinyint(1) NOT NULL DEFAULT 1,
  `version` int(11) NOT NULL DEFAULT 1 COMMENT 'Optimistic locking version',
  `assigned_admin_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin currently assigned to this conversation',
  `last_reply_admin_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin who last replied to this conversation',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `active_windows` (`is_window_active`,`window_expires_at`),
  KEY `support_conversations_order_id_index` (`order_id`),
  KEY `support_conversations_customer_phone_index` (`customer_phone`),
  KEY `support_conversations_status_index` (`status`),
  KEY `support_conversations_is_window_active_index` (`is_window_active`),
  KEY `support_conversations_last_reply_admin_id_foreign` (`last_reply_admin_id`),
  KEY `support_conversations_assigned_admin_id_index` (`assigned_admin_id`),
  CONSTRAINT `support_conversations_assigned_admin_id_foreign` FOREIGN KEY (`assigned_admin_id`) REFERENCES `admins` (`id`) ON DELETE SET NULL,
  CONSTRAINT `support_conversations_last_reply_admin_id_foreign` FOREIGN KEY (`last_reply_admin_id`) REFERENCES `admins` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `support_labels` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL COMMENT 'Machine-readable name, e.g., "vip"',
  `display_name` varchar(100) NOT NULL COMMENT 'Human-readable name, e.g., "VIP Customer"',
  `color` varchar(7) NOT NULL COMMENT 'Hex color code, e.g., "#FFD700"',
  `description` varchar(255) DEFAULT NULL COMMENT 'Optional description of the label',
  `sort_order` int(11) NOT NULL DEFAULT 0 COMMENT 'Display order in UI',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `support_labels_name_unique` (`name`),
  KEY `support_labels_sort_order_index` (`sort_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `teams` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `telescope_entries` (
  `sequence` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` char(36) NOT NULL,
  `batch_id` char(36) NOT NULL,
  `family_hash` varchar(191) DEFAULT NULL,
  `should_display_on_index` tinyint(1) NOT NULL DEFAULT 1,
  `type` varchar(20) NOT NULL,
  `content` longtext NOT NULL,
  `created_at` datetime DEFAULT NULL,
  PRIMARY KEY (`sequence`),
  UNIQUE KEY `telescope_entries_uuid_unique` (`uuid`),
  KEY `telescope_entries_batch_id_index` (`batch_id`),
  KEY `telescope_entries_family_hash_index` (`family_hash`),
  KEY `telescope_entries_created_at_index` (`created_at`),
  KEY `telescope_entries_type_should_display_on_index_index` (`type`,`should_display_on_index`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `telescope_entries_tags` (
  `entry_uuid` char(36) NOT NULL,
  `tag` varchar(191) NOT NULL,
  PRIMARY KEY (`entry_uuid`,`tag`),
  KEY `telescope_entries_tags_tag_index` (`tag`),
  CONSTRAINT `telescope_entries_tags_entry_uuid_foreign` FOREIGN KEY (`entry_uuid`) REFERENCES `telescope_entries` (`uuid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `telescope_monitoring` (
  `tag` varchar(191) NOT NULL,
  PRIMARY KEY (`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_booking` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `booking_id` varchar(255) NOT NULL,
  `cust_name` varchar(255) NOT NULL,
  `cust_email` varchar(255) NOT NULL,
  `cust_phone` varchar(255) NOT NULL,
  `billing_address` text NOT NULL,
  `event_id` bigint(20) unsigned NOT NULL,
  `tuids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`tuids`)),
  `total_amount` double(8,2) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'allow only 0 / 1 for pending and paid',
  `ticket_document` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ticket_booking_booking_id_unique` (`booking_id`),
  KEY `ticket_booking_event_id_foreign` (`event_id`),
  CONSTRAINT `ticket_booking_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_categories` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_download_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ticket_id` varchar(255) DEFAULT NULL,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `ip_address` varchar(45) NOT NULL,
  `user_agent` text DEFAULT NULL,
  `status` enum('attempted','success','unauthorized','failed') NOT NULL,
  `download_method` enum('direct','temporary_url') DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ticket_download_logs_ticket_id_index` (`ticket_id`),
  KEY `ticket_download_logs_order_id_index` (`order_id`),
  KEY `ticket_download_logs_user_id_index` (`user_id`),
  KEY `ticket_download_logs_status_index` (`status`),
  KEY `ticket_download_logs_created_at_index` (`created_at`),
  KEY `ticket_download_logs_ticket_id_status_index` (`ticket_id`,`status`),
  KEY `ticket_download_logs_user_id_created_at_index` (`user_id`,`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_generation_batches` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` char(36) NOT NULL,
  `name` varchar(255) NOT NULL,
  `status` enum('initializing','processing','completed','failed','cancelled') NOT NULL DEFAULT 'initializing',
  `priority` enum('normal','high') NOT NULL DEFAULT 'normal',
  `template_type` varchar(255) NOT NULL DEFAULT 'standard',
  `total_orders` int(11) NOT NULL DEFAULT 0,
  `valid_orders` int(11) NOT NULL DEFAULT 0,
  `total_tickets` int(11) NOT NULL DEFAULT 0,
  `completed_tickets` int(11) NOT NULL DEFAULT 0,
  `failed_tickets` int(11) NOT NULL DEFAULT 0,
  `progress_percentage` decimal(5,2) NOT NULL DEFAULT 0.00,
  `started_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `cancelled_at` timestamp NULL DEFAULT NULL,
  `include_email` tinyint(1) NOT NULL DEFAULT 0,
  `webhook_url` varchar(255) DEFAULT NULL,
  `invalid_orders` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`invalid_orders`)),
  `errors` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`errors`)),
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ticket_generation_batches_batch_id_unique` (`batch_id`),
  KEY `ticket_generation_batches_batch_id_index` (`batch_id`),
  KEY `ticket_generation_batches_status_index` (`status`),
  KEY `ticket_generation_batches_priority_index` (`priority`),
  KEY `ticket_generation_batches_created_at_index` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_price` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned NOT NULL,
  `date` date NOT NULL,
  `level` varchar(255) NOT NULL,
  `price` double(8,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ticket_price_event_id_foreign` (`event_id`),
  CONSTRAINT `ticket_price_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_reissuances` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ticket_id` bigint(20) unsigned NOT NULL,
  `reason` varchar(255) NOT NULL,
  `issued_by` bigint(20) unsigned DEFAULT NULL,
  `delivery_method` enum('email','download') NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ticket_reissuances_issued_by_foreign` (`issued_by`),
  KEY `ticket_reissuances_ticket_id_created_at_index` (`ticket_id`,`created_at`),
  CONSTRAINT `ticket_reissuances_issued_by_foreign` FOREIGN KEY (`issued_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `ticket_reissuances_ticket_id_foreign` FOREIGN KEY (`ticket_id`) REFERENCES `tickets` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_security_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_type` varchar(50) NOT NULL,
  `ticket_id` bigint(20) unsigned DEFAULT NULL,
  `details` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`details`)),
  `ip_address` varchar(45) NOT NULL,
  `user_agent` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `ticket_security_events_event_type_index` (`event_type`),
  KEY `ticket_security_events_ticket_id_index` (`ticket_id`),
  KEY `ticket_security_events_created_at_index` (`created_at`),
  KEY `ticket_security_events_event_type_created_at_index` (`event_type`,`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_templates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `type` enum('standard','vip','wristband','digital') NOT NULL,
  `html_template` longtext NOT NULL,
  `css_styles` longtext NOT NULL,
  `dimensions` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`dimensions`)),
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `version` int(11) NOT NULL DEFAULT 1,
  `accessibility_compliant` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ticket_templates_type_is_active_index` (`type`,`is_active`),
  KEY `ticket_templates_version_index` (`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_url_access_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ticket_id` bigint(20) unsigned NOT NULL,
  `token_jti` varchar(255) DEFAULT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `accessed_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `ip_address` varchar(45) NOT NULL,
  `user_agent` text DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  PRIMARY KEY (`id`),
  KEY `ticket_url_access_logs_ticket_id_index` (`ticket_id`),
  KEY `ticket_url_access_logs_token_jti_index` (`token_jti`),
  KEY `ticket_url_access_logs_event_id_index` (`event_id`),
  KEY `ticket_url_access_logs_order_id_index` (`order_id`),
  KEY `ticket_url_access_logs_accessed_at_index` (`accessed_at`),
  KEY `ticket_url_access_logs_ticket_id_accessed_at_index` (`ticket_id`,`accessed_at`),
  KEY `ticket_url_access_logs_ip_address_accessed_at_index` (`ip_address`,`accessed_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_url_generation_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ticket_id` bigint(20) unsigned NOT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `generated_by` bigint(20) unsigned DEFAULT NULL,
  `expiry_minutes` int(11) NOT NULL,
  `access_limit` int(11) DEFAULT NULL,
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `generated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `ip_address` varchar(45) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `ticket_url_generation_logs_ticket_id_index` (`ticket_id`),
  KEY `ticket_url_generation_logs_generated_by_index` (`generated_by`),
  KEY `ticket_url_generation_logs_generated_at_index` (`generated_at`),
  KEY `ticket_url_generation_logs_ticket_id_generated_at_index` (`ticket_id`,`generated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_validations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ticket_id` bigint(20) unsigned NOT NULL,
  `line_item_id` bigint(20) unsigned DEFAULT NULL,
  `tuid` varchar(255) NOT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `validation_code` varchar(255) NOT NULL,
  `status` enum('valid','invalid','duplicate','expired','tampered','already_scanned','not_found','revoked') NOT NULL DEFAULT 'valid',
  `scan_type` enum('entry','exit') DEFAULT NULL COMMENT 'Type of scan: entry (IN) or exit (OUT)',
  `zone_id` bigint(20) unsigned DEFAULT NULL,
  `zone_name` varchar(255) DEFAULT NULL COMMENT 'Denormalized: zone name at scan time',
  `operator_name` varchar(255) DEFAULT NULL COMMENT 'Denormalized: operator name at scan time',
  `device_nickname` varchar(255) DEFAULT NULL COMMENT 'Denormalized: device nickname at scan time',
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `customer_name` varchar(255) DEFAULT NULL COMMENT 'Denormalized: customer name at scan time',
  `customer_email` varchar(255) DEFAULT NULL COMMENT 'Denormalized: customer email at scan time',
  `seat_number` varchar(50) DEFAULT NULL COMMENT 'Denormalized: seat number at scan time',
  `ticket_type` varchar(50) DEFAULT NULL COMMENT 'Denormalized: ticket type (standard, vip, comp, etc.)',
  `scanner_id` varchar(255) DEFAULT NULL,
  `scanner_location` varchar(255) DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` varchar(255) DEFAULT NULL,
  `qr_data` text DEFAULT NULL,
  `signature_hash` varchar(255) DEFAULT NULL,
  `signature_valid` tinyint(1) NOT NULL DEFAULT 0,
  `validation_errors` text DEFAULT NULL,
  `validated_at` datetime NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `idempotency_key` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_idempotency_key` (`idempotency_key`),
  KEY `ticket_validations_ticket_id_index` (`ticket_id`),
  KEY `ticket_validations_tuid_index` (`tuid`),
  KEY `ticket_validations_event_id_index` (`event_id`),
  KEY `ticket_validations_validation_code_index` (`validation_code`),
  KEY `ticket_validations_validated_at_index` (`validated_at`),
  KEY `ticket_validations_status_index` (`status`),
  KEY `ticket_validations_line_item_id_index` (`line_item_id`),
  KEY `idx_validation_scan_lookup` (`validation_code`,`scan_type`,`status`),
  KEY `idx_validation_code` (`validation_code`),
  KEY `idx_tv_scan_type` (`scan_type`),
  KEY `idx_tv_zone_id` (`zone_id`),
  KEY `idx_tv_operator_name` (`operator_name`),
  KEY `idx_tv_order_id` (`order_id`),
  KEY `idx_tv_customer_email` (`customer_email`),
  KEY `idx_tv_seat_number` (`seat_number`),
  KEY `idx_tv_event_scan_time` (`event_id`,`scan_type`,`validated_at`),
  KEY `idx_tv_event_zone_time` (`event_id`,`zone_id`,`validated_at`),
  KEY `idx_tv_event_operator_time` (`event_id`,`operator_name`,`validated_at`),
  CONSTRAINT `ticket_validations_line_item_id_foreign` FOREIGN KEY (`line_item_id`) REFERENCES `order_line_items` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket_wise_prices` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned NOT NULL,
  `ticket_category_id` bigint(20) unsigned NOT NULL,
  `per_ticket_price` bigint(20) unsigned NOT NULL,
  `ticket_quantity` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `tickets` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned NOT NULL,
  `booking_id` varchar(255) NOT NULL,
  `tuid` varchar(255) NOT NULL,
  `status` enum('pending','processing','ready','generation_failed') NOT NULL DEFAULT 'pending',
  `ticket_status` enum('active','blocked','barred','revoked','transferred','cancelled') NOT NULL DEFAULT 'active',
  `is_blocked` tinyint(1) NOT NULL DEFAULT 0,
  `is_barred` tinyint(1) NOT NULL DEFAULT 0,
  `denial_reason` varchar(255) DEFAULT NULL,
  `blocked_at` timestamp NULL DEFAULT NULL,
  `barred_by` bigint(20) unsigned DEFAULT NULL,
  `barred_at` timestamp NULL DEFAULT NULL,
  `security_alerts_count` int(11) NOT NULL DEFAULT 0,
  `last_security_alert_at` timestamp NULL DEFAULT NULL,
  `blocked_by` bigint(20) unsigned DEFAULT NULL,
  `blocked_reason` text DEFAULT NULL,
  `unblocked_at` timestamp NULL DEFAULT NULL,
  `unblocked_by` bigint(20) unsigned DEFAULT NULL,
  `ticket_type` enum('individual','party','group') NOT NULL DEFAULT 'individual' COMMENT 'Type of ticket: individual, party (child of a party ticket), or group',
  `parent_ticket_id` bigint(20) unsigned DEFAULT NULL COMMENT 'For party tickets, reference to the parent ticket',
  `party_name` varchar(255) DEFAULT NULL COMMENT 'Name for party/group bookings',
  `party_size` int(10) unsigned DEFAULT NULL COMMENT 'Number of people in party/group booking',
  `used_at` datetime DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  `pdf_path` varchar(255) DEFAULT NULL,
  `pdf_generated_at` timestamp NULL DEFAULT NULL,
  `template_version` int(11) NOT NULL DEFAULT 1,
  `reissued_at` timestamp NULL DEFAULT NULL,
  `reissued_by` varchar(255) DEFAULT NULL,
  `reissue_reason` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tickets_booking_id_unique` (`booking_id`),
  KEY `tickets_reissued_at_index` (`reissued_at`),
  KEY `tickets_reissued_by_index` (`reissued_by`),
  KEY `tickets_pdf_generated_at_index` (`pdf_generated_at`),
  KEY `idx_status` (`status`),
  KEY `idx_event_status` (`event_id`,`status`),
  KEY `idx_booking_event` (`booking_id`,`event_id`),
  KEY `idx_used_at` (`used_at`),
  KEY `idx_expires_at` (`expires_at`),
  KEY `idx_ticket_type` (`ticket_type`),
  KEY `idx_parent_ticket` (`parent_ticket_id`),
  KEY `tickets_unblocked_by_foreign` (`unblocked_by`),
  KEY `tickets_blocked_at_index` (`blocked_at`),
  KEY `tickets_blocked_by_index` (`blocked_by`),
  KEY `tickets_unblocked_at_index` (`unblocked_at`),
  KEY `tickets_is_blocked_index` (`is_blocked`),
  KEY `tickets_is_barred_index` (`is_barred`),
  KEY `tickets_is_blocked_is_barred_index` (`is_blocked`,`is_barred`),
  KEY `blocked_at_index` (`blocked_at`),
  CONSTRAINT `tickets_blocked_by_foreign` FOREIGN KEY (`blocked_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `tickets_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`),
  CONSTRAINT `tickets_parent_ticket_id_foreign` FOREIGN KEY (`parent_ticket_id`) REFERENCES `tickets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `tickets_unblocked_by_foreign` FOREIGN KEY (`unblocked_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `tshirt_trackings` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `registration_id` bigint(20) unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `user_consents` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `consent_type` varchar(100) NOT NULL,
  `consent_given` tinyint(1) NOT NULL DEFAULT 0,
  `consent_version` varchar(50) NOT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` text DEFAULT NULL,
  `source` varchar(100) DEFAULT NULL,
  `consented_at` timestamp NULL DEFAULT NULL,
  `withdrawn_at` timestamp NULL DEFAULT NULL,
  `expires_at` timestamp NULL DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user_consents_user_id_consent_type_consent_given_index` (`user_id`,`consent_type`,`consent_given`),
  KEY `user_consents_email_consent_type_consent_given_index` (`email`,`consent_type`,`consent_given`),
  KEY `user_consents_user_id_index` (`user_id`),
  KEY `user_consents_email_index` (`email`),
  KEY `user_consents_consent_type_index` (`consent_type`),
  KEY `user_consents_consent_given_index` (`consent_given`),
  KEY `user_consents_consented_at_index` (`consented_at`),
  KEY `user_consents_withdrawn_at_index` (`withdrawn_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `user_groups` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `venue_templates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `venue_id` bigint(20) unsigned DEFAULT NULL,
  `name` varchar(255) NOT NULL DEFAULT 'Venue Template',
  `version` int(11) NOT NULL DEFAULT 1,
  `status` enum('draft','published','archived') NOT NULL DEFAULT 'draft',
  `save_type` enum('manual','auto') NOT NULL DEFAULT 'manual',
  `description` text DEFAULT NULL,
  `author` varchar(255) DEFAULT NULL,
  `template_data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`template_data`)),
  `sections_data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`sections_data`)),
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),
  `total_seats` int(11) NOT NULL DEFAULT 0,
  `total_tables` int(11) NOT NULL DEFAULT 0,
  `total_capacity` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `venue_templates_event_id_is_active_index` (`event_id`,`is_active`),
  KEY `venue_templates_event_id_index` (`event_id`),
  KEY `venue_templates_event_id_version_index` (`event_id`,`version`),
  KEY `venue_templates_event_id_status_index` (`event_id`,`status`),
  KEY `venue_templates_event_id_version_status_index` (`event_id`,`version`,`status`),
  KEY `idx_venue_templates_venue_id` (`venue_id`),
  KEY `idx_venue_templates_venue_active` (`venue_id`,`is_active`),
  KEY `idx_venue_templates_venue_status` (`venue_id`,`status`),
  KEY `idx_venue_templates_venue_version` (`venue_id`,`version`),
  CONSTRAINT `fk_venue_templates_venue_id` FOREIGN KEY (`venue_id`) REFERENCES `venues` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `venue_themes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(191) NOT NULL,
  `theme_id` varchar(191) NOT NULL,
  `description` text DEFAULT NULL,
  `config` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`config`)),
  `is_global` tinyint(1) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `venue_id` bigint(20) unsigned DEFAULT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `author` varchar(191) DEFAULT NULL,
  `version` varchar(20) NOT NULL DEFAULT '1.0.0',
  `mode` varchar(50) NOT NULL DEFAULT 'custom',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `venue_themes_theme_id_unique` (`theme_id`),
  KEY `venue_themes_is_global_is_active_index` (`is_global`,`is_active`),
  KEY `venue_themes_venue_id_is_active_index` (`venue_id`,`is_active`),
  KEY `venue_themes_event_id_is_active_index` (`event_id`,`is_active`),
  KEY `venue_themes_name_index` (`name`),
  KEY `venue_themes_is_global_index` (`is_global`),
  KEY `venue_themes_is_active_index` (`is_active`),
  KEY `venue_themes_venue_id_index` (`venue_id`),
  KEY `venue_themes_event_id_index` (`event_id`),
  KEY `venue_themes_mode_index` (`mode`),
  CONSTRAINT `venue_themes_venue_id_foreign` FOREIGN KEY (`venue_id`) REFERENCES `venues` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `venues` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `default_theme_id` bigint(20) unsigned DEFAULT NULL,
  `name` varchar(255) NOT NULL,
  `address` varchar(255) DEFAULT NULL,
  `street_address` varchar(191) DEFAULT NULL COMMENT 'Street number and name (required for Revolut)',
  `city` varchar(255) DEFAULT NULL,
  `region` varchar(100) DEFAULT NULL COMMENT 'State, province, or region (optional for Revolut)',
  `country` varchar(255) DEFAULT NULL,
  `postal_code` varchar(255) DEFAULT NULL,
  `country_code` char(2) DEFAULT NULL COMMENT 'ISO 3166-1 alpha-2 country code (GB, US, FR, etc.)',
  `description` text DEFAULT NULL,
  `capacity` int(11) DEFAULT NULL,
  `contact_info` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`contact_info`)),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `venues_default_theme_id_foreign` (`default_theme_id`),
  KEY `venues_country_code_index` (`country_code`),
  CONSTRAINT `venues_default_theme_id_foreign` FOREIGN KEY (`default_theme_id`) REFERENCES `venue_themes` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `verified_financial_entries` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `type` enum('bank_transfer','cash','adjustment') NOT NULL COMMENT 'Type of manual entry',
  `status` enum('pending','verified','rejected') NOT NULL DEFAULT 'pending' COMMENT 'Verification status',
  `entry_date` date NOT NULL COMMENT 'Date the payment/entry occurred',
  `amount` decimal(12,2) NOT NULL COMMENT 'Amount in major currency units (e.g., 100.50)',
  `currency` varchar(3) NOT NULL DEFAULT 'GBP' COMMENT 'ISO 4217 currency code',
  `reference` varchar(255) DEFAULT NULL COMMENT 'Bank reference, receipt number, etc.',
  `payer_name` varchar(255) DEFAULT NULL COMMENT 'Name of payer/customer',
  `verified_by` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin who verified/rejected this entry',
  `verified_at` timestamp NULL DEFAULT NULL COMMENT 'When the entry was verified/rejected',
  `notes` text DEFAULT NULL COMMENT 'Free-form notes about this entry',
  `document_path` varchar(500) DEFAULT NULL COMMENT 'Path to supporting document (receipt, bank statement)',
  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Additional structured data' CHECK (json_valid(`metadata`)),
  `created_by` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin who created this entry',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `vfe_event_type_date_idx` (`event_id`,`type`,`entry_date`),
  KEY `vfe_status_date_idx` (`status`,`entry_date`),
  KEY `vfe_date_type_idx` (`entry_date`,`type`),
  KEY `verified_financial_entries_verified_by_foreign` (`verified_by`),
  KEY `verified_financial_entries_created_by_foreign` (`created_by`),
  CONSTRAINT `verified_financial_entries_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `admins` (`id`) ON DELETE SET NULL,
  CONSTRAINT `verified_financial_entries_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE SET NULL,
  CONSTRAINT `verified_financial_entries_verified_by_foreign` FOREIGN KEY (`verified_by`) REFERENCES `admins` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `waitlist_submissions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned NOT NULL,
  `full_name` varchar(191) NOT NULL,
  `email` varchar(191) NOT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `seat_preferences` text DEFAULT NULL COMMENT 'Text description of desired seats (e.g., "Table 5, seats 1-4" or "VIP section")',
  `reason_notes` text DEFAULT NULL COMMENT 'Why they want these seats, special requests',
  `status` enum('pending','contacted','resolved') NOT NULL DEFAULT 'pending' COMMENT 'Admin response status: pending=not contacted, contacted=admin replied, resolved=resolved/closed',
  `contacted_at` timestamp NULL DEFAULT NULL COMMENT 'When admin marked as contacted',
  `contacted_by` bigint(20) unsigned DEFAULT NULL COMMENT 'Admin user who marked as contacted',
  `ip_address` varchar(45) DEFAULT NULL COMMENT 'For spam prevention',
  `user_agent` text DEFAULT NULL COMMENT 'For analytics',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL COMMENT 'Soft deletes for GDPR compliance',
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_email_per_event` (`email`,`event_id`),
  KEY `idx_event_id` (`event_id`),
  KEY `idx_email` (`email`),
  KEY `idx_created_at` (`created_at`),
  KEY `fk_waitlist_contacted_by` (`contacted_by`),
  CONSTRAINT `fk_waitlist_contacted_by` FOREIGN KEY (`contacted_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_waitlist_event` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `webhook_events` (
  `event_id` varchar(255) NOT NULL,
  `event_type` varchar(255) NOT NULL,
  `payment_intent_id` varchar(191) DEFAULT NULL COMMENT 'EDGE-013 FIX: Payment Intent ID for deduplication',
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`payload`)),
  `status` enum('pending','processing','processed','failed') NOT NULL DEFAULT 'pending',
  `error_message` text DEFAULT NULL,
  `retry_count` int(11) NOT NULL DEFAULT 0,
  `received_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `processed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`event_id`),
  KEY `webhook_events_event_type_received_at_index` (`event_type`,`received_at`),
  KEY `webhook_events_status_received_at_index` (`status`,`received_at`),
  KEY `webhook_events_processed_at_index` (`processed_at`),
  KEY `webhook_events_payment_intent_id_index` (`payment_intent_id`),
  KEY `idx_webhook_dedup` (`event_type`(100),`payment_intent_id`(100))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `whats_app_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `conversation_id` bigint(20) unsigned DEFAULT NULL,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `customer_phone` varchar(20) NOT NULL,
  `message_body` text NOT NULL,
  `media_url` varchar(191) DEFAULT NULL,
  `twilio_sid` varchar(191) NOT NULL COMMENT 'Unique Twilio message SID for idempotency',
  `direction` enum('inbound','outbound') NOT NULL,
  `status` varchar(20) NOT NULL DEFAULT 'queued',
  `template_sid` varchar(191) DEFAULT NULL COMMENT 'Twilio Content SID if template used',
  `cost_amount` decimal(10,4) NOT NULL DEFAULT 0.0000 COMMENT 'Message cost from Twilio',
  `cost_currency` varchar(3) NOT NULL DEFAULT 'USD',
  `sent_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `whats_app_logs_twilio_sid_unique` (`twilio_sid`),
  KEY `customer_messages` (`customer_phone`,`created_at`),
  KEY `message_status` (`direction`,`status`),
  KEY `whats_app_logs_conversation_id_index` (`conversation_id`),
  KEY `whats_app_logs_order_id_index` (`order_id`),
  KEY `whats_app_logs_customer_phone_index` (`customer_phone`),
  KEY `whats_app_logs_direction_index` (`direction`),
  KEY `whats_app_logs_status_index` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `whatsapp_cost_tracker` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `period_type` enum('hour','day') NOT NULL COMMENT 'Tracking period: hour or day',
  `period_start` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'Start of tracking period',
  `period_end` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'End of tracking period',
  `message_count` int(11) NOT NULL DEFAULT 0 COMMENT 'Total messages in period',
  `total_cost` decimal(10,4) NOT NULL DEFAULT 0.0000 COMMENT 'Total cost in period (USD)',
  `currency` varchar(3) NOT NULL DEFAULT 'USD',
  `inbound_count` int(11) NOT NULL DEFAULT 0 COMMENT 'Inbound messages',
  `outbound_count` int(11) NOT NULL DEFAULT 0 COMMENT 'Outbound messages',
  `template_count` int(11) NOT NULL DEFAULT 0 COMMENT 'Template messages',
  `circuit_broken` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Circuit breaker tripped flag',
  `circuit_broken_at` timestamp NULL DEFAULT NULL COMMENT 'When circuit breaker tripped',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_period` (`period_type`,`period_start`),
  KEY `period_lookup` (`period_type`,`period_start`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `whatsapp_templates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `template_sid` varchar(191) NOT NULL COMMENT 'Twilio Content SID',
  `template_name` varchar(191) NOT NULL,
  `language` varchar(10) NOT NULL DEFAULT 'en',
  `status` enum('approved','pending','rejected','disabled','paused') NOT NULL DEFAULT 'pending',
  `rejection_reason` text DEFAULT NULL,
  `submitted_at` timestamp NULL DEFAULT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `last_synced_at` timestamp NULL DEFAULT NULL COMMENT 'Last sync from Twilio API',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_template_language` (`template_name`,`language`),
  UNIQUE KEY `whatsapp_templates_template_sid_unique` (`template_sid`),
  KEY `whatsapp_templates_template_name_index` (`template_name`),
  KEY `whatsapp_templates_status_index` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


INSERT INTO `migrations` VALUES (1,'2014_10_12_000000_create_users_table',1);
INSERT INTO `migrations` VALUES (2,'2014_10_12_100000_create_password_resets_table',1);
INSERT INTO `migrations` VALUES (3,'2022_02_15_105028_create_fundraising_profiles_table',1);
INSERT INTO `migrations` VALUES (4,'2022_02_15_112347_create_fundraising_transactions_table',1);
INSERT INTO `migrations` VALUES (5,'2022_03_07_040816_modify_registration_ext',1);
INSERT INTO `migrations` VALUES (6,'2022_03_08_132523_create_photos_table',1);
INSERT INTO `migrations` VALUES (7,'2022_03_08_140817_modify_users',1);
INSERT INTO `migrations` VALUES (8,'2022_03_08_143720_create_faqs_table',1);
INSERT INTO `migrations` VALUES (9,'2022_03_08_163251_create_donation_amounts_table',1);
INSERT INTO `migrations` VALUES (10,'2022_03_15_041018_create_special_messages_table',1);
INSERT INTO `migrations` VALUES (11,'2022_03_16_090802_create_posts_table',1);
INSERT INTO `migrations` VALUES (12,'2022_03_23_081540_create_strava_users_table',1);
INSERT INTO `migrations` VALUES (13,'2022_03_24_061328_create_tshirt_trackings_table',1);
INSERT INTO `migrations` VALUES (14,'2022_03_28_053654_create_user_groups_table',1);
INSERT INTO `migrations` VALUES (15,'2022_04_13_104317_create_teams_table',1);
INSERT INTO `migrations` VALUES (16,'2022_08_24_152513_create_events_table',1);
INSERT INTO `migrations` VALUES (17,'2022_08_24_152536_create_acts_table',1);
INSERT INTO `migrations` VALUES (18,'2022_08_25_073206_create_clubs_table',1);
INSERT INTO `migrations` VALUES (19,'2022_08_25_075649_create_event_photos_table',1);
INSERT INTO `migrations` VALUES (20,'2022_08_25_085350_create_act_sponsor_photos_table',1);
INSERT INTO `migrations` VALUES (21,'2022_08_25_085418_create_ticket_booking_table',1);
INSERT INTO `migrations` VALUES (22,'2022_08_25_122500_create_ticket_price_table',1);
INSERT INTO `migrations` VALUES (23,'2022_08_25_124049_create_tickets_table',1);
INSERT INTO `migrations` VALUES (24,'2022_08_25_140000_create_carts_table',1);
INSERT INTO `migrations` VALUES (25,'2022_08_25_150000_create_permissions_table',1);
INSERT INTO `migrations` VALUES (26,'2022_08_25_160000_create_contents_table',1);
INSERT INTO `migrations` VALUES (27,'2022_08_26_110000_create_blog_categories_table',1);
INSERT INTO `migrations` VALUES (28,'2022_08_26_120000_create_blogs_table',1);
INSERT INTO `migrations` VALUES (29,'2022_08_26_130000_create_banners_table',1);
INSERT INTO `migrations` VALUES (30,'2022_12_02_054841_create_queue_merge_acts_table',1);
INSERT INTO `migrations` VALUES (31,'2023_07_05_172058_create_ticket_categories_table',1);
INSERT INTO `migrations` VALUES (32,'2023_07_05_193358_create_ticket_wise_prices_table',1);
INSERT INTO `migrations` VALUES (33,'2024_09_10_111500_add_unique_constraint_to_carts_table',1);
INSERT INTO `migrations` VALUES (34,'2025_09_09_100000_create_seat_reservations_table',1);
INSERT INTO `migrations` VALUES (35,'2025_09_09_105000_create_seats_table',1);
INSERT INTO `migrations` VALUES (36,'2025_09_09_110000_create_orders_table',1);
INSERT INTO `migrations` VALUES (37,'2025_09_09_120000_add_idempotency_key_to_orders_table',1);
INSERT INTO `migrations` VALUES (38,'2025_09_09_130000_make_user_id_nullable_in_orders_table',1);
INSERT INTO `migrations` VALUES (39,'2025_09_09_153015_create_cache_table',1);
INSERT INTO `migrations` VALUES (40,'2025_09_10_155059_create_order_items_table',1);
INSERT INTO `migrations` VALUES (41,'2025_09_10_155308_create_event_wise_seat_categories_table',1);
INSERT INTO `migrations` VALUES (42,'2025_09_12_225618_add_table_support_to_seats_table',1);
INSERT INTO `migrations` VALUES (43,'2025_09_12_230003_create_venue_templates_table',1);
INSERT INTO `migrations` VALUES (44,'2025_09_17_182524_add_shadow_sold_status_to_seat_reservations_table',1);
INSERT INTO `migrations` VALUES (45,'2025_09_23_140000_add_versioning_to_venue_templates',1);
INSERT INTO `migrations` VALUES (46,'2025_09_23_150000_fix_venue_templates_constraints',1);
INSERT INTO `migrations` VALUES (47,'2025_09_24_174638_create_admin_roles_table',1);
INSERT INTO `migrations` VALUES (48,'2025_09_24_174639_create_admins_table',1);
INSERT INTO `migrations` VALUES (49,'2025_09_24_175742_migrate_mbs_users_to_admin_system',1);
INSERT INTO `migrations` VALUES (50,'2025_09_24_180659_create_email_templates_table',1);
INSERT INTO `migrations` VALUES (51,'2025_09_24_183910_create_content_pages_table',1);
INSERT INTO `migrations` VALUES (52,'2025_09_26_163916_add_selling_period_columns_to_events_table',1);
INSERT INTO `migrations` VALUES (53,'2025_09_29_000000_add_reissue_fields_to_tickets_table',1);
INSERT INTO `migrations` VALUES (54,'2025_09_29_000001_create_email_templates_table',1);
INSERT INTO `migrations` VALUES (55,'2025_09_29_115701_create_ticket_templates_table',1);
INSERT INTO `migrations` VALUES (56,'2025_09_29_123239_add_pdf_tracking_to_tickets_table',1);
INSERT INTO `migrations` VALUES (57,'2025_09_29_123500_create_ticket_reissuances_table',1);
INSERT INTO `migrations` VALUES (58,'2025_09_29_124324_add_ticket_generation_status_to_order_items_table',1);
INSERT INTO `migrations` VALUES (59,'2025_09_29_140000_create_ticket_generation_batches_table',1);
INSERT INTO `migrations` VALUES (60,'2025_09_29_150000_create_ticket_download_logs_table',1);
INSERT INTO `migrations` VALUES (61,'2025_09_29_160000_create_ticket_url_access_logs_table',1);
INSERT INTO `migrations` VALUES (62,'2025_09_29_160001_create_ticket_url_generation_logs_table',1);
INSERT INTO `migrations` VALUES (63,'2025_09_29_160002_create_ticket_security_events_table',1);
INSERT INTO `migrations` VALUES (64,'2025_09_29_163525_create_jobs_table',1);
INSERT INTO `migrations` VALUES (65,'2025_09_29_163527_create_failed_jobs_table',1);
INSERT INTO `migrations` VALUES (66,'2025_09_29_163807_create_batch_jobs_table',1);
INSERT INTO `migrations` VALUES (67,'2025_09_29_170653_create_ticket_validations_table',1);
INSERT INTO `migrations` VALUES (68,'2025_09_29_170912_add_used_at_expires_at_to_tickets_table',1);
INSERT INTO `migrations` VALUES (69,'2025_09_29_172114_create_queue_monitor_table',1);
INSERT INTO `migrations` VALUES (70,'2025_09_29_200000_create_ticket_audit_logs_table',1);
INSERT INTO `migrations` VALUES (71,'2025_09_29_210000_create_qr_validations_table',1);
INSERT INTO `migrations` VALUES (72,'2025_09_29_214724_add_performance_indexes_to_tickets_table',1);
INSERT INTO `migrations` VALUES (73,'2025_10_01_185741_update_users_table_for_generic_accounts',1);
INSERT INTO `migrations` VALUES (75,'2025_10_02_100255_add_customer_data_to_orders_table',2);
INSERT INTO `migrations` VALUES (78,'2025_10_03_132354_add_price_indexes_to_seats_table',3);
INSERT INTO `migrations` VALUES (79,'2025_10_06_123322_create_galleries_table',3);
INSERT INTO `migrations` VALUES (80,'2025_10_06_000000_create_payment_transactions_table',4);
INSERT INTO `migrations` VALUES (81,'2025_10_06_164501_create_order_refunds_table',4);
INSERT INTO `migrations` VALUES (82,'2025_10_06_170147_create_stripe_webhook_events_table',4);
INSERT INTO `migrations` VALUES (83,'2025_10_06_170603_add_revolut_fields_to_orders_table',4);
INSERT INTO `migrations` VALUES (84,'2025_10_06_184106_add_ticket_type_fields_to_tickets_table',4);
INSERT INTO `migrations` VALUES (85,'2025_10_06_184117_add_ticket_status_management_to_tickets_table',4);
INSERT INTO `migrations` VALUES (86,'2025_10_06_184142_add_ticket_status_validation_fields_to_tickets_table',4);
INSERT INTO `migrations` VALUES (87,'2025_10_06_184212_add_blocking_fields_to_tickets_table',4);
INSERT INTO `migrations` VALUES (88,'2025_10_06_184243_add_blocked_status_to_seat_reservations',4);
INSERT INTO `migrations` VALUES (89,'2025_10_06_184306_create_bulk_ticket_status_batches_table',4);
INSERT INTO `migrations` VALUES (90,'2025_10_06_184843_create_seat_reassignments_table',4);
INSERT INTO `migrations` VALUES (91,'2025_10_06_190356_add_unique_constraint_to_seat_id',4);
INSERT INTO `migrations` VALUES (92,'2025_10_06_190357_create_seat_transfer_requests_table',5);
INSERT INTO `migrations` VALUES (93,'2025_10_06_194918_add_profile_fields_to_customers_table',5);
INSERT INTO `migrations` VALUES (94,'2025_10_06_212929_add_granular_statuses_to_orders_table',5);
INSERT INTO `migrations` VALUES (95,'2025_10_06_212954_create_order_modifications_table',5);
INSERT INTO `migrations` VALUES (96,'2025_10_06_213007_create_order_status_audit_logs_table',5);
INSERT INTO `migrations` VALUES (97,'2025_10_06_213324_add_cancelled_status_to_seat_reservations_table',5);
INSERT INTO `migrations` VALUES (98,'2025_10_06_213327_add_cancelled_status_to_tickets_table',5);
INSERT INTO `migrations` VALUES (99,'2025_10_06_224236_create_payment_audit_logs_table',6);
INSERT INTO `migrations` VALUES (100,'2025_10_07_143833_add_stripe_fields_to_orders_table',7);
INSERT INTO `migrations` VALUES (101,'2025_10_07_144937_create_webhook_events_table',8);
INSERT INTO `migrations` VALUES (102,'2025_10_08_121909_create_order_line_items_table',9);
INSERT INTO `migrations` VALUES (103,'2025_10_08_135135_add_stripe_customer_id_to_orders_table',10);
INSERT INTO `migrations` VALUES (104,'2025_10_06_224306_create_payment_reconciliations_table',11);
INSERT INTO `migrations` VALUES (105,'2025_10_06_224348_add_gdpr_fields_to_payment_transactions_and_orders',11);
INSERT INTO `migrations` VALUES (106,'2025_10_06_224418_create_gdpr_audit_logs_table',11);
INSERT INTO `migrations` VALUES (107,'2025_10_08_152651_add_payment_mode_to_orders',12);
INSERT INTO `migrations` VALUES (108,'2025_10_08_152751_add_cash_and_comp_gateways_to_payment_transactions',12);
INSERT INTO `migrations` VALUES (109,'2025_10_08_155245_create_user_consents_table',13);
INSERT INTO `migrations` VALUES (111,'2025_10_09_133231_add_performance_indexes_to_seat_reservations',14);
INSERT INTO `migrations` VALUES (112,'2025_10_09_172052_create_email_accounts_table',15);
INSERT INTO `migrations` VALUES (113,'2025_10_09_172117_create_email_rate_tracking_table',16);
INSERT INTO `migrations` VALUES (114,'2025_10_09_172119_enhance_email_logs_table',17);
INSERT INTO `migrations` VALUES (115,'2025_10_09_172115_create_email_inbox_table',18);
INSERT INTO `migrations` VALUES (116,'2025_10_09_000000_create_mbs_activity_logs_table',19);
INSERT INTO `migrations` VALUES (117,'2025_10_09_150340_create_order_notes_table',19);
INSERT INTO `migrations` VALUES (118,'2025_10_09_180449_create_manager_overrides_table',20);
INSERT INTO `migrations` VALUES (119,'2025_10_09_200000_create_device_tokens_table',20);
INSERT INTO `migrations` VALUES (120,'2025_10_09_200001_create_fire_marshal_tokens_table',20);
INSERT INTO `migrations` VALUES (121,'2025_10_09_184012_add_pin_to_users_table',21);
INSERT INTO `migrations` VALUES (122,'2025_10_09_172120_create_email_reputation_table',22);
INSERT INTO `migrations` VALUES (123,'2025_10_10_115019_create_newsletter_contacts_table',23);
INSERT INTO `migrations` VALUES (124,'2025_10_10_115023_create_newsletter_campaigns_table',23);
INSERT INTO `migrations` VALUES (125,'2025_10_10_115026_create_newsletter_subscriptions_table',23);
INSERT INTO `migrations` VALUES (126,'2025_10_10_000000_create_chargebacks_table',24);
INSERT INTO `migrations` VALUES (127,'2025_10_11_140242_add_missing_fields_to_chargebacks_table',25);
INSERT INTO `migrations` VALUES (128,'2025_10_11_142240_add_needs_response_status_to_chargebacks',26);
INSERT INTO `migrations` VALUES (129,'2025_10_11_000000_add_suspension_fields_to_users_table',27);
INSERT INTO `migrations` VALUES (130,'2025_10_11_170737_add_missing_fields_to_admins_table',27);
INSERT INTO `migrations` VALUES (131,'2025_10_11_172424_create_admin_permissions_table',27);
INSERT INTO `migrations` VALUES (132,'2025_10_11_175141_add_password_changed_at_to_admins_table',27);
INSERT INTO `migrations` VALUES (133,'2025_10_12_171127_add_new_event_fields_to_events_table',28);
INSERT INTO `migrations` VALUES (134,'2025_10_12_171815_add_seo_and_publishing_fields_to_events_table',28);
INSERT INTO `migrations` VALUES (135,'2025_10_12_175638_create_event_categories_table',29);
INSERT INTO `migrations` VALUES (136,'2025_10_12_183527_add_publishing_status_columns_to_events_table',29);
INSERT INTO `migrations` VALUES (137,'2025_10_13_123422_create_venues_table',30);
INSERT INTO `migrations` VALUES (138,'2025_10_13_125852_add_venue_id_to_events_table',31);
INSERT INTO `migrations` VALUES (139,'2025_10_13_131302_refactor_venue_templates_add_venue_id',32);
INSERT INTO `migrations` VALUES (140,'2025_10_13_132027_create_event_venues_table',32);
INSERT INTO `migrations` VALUES (141,'2025_10_13_142019_populate_event_venues_table',33);
INSERT INTO `migrations` VALUES (142,'2025_10_14_120000_add_missing_columns_to_events_table',34);
INSERT INTO `migrations` VALUES (143,'2025_10_15_000001_add_template_support_to_newsletter_campaigns',34);
INSERT INTO `migrations` VALUES (144,'2018_08_08_100000_create_telescope_entries_table',35);
INSERT INTO `migrations` VALUES (145,'2025_01_21_000001_create_venue_themes_table',35);
INSERT INTO `migrations` VALUES (146,'2025_10_16_000001_add_email_tracking_to_orders',35);
INSERT INTO `migrations` VALUES (147,'2025_10_16_171509_add_fee_tax_settings_to_events_table',35);
INSERT INTO `migrations` VALUES (148,'2025_10_16_173156_create_ticket_verification_codes_table',35);
INSERT INTO `migrations` VALUES (149,'2025_10_16_174631_add_code_type_preferences_to_events_table',35);
INSERT INTO `migrations` VALUES (150,'2025_10_17_124724_add_line_item_id_to_ticket_validations_table',35);
INSERT INTO `migrations` VALUES (151,'2025_10_21_000002_add_payment_intent_id_to_webhook_events',35);
INSERT INTO `migrations` VALUES (152,'2025_10_22_112045_create_cms_files_table',35);
INSERT INTO `migrations` VALUES (153,'2025_10_22_130045_create_account_setup_invitations_table',35);
INSERT INTO `migrations` VALUES (154,'2025_10_23_120718_add_campaign_metadata_to_invitations',35);
INSERT INTO `migrations` VALUES (155,'2025_10_23_120750_create_failed_invitation_attempts_table',35);
INSERT INTO `migrations` VALUES (156,'2025_10_23_120827_create_campaign_audit_logs_table',35);
INSERT INTO `migrations` VALUES (157,'2025_10_23_143224_add_indexes_to_account_setup_invitations',35);
INSERT INTO `migrations` VALUES (158,'2025_10_24_000001_clean_venue_architecture',35);
INSERT INTO `migrations` VALUES (159,'2025_10_24_134926_add_is_published_and_publish_website_to_events_table',35);
INSERT INTO `migrations` VALUES (160,'2025_10_24_185319_add_theme_foreign_keys_to_events_and_venues',35);
INSERT INTO `migrations` VALUES (161,'2025_10_25_142803_fix_seats_seat_id_unique_constraint_per_event',36);
INSERT INTO `migrations` VALUES (162,'2025_10_27_144317_add_unique_session_constraint_to_orders_table',36);
INSERT INTO `migrations` VALUES (163,'2025_10_27_151716_add_payment_started_at_to_seat_reservations_table',36);
INSERT INTO `migrations` VALUES (164,'2025_10_28_000001_add_email_tracking_to_account_setup_invitations',36);
INSERT INTO `migrations` VALUES (165,'2025_10_28_000002_add_email_tracking_to_users',36);
INSERT INTO `migrations` VALUES (166,'2025_10_28_170133_add_admin_reservation_support',36);
INSERT INTO `migrations` VALUES (167,'2025_10_28_170330_create_ownership_transfer_requests_table',36);
INSERT INTO `migrations` VALUES (168,'2025_10_29_114258_add_payment_intent_id_to_seat_reservations_table',36);
INSERT INTO `migrations` VALUES (169,'2025_10_30_153808_create_webhook_events_table',1);
INSERT INTO `migrations` VALUES (170,'2025_10_30_205810_add_revolut_order_id_to_seat_reservations_table',37);
INSERT INTO `migrations` VALUES (171,'2025_10_31_124326_add_revolut_metadata_to_events',37);
INSERT INTO `migrations` VALUES (172,'2025_10_31_124400_add_structured_address_to_venues',37);
INSERT INTO `migrations` VALUES (173,'2025_11_03_131603_create_homepage_sections_table',38);
INSERT INTO `migrations` VALUES (174,'2025_11_03_211512_add_bank_transfer_fields_to_orders_table',38);
INSERT INTO `migrations` VALUES (175,'2025_11_03_214956_add_payment_mode_to_seat_reservations_table',38);
INSERT INTO `migrations` VALUES (176,'2025_11_04_122714_add_payment_gateway_to_seat_reservations',38);
INSERT INTO `migrations` VALUES (177,'2025_11_04_135939_create_admin_password_resets_table',39);
INSERT INTO `migrations` VALUES (178,'2025_11_04_000001_create_price_tiers_table',40);
INSERT INTO `migrations` VALUES (179,'2025_11_04_000002_add_tier_fields_to_seats_table',40);
INSERT INTO `migrations` VALUES (180,'2025_11_04_171047_add_optional_fees_to_reservations_and_orders',40);
INSERT INTO `migrations` VALUES (181,'2025_11_04_172805_create_fee_waiver_audit_log_table',40);
INSERT INTO `migrations` VALUES (182,'2025_11_04_185730_add_fee_config_to_events_table',40);
INSERT INTO `migrations` VALUES (183,'2025_11_05_180148_add_media_support_columns_to_cms_files_table',41);
INSERT INTO `migrations` VALUES (184,'2025_11_06_175934_add_currency_to_events_table',42);
INSERT INTO `migrations` VALUES (185,'2025_11_06_202141_add_currency_to_seat_reservations_table',42);
INSERT INTO `migrations` VALUES (186,'2025_11_08_230228_add_seat_prefix_to_price_tiers',42);
INSERT INTO `migrations` VALUES (187,'2025_11_09_110917_create_artists_table',42);
INSERT INTO `migrations` VALUES (188,'2025_11_09_123657_create_artist_event_table',42);
INSERT INTO `migrations` VALUES (189,'2025_11_09_170618_remove_artists_column_from_events_table',42);
INSERT INTO `migrations` VALUES (190,'2025_11_10_000001_add_map_banner_to_events_table',42);
INSERT INTO `migrations` VALUES (191,'2025_11_10_000001_add_released_at_to_seat_reservations_table',42);
INSERT INTO `migrations` VALUES (192,'2025_11_10_194613_fix_seat_reservations_foreign_key_and_orders_unique_constraint',42);
INSERT INTO `migrations` VALUES (193,'2025_11_10_212140_fix_order_refunds_processed_by_foreign_key',42);
INSERT INTO `migrations` VALUES (194,'2025_11_11_000001_create_coupons_table',42);
INSERT INTO `migrations` VALUES (195,'2025_11_11_000002_create_coupon_usage_table',42);
INSERT INTO `migrations` VALUES (196,'2025_11_11_000003_add_coupon_fields_to_seat_reservations_table',42);
INSERT INTO `migrations` VALUES (197,'2025_11_11_000004_add_coupon_fields_to_orders_table',42);
INSERT INTO `migrations` VALUES (198,'2025_11_11_092259_fix_seat_reservations_admin_user_foreign_key',42);
INSERT INTO `migrations` VALUES (199,'2025_11_11_095845_fix_order_refunds_processed_by_foreign_key',42);
INSERT INTO `migrations` VALUES (200,'2025_11_11_112357_add_notes_to_seat_reservations',42);
INSERT INTO `migrations` VALUES (201,'2025_11_11_113629_add_booking_banner_image_to_events_table',42);
INSERT INTO `migrations` VALUES (202,'2025_11_11_224510_add_is_test_mode_to_events_table',43);
INSERT INTO `migrations` VALUES (203,'2025_11_12_000001_add_composite_indexes_for_performance',44);
INSERT INTO `migrations` VALUES (204,'2025_11_13_115435_add_display_in_legend_to_price_tiers_table',44);
INSERT INTO `migrations` VALUES (205,'2025_11_13_164122_create_booking_access_codes_tables',45);
INSERT INTO `migrations` VALUES (206,'2025_11_14_173205_create_analytics_events_table',46);
INSERT INTO `migrations` VALUES (207,'2025_11_17_104017_create_order_audit_log_table',47);
INSERT INTO `migrations` VALUES (208,'2025_11_17_161632_create_waitlist_submissions_table',48);
INSERT INTO `migrations` VALUES (209,'2025_11_18_124703_add_status_to_waitlist_submissions_table',48);
INSERT INTO `migrations` VALUES (210,'2025_11_18_210000_create_scanner_devices_table',49);
INSERT INTO `migrations` VALUES (211,'2025_11_19_120000_add_idempotency_key_to_ticket_validations',49);
INSERT INTO `migrations` VALUES (212,'2025_11_19_195955_add_pos_fields_to_orders_table',49);
INSERT INTO `migrations` VALUES (213,'2025_11_19_204212_add_deposit_reserve_fields_to_orders_table',49);
INSERT INTO `migrations` VALUES (214,'0000_00_00_000000_load_schema_dump',50);
INSERT INTO `migrations` VALUES (215,'2025_11_23_183337_create_scanner_zones_table',50);
INSERT INTO `migrations` VALUES (216,'2025_11_23_183340_add_zone_fields_to_scanner_devices_table',50);
INSERT INTO `migrations` VALUES (217,'2025_11_24_141603_add_operator_tracking_to_scanner_devices_table',50);
INSERT INTO `migrations` VALUES (218,'2025_11_24_221130_add_scan_type_to_ticket_validations_table',50);
INSERT INTO `migrations` VALUES (219,'2025_11_25_120511_remove_unique_constraint_from_ticket_validations_validation_code',50);
INSERT INTO `migrations` VALUES (220,'2025_11_27_141016_add_wristband_columns_to_events_table',50);
INSERT INTO `migrations` VALUES (221,'2025_11_27_205027_create_mbs_activity_logs_table',50);
INSERT INTO `migrations` VALUES (222,'2025_11_28_133018_add_legacy_fields_to_artists_table',50);
INSERT INTO `migrations` VALUES (223,'2025_11_28_134911_add_legacy_fields_to_events_table',50);
INSERT INTO `migrations` VALUES (224,'2025_11_28_144506_create_archived_events_table',50);
INSERT INTO `migrations` VALUES (225,'2025_11_28_144528_create_archived_event_artist_table',50);
INSERT INTO `migrations` VALUES (226,'2025_11_28_144546_create_event_images_table',50);
INSERT INTO `migrations` VALUES (227,'2025_11_28_153358_add_role_to_event_images_table',50);
INSERT INTO `migrations` VALUES (228,'2025_11_29_170020_add_is_featured_to_archived_events',50);
INSERT INTO `migrations` VALUES (229,'2025_12_01_165319_add_order_reference_to_orders_table',50);
INSERT INTO `migrations` VALUES (230,'2025_12_03_222456_fix_orders_staff_id_foreign_key_references_admins',50);
INSERT INTO `migrations` VALUES (231,'2025_12_08_130000_create_whats_app_logs_table',50);
INSERT INTO `migrations` VALUES (232,'2025_12_08_140000_create_support_conversations_table',50);
INSERT INTO `migrations` VALUES (233,'2025_12_08_150000_create_whatsapp_templates_table',50);
INSERT INTO `migrations` VALUES (234,'2025_12_08_195000_create_whatsapp_cost_tracker_table',50);
INSERT INTO `migrations` VALUES (235,'2025_12_09_210116_add_phone_index_to_orders_table',50);
INSERT INTO `migrations` VALUES (236,'2025_12_10_001000_create_support_labels_tables',50);
INSERT INTO `migrations` VALUES (237,'2025_12_11_000000_create_settings_table',51);
INSERT INTO `migrations` VALUES (238,'2025_12_11_120000_add_audit_columns_to_ticket_validations_table',51);
INSERT INTO `migrations` VALUES (239,'2025_12_11_120000_add_requires_super_admin_to_settings',51);
INSERT INTO `migrations` VALUES (240,'2025_12_11_140511_add_email_delivery_option_to_orders_table',51);
INSERT INTO `migrations` VALUES (241,'2025_12_11_145105_add_custom_email_to_orders_table',51);
INSERT INTO `migrations` VALUES (242,'2025_12_17_124426_add_email_delivery_options_to_seat_reservations_table',52);
INSERT INTO `migrations` VALUES (243,'2025_12_19_154451_drop_payment_audit_logs_user_id_foreign_key',53);
INSERT INTO `migrations` VALUES (244,'2025_12_20_000001_create_reseating_system',54);
INSERT INTO `migrations` VALUES (245,'2025_12_22_172004_add_comp_to_payment_mode_enum_and_backfill',55);
INSERT INTO `migrations` VALUES (246,'2025_12_23_114622_add_blocking_columns_to_seats_table',55);
INSERT INTO `migrations` VALUES (247,'2025_12_23_115126_create_seat_state_log_table',55);
INSERT INTO `migrations` VALUES (248,'2025_12_29_230405_add_status_values_to_ticket_validations',56);
INSERT INTO `migrations` VALUES (249,'2026_01_07_160000_create_verified_financial_entries_table',999);
INSERT INTO `migrations` VALUES (250,'2026_01_07_180000_create_eod_reports_table',999);
INSERT INTO `migrations` VALUES (251,'2026_01_08_100000_normalize_order_status_values',999);
INSERT INTO `migrations` VALUES (252,'2026_01_08_100001_normalize_payment_method_values',999);
INSERT INTO `migrations` VALUES (253,'2026_01_08_140000_add_currency_to_orders_and_normalize_events',999);
INSERT INTO `migrations` VALUES (254,'2026_01_08_150000_fix_order_audit_log_order_id_fk',999);
INSERT INTO `migrations` VALUES (255,'2026_01_08_151000_fix_coupon_usage_order_id_fk',999);
INSERT INTO `migrations` VALUES (256,'2026_01_15_141800_add_video_fields_to_events_table',1000);
INSERT INTO `migrations` VALUES (257,'2026_01_19_130533_add_video_collection_id_to_events_table',1001);
