-- MariaDB dump 10.19  Distrib 10.4.32-MariaDB, for Win64 (AMD64)
--
-- Host: localhost    Database: masonic_office
-- ------------------------------------------------------
-- Server version	10.4.32-MariaDB

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

--
-- Table structure for table `access_reviews`
--

DROP TABLE IF EXISTS `access_reviews`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `access_reviews` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `membership_id` bigint(20) unsigned NOT NULL,
  `reviewer_id` bigint(20) unsigned NOT NULL,
  `scope_type` enum('platform','province','unit') NOT NULL,
  `scope_id` bigint(20) unsigned NOT NULL,
  `role_key` varchar(50) NOT NULL,
  `decision` enum('retain','revoke') NOT NULL,
  `previous_expires_at` datetime DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  `next_review_at` datetime DEFAULT NULL,
  `reviewed_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_review_scope` (`scope_type`,`scope_id`,`reviewed_at`),
  KEY `membership_id` (`membership_id`),
  KEY `reviewer_id` (`reviewer_id`),
  CONSTRAINT `access_reviews_ibfk_1` FOREIGN KEY (`membership_id`) REFERENCES `user_memberships` (`id`),
  CONSTRAINT `access_reviews_ibfk_2` FOREIGN KEY (`reviewer_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `access_reviews`
--

LOCK TABLES `access_reviews` WRITE;
/*!40000 ALTER TABLE `access_reviews` DISABLE KEYS */;
/*!40000 ALTER TABLE `access_reviews` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_mfa`
--

DROP TABLE IF EXISTS `account_mfa`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_mfa` (
  `user_id` bigint(20) unsigned NOT NULL,
  `secret_cipher` text DEFAULT NULL,
  `enabled_at` datetime DEFAULT NULL,
  `last_counter` bigint(20) NOT NULL DEFAULT -1,
  `pending_cipher` text DEFAULT NULL,
  `pending_expires_at` datetime DEFAULT NULL,
  `pending_session_hash` char(64) DEFAULT NULL,
  PRIMARY KEY (`user_id`),
  CONSTRAINT `account_mfa_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_mfa`
--

LOCK TABLES `account_mfa` WRITE;
/*!40000 ALTER TABLE `account_mfa` DISABLE KEYS */;
/*!40000 ALTER TABLE `account_mfa` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_recovery_codes`
--

DROP TABLE IF EXISTS `account_recovery_codes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_recovery_codes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL,
  `code_hash` char(64) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `used_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_recovery_code` (`user_id`,`code_hash`),
  CONSTRAINT `account_recovery_codes_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_recovery_codes`
--

LOCK TABLES `account_recovery_codes` WRITE;
/*!40000 ALTER TABLE `account_recovery_codes` DISABLE KEYS */;
/*!40000 ALTER TABLE `account_recovery_codes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `action_centre_authorisations`
--

DROP TABLE IF EXISTS `action_centre_authorisations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `action_centre_authorisations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `task_kind` enum('unpaid_reminder') NOT NULL,
  `authorised_by` bigint(20) unsigned NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `expires_at` datetime DEFAULT NULL,
  `authorised_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_action_authorisation` (`unit_id`,`task_kind`),
  KEY `authorised_by` (`authorised_by`),
  CONSTRAINT `action_centre_authorisations_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `action_centre_authorisations_ibfk_2` FOREIGN KEY (`authorised_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `action_centre_authorisations`
--

LOCK TABLES `action_centre_authorisations` WRITE;
/*!40000 ALTER TABLE `action_centre_authorisations` DISABLE KEYS */;
/*!40000 ALTER TABLE `action_centre_authorisations` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `action_centre_tasks`
--

DROP TABLE IF EXISTS `action_centre_tasks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `action_centre_tasks` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `task_kind` enum('role_message','invitation_request','booking_deadline','waiting_offer','draft_publication','unpaid_reminder','access_review','minutes_action') NOT NULL,
  `source_type` varchar(50) NOT NULL,
  `source_id` bigint(20) unsigned NOT NULL,
  `owner_role` varchar(50) NOT NULL,
  `required_capability` varchar(80) NOT NULL,
  `title` varchar(250) NOT NULL,
  `due_at` datetime DEFAULT NULL,
  `action_url` varchar(500) NOT NULL,
  `status` enum('open','resolved','dismissed') NOT NULL DEFAULT 'open',
  `resolved_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_action_source` (`unit_id`,`task_kind`,`source_type`,`source_id`),
  KEY `idx_action_owner` (`unit_id`,`status`,`owner_role`,`due_at`),
  CONSTRAINT `action_centre_tasks_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `action_centre_tasks`
--

LOCK TABLES `action_centre_tasks` WRITE;
/*!40000 ALTER TABLE `action_centre_tasks` DISABLE KEYS */;
/*!40000 ALTER TABLE `action_centre_tasks` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Temporary table structure for view `active_user_memberships`
--

DROP TABLE IF EXISTS `active_user_memberships`;
/*!50001 DROP VIEW IF EXISTS `active_user_memberships`*/;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `active_user_memberships` AS SELECT
 1 AS `id`,
  1 AS `user_id`,
  1 AS `scope_type`,
  1 AS `province_id`,
  1 AS `unit_id`,
  1 AS `role`,
  1 AS `active`,
  1 AS `created_at`,
  1 AS `updated_at`,
  1 AS `scope_key`,
  1 AS `expires_at`,
  1 AS `revoked_at`,
  1 AS `last_used_at`,
  1 AS `reviewed_at`,
  1 AS `review_due_at` */;
SET character_set_client = @saved_cs_client;

--
-- Table structure for table `activity_log`
--

DROP TABLE IF EXISTS `activity_log`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `activity_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `source_kind` enum('unit','province') NOT NULL,
  `source_id` bigint(20) unsigned NOT NULL,
  `actor_id` bigint(20) unsigned DEFAULT NULL,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `action` varchar(100) NOT NULL,
  `target_type` varchar(50) DEFAULT NULL,
  `target_id` bigint(20) unsigned DEFAULT NULL,
  `change_summary` varchar(250) NOT NULL,
  `occurred_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_activity_source` (`source_kind`,`source_id`),
  KEY `idx_activity_unit` (`unit_id`,`occurred_at`,`id`),
  KEY `idx_activity_province` (`province_id`,`occurred_at`,`id`),
  KEY `idx_activity_actor` (`actor_id`,`occurred_at`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `activity_log`
--

LOCK TABLES `activity_log` WRITE;
/*!40000 ALTER TABLE `activity_log` DISABLE KEYS */;
INSERT INTO `activity_log` VALUES (1,'unit',1,1,NULL,NULL,'initial_admin_created','user',1,'initial admin created','2026-09-27 22:07:43'),(2,'unit',2,1,NULL,NULL,'login_succeeded',NULL,NULL,'login succeeded','2026-09-27 22:07:51'),(3,'unit',3,1,NULL,NULL,'login_succeeded',NULL,NULL,'login succeeded','2026-09-28 08:32:26'),(4,'unit',4,1,NULL,NULL,'login_succeeded',NULL,NULL,'login succeeded','2026-09-28 12:03:06'),(5,'unit',5,1,NULL,NULL,'login_failed',NULL,NULL,'login failed','2026-09-28 16:49:43'),(6,'unit',6,1,NULL,NULL,'login_succeeded',NULL,NULL,'login succeeded','2026-09-28 16:49:49'),(7,'province',1,1,103,NULL,'province_created','province',103,'province created','2026-09-28 16:50:08'),(8,'province',2,1,103,134,'unit_created','unit',134,'unit created','2026-09-28 16:50:44'),(14,'unit',12,1,NULL,NULL,'login_failed',NULL,NULL,'login failed','2026-09-28 18:39:39'),(15,'unit',13,1,NULL,NULL,'login_succeeded',NULL,NULL,'login succeeded','2026-09-28 18:39:43');
/*!40000 ALTER TABLE `activity_log` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER trg_activity_immutable_update BEFORE UPDATE ON activity_log FOR EACH ROW
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Activity history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER trg_activity_immutable_delete BEFORE DELETE ON activity_log FOR EACH ROW
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Activity history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `administrator_sessions`
--

DROP TABLE IF EXISTS `administrator_sessions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `administrator_sessions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL,
  `session_hash` char(64) NOT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` varchar(500) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `last_seen_at` datetime NOT NULL DEFAULT current_timestamp(),
  `expires_at` datetime NOT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `auth_strength` enum('password','email','totp','recovery') NOT NULL DEFAULT 'password',
  `reauthenticated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_administrator_session_hash` (`session_hash`),
  KEY `idx_administrator_session_user` (`user_id`,`last_seen_at`),
  CONSTRAINT `fk_administrator_session_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `administrator_sessions`
--

LOCK TABLES `administrator_sessions` WRITE;
/*!40000 ALTER TABLE `administrator_sessions` DISABLE KEYS */;
INSERT INTO `administrator_sessions` VALUES (1,1,'d815c439bbe77d6b6b29f631884b605ef8cf83bf591e17e1becd0348a7a8bcaf','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36','2026-09-27 22:07:51','2026-09-27 22:32:14','2026-09-28 10:07:51',NULL,'password',NULL),(2,1,'eeea5bef363cfa539ecddc9358b948d5389dc336d23088157d9ca24d6914172e','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36','2026-09-28 08:32:26','2026-09-28 08:32:26','2026-09-28 20:32:26',NULL,'password',NULL),(3,1,'a04b343d634fab789d89896c0d0cf37e4e8aa8b084135ec4d752279af4306caf','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36','2026-09-28 12:03:06','2026-09-28 12:51:10','2026-09-29 00:03:06',NULL,'password',NULL),(4,1,'2c4d61d675871c527251a4bf7afd04867c3ffa62570b98ea9d801a2e937c96b0','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36','2026-09-28 16:49:49','2026-09-28 17:26:01','2026-09-29 04:49:49',NULL,'password','2026-09-28 16:50:44'),(5,1,'321abb5c6025c4760698a74cfe960a1f433c332103eed40f234ee411203305b1','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36','2026-09-28 18:39:43','2026-09-28 18:39:52','2026-09-29 06:39:43',NULL,'password',NULL);
/*!40000 ALTER TABLE `administrator_sessions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `asset_assignments`
--

DROP TABLE IF EXISTS `asset_assignments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `asset_assignments` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `asset_id` bigint(20) unsigned NOT NULL,
  `custodian_person_id` bigint(20) unsigned NOT NULL,
  `checked_out_at` datetime NOT NULL,
  `due_at` datetime DEFAULT NULL,
  `checked_in_at` datetime DEFAULT NULL,
  `issued_by` bigint(20) unsigned NOT NULL,
  `checked_in_by` bigint(20) unsigned DEFAULT NULL,
  `custodian_confirmed_at` datetime DEFAULT NULL,
  `return_confirmed_at` datetime DEFAULT NULL,
  `handover_note` varchar(500) DEFAULT NULL,
  `active_asset_id` bigint(20) unsigned GENERATED ALWAYS AS (if(`checked_in_at` is null,`asset_id`,NULL)) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_asset_active_assignment` (`active_asset_id`),
  KEY `idx_asset_custodian` (`custodian_person_id`,`checked_in_at`,`due_at`),
  KEY `asset_id` (`asset_id`),
  KEY `issued_by` (`issued_by`),
  KEY `checked_in_by` (`checked_in_by`),
  CONSTRAINT `asset_assignments_ibfk_1` FOREIGN KEY (`asset_id`) REFERENCES `asset_register` (`id`) ON DELETE CASCADE,
  CONSTRAINT `asset_assignments_ibfk_2` FOREIGN KEY (`custodian_person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `asset_assignments_ibfk_3` FOREIGN KEY (`issued_by`) REFERENCES `users` (`id`),
  CONSTRAINT `asset_assignments_ibfk_4` FOREIGN KEY (`checked_in_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `asset_assignments`
--

LOCK TABLES `asset_assignments` WRITE;
/*!40000 ALTER TABLE `asset_assignments` DISABLE KEYS */;
/*!40000 ALTER TABLE `asset_assignments` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `asset_history`
--

DROP TABLE IF EXISTS `asset_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `asset_history` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `asset_id` bigint(20) unsigned NOT NULL,
  `event_type` enum('created','updated','image_linked','checked_out','custodian_confirmed','checked_in','return_confirmed','loaned','loan_returned','lost','found','disposal_requested','disposed','archived','published','unpublished') NOT NULL,
  `assignment_id` bigint(20) unsigned DEFAULT NULL,
  `loan_id` bigint(20) unsigned DEFAULT NULL,
  `change_json` text DEFAULT NULL,
  `actor_user_id` bigint(20) unsigned DEFAULT NULL,
  `occurred_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_asset_history` (`asset_id`,`occurred_at`,`id`),
  KEY `assignment_id` (`assignment_id`),
  KEY `loan_id` (`loan_id`),
  KEY `actor_user_id` (`actor_user_id`),
  CONSTRAINT `asset_history_ibfk_1` FOREIGN KEY (`asset_id`) REFERENCES `asset_register` (`id`) ON DELETE CASCADE,
  CONSTRAINT `asset_history_ibfk_2` FOREIGN KEY (`assignment_id`) REFERENCES `asset_assignments` (`id`) ON DELETE SET NULL,
  CONSTRAINT `asset_history_ibfk_3` FOREIGN KEY (`loan_id`) REFERENCES `asset_loans` (`id`) ON DELETE SET NULL,
  CONSTRAINT `asset_history_ibfk_4` FOREIGN KEY (`actor_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `asset_history`
--

LOCK TABLES `asset_history` WRITE;
/*!40000 ALTER TABLE `asset_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `asset_history` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER asset_history_no_update BEFORE UPDATE ON asset_history FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Asset history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER asset_history_no_delete BEFORE DELETE ON asset_history FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Asset history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `asset_images`
--

DROP TABLE IF EXISTS `asset_images`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `asset_images` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `asset_id` bigint(20) unsigned NOT NULL,
  `tenant_version_id` bigint(20) unsigned DEFAULT NULL,
  `province_version_id` bigint(20) unsigned DEFAULT NULL,
  `caption` varchar(200) DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_asset_image_version` (`asset_id`,`tenant_version_id`,`province_version_id`),
  KEY `tenant_version_id` (`tenant_version_id`),
  KEY `province_version_id` (`province_version_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `asset_images_ibfk_1` FOREIGN KEY (`asset_id`) REFERENCES `asset_register` (`id`) ON DELETE CASCADE,
  CONSTRAINT `asset_images_ibfk_2` FOREIGN KEY (`tenant_version_id`) REFERENCES `tenant_document_versions` (`id`),
  CONSTRAINT `asset_images_ibfk_3` FOREIGN KEY (`province_version_id`) REFERENCES `province_document_versions` (`id`),
  CONSTRAINT `asset_images_ibfk_4` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_asset_image_version` CHECK (`tenant_version_id` is null <> (`province_version_id` is null))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `asset_images`
--

LOCK TABLES `asset_images` WRITE;
/*!40000 ALTER TABLE `asset_images` DISABLE KEYS */;
/*!40000 ALTER TABLE `asset_images` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `asset_loans`
--

DROP TABLE IF EXISTS `asset_loans`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `asset_loans` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `asset_id` bigint(20) unsigned NOT NULL,
  `borrowing_unit_id` bigint(20) unsigned NOT NULL,
  `loaned_at` datetime NOT NULL,
  `due_at` datetime DEFAULT NULL,
  `returned_at` datetime DEFAULT NULL,
  `approved_by` bigint(20) unsigned NOT NULL,
  `received_by` bigint(20) unsigned DEFAULT NULL,
  `active_asset_id` bigint(20) unsigned GENERATED ALWAYS AS (if(`returned_at` is null,`asset_id`,NULL)) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_asset_active_loan` (`active_asset_id`),
  KEY `idx_asset_loan_unit` (`borrowing_unit_id`,`returned_at`,`due_at`),
  KEY `asset_id` (`asset_id`),
  KEY `approved_by` (`approved_by`),
  KEY `received_by` (`received_by`),
  CONSTRAINT `asset_loans_ibfk_1` FOREIGN KEY (`asset_id`) REFERENCES `asset_register` (`id`) ON DELETE CASCADE,
  CONSTRAINT `asset_loans_ibfk_2` FOREIGN KEY (`borrowing_unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `asset_loans_ibfk_3` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`),
  CONSTRAINT `asset_loans_ibfk_4` FOREIGN KEY (`received_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `asset_loans`
--

LOCK TABLES `asset_loans` WRITE;
/*!40000 ALTER TABLE `asset_loans` DISABLE KEYS */;
/*!40000 ALTER TABLE `asset_loans` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `asset_register`
--

DROP TABLE IF EXISTS `asset_register`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `asset_register` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('province','unit') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `asset_identifier` varchar(80) NOT NULL,
  `asset_type` enum('jewel','collar','regalia','banner','furniture','key','other') NOT NULL,
  `description` varchar(500) NOT NULL,
  `condition_state` enum('excellent','good','fair','poor','damaged','missing','disposed') NOT NULL DEFAULT 'good',
  `location_label` varchar(200) DEFAULT NULL,
  `acquisition_date` date DEFAULT NULL,
  `disposal_date` date DEFAULT NULL,
  `purchase_value` decimal(12,2) DEFAULT NULL,
  `insured_value` decimal(12,2) DEFAULT NULL,
  `key_details_cipher` mediumtext DEFAULT NULL,
  `review_due_at` date DEFAULT NULL,
  `visibility` enum('private_officer','member') NOT NULL DEFAULT 'private_officer',
  `status` enum('active','lost','disposal_pending','disposed','archived') NOT NULL DEFAULT 'active',
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `scope_key` varchar(90) GENERATED ALWAYS AS (concat(`scope_type`,':',`province_id`,':',ifnull(`unit_id`,0))) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_asset_identifier` (`scope_key`,`asset_identifier`),
  KEY `idx_asset_scope` (`scope_type`,`province_id`,`unit_id`,`status`,`review_due_at`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `asset_register_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `asset_register_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `asset_register_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_asset_scope` CHECK (`scope_type` = 'province' and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null),
  CONSTRAINT `chk_asset_disposal` CHECK (`status` = 'disposed' and `disposal_date` is not null or `status` <> 'disposed')
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `asset_register`
--

LOCK TABLES `asset_register` WRITE;
/*!40000 ALTER TABLE `asset_register` DISABLE KEYS */;
/*!40000 ALTER TABLE `asset_register` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `attendee_contacts`
--

DROP TABLE IF EXISTS `attendee_contacts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `attendee_contacts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `salutation` varchar(30) NOT NULL,
  `first_name` varchar(100) NOT NULL,
  `surname` varchar(100) NOT NULL,
  `email` varchar(254) NOT NULL,
  `phone` varchar(30) DEFAULT NULL,
  `masonic_rank` varchar(150) DEFAULT NULL,
  `provincial_rank` varchar(150) DEFAULT NULL,
  `grand_rank` varchar(150) DEFAULT NULL,
  `lodge_name` varchar(150) DEFAULT NULL,
  `lodge_number` varchar(30) DEFAULT NULL,
  `consented_at` datetime NOT NULL,
  `last_booked_at` datetime NOT NULL,
  `consent_withdrawn_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_attendee_contact_unit_email` (`unit_id`,`email`),
  KEY `idx_attendee_contact_consent` (`consent_withdrawn_at`,`last_booked_at`),
  KEY `idx_attendee_contacts_unit` (`unit_id`),
  CONSTRAINT `fk_attendee_contacts_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `attendee_contacts`
--

LOCK TABLES `attendee_contacts` WRITE;
/*!40000 ALTER TABLE `attendee_contacts` DISABLE KEYS */;
/*!40000 ALTER TABLE `attendee_contacts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `attendee_invitations`
--

DROP TABLE IF EXISTS `attendee_invitations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `attendee_invitations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `attendee_contact_id` bigint(20) unsigned NOT NULL,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `status` enum('queued','sent','failed') NOT NULL,
  `sent_at` datetime DEFAULT NULL,
  `failure_message` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_attendee_meeting_invitation` (`attendee_contact_id`,`meeting_id`),
  KEY `fk_attendee_invitation_meeting` (`meeting_id`),
  CONSTRAINT `fk_attendee_invitation_contact` FOREIGN KEY (`attendee_contact_id`) REFERENCES `attendee_contacts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_attendee_invitation_meeting` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `attendee_invitations`
--

LOCK TABLES `attendee_invitations` WRITE;
/*!40000 ALTER TABLE `attendee_invitations` DISABLE KEYS */;
/*!40000 ALTER TABLE `attendee_invitations` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `audit_log`
--

DROP TABLE IF EXISTS `audit_log`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `audit_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `action` varchar(100) NOT NULL,
  `entity_type` varchar(50) DEFAULT NULL,
  `entity_id` bigint(20) unsigned DEFAULT NULL,
  `booking_reference` varchar(50) DEFAULT NULL,
  `details` text DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_audit_created` (`created_at`),
  KEY `idx_audit_reference` (`booking_reference`),
  KEY `fk_audit_user` (`user_id`),
  KEY `idx_audit_unit_created` (`unit_id`,`created_at`),
  CONSTRAINT `fk_audit_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_audit_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `audit_log`
--

LOCK TABLES `audit_log` WRITE;
/*!40000 ALTER TABLE `audit_log` DISABLE KEYS */;
INSERT INTO `audit_log` VALUES (1,NULL,1,'initial_admin_created','user',1,NULL,NULL,'127.0.0.1','2026-09-27 22:07:43'),(2,NULL,1,'login_succeeded',NULL,NULL,NULL,NULL,'127.0.0.1','2026-09-27 22:07:51'),(3,NULL,1,'login_succeeded',NULL,NULL,NULL,NULL,'127.0.0.1','2026-09-28 08:32:26'),(4,NULL,1,'login_succeeded',NULL,NULL,NULL,NULL,'127.0.0.1','2026-09-28 12:03:06'),(5,NULL,1,'login_failed',NULL,NULL,NULL,NULL,'127.0.0.1','2026-09-28 16:49:43'),(6,NULL,1,'login_succeeded',NULL,NULL,NULL,NULL,'127.0.0.1','2026-09-28 16:49:49'),(12,NULL,1,'login_failed',NULL,NULL,NULL,NULL,'127.0.0.1','2026-09-28 18:39:39'),(13,NULL,1,'login_succeeded',NULL,NULL,NULL,NULL,'127.0.0.1','2026-09-28 18:39:43');
/*!40000 ALTER TABLE `audit_log` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER trg_activity_from_unit AFTER INSERT ON audit_log FOR EACH ROW
INSERT INTO activity_log(source_kind,source_id,actor_id,province_id,unit_id,action,target_type,target_id,change_summary,occurred_at)
VALUES('unit',NEW.id,NEW.user_id,(SELECT u.province_id FROM units u WHERE u.id=NEW.unit_id),NEW.unit_id,
NEW.action,NEW.entity_type,NEW.entity_id,REPLACE(NEW.action,'_',' '),NEW.created_at) */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `auth_rate_limits`
--

DROP TABLE IF EXISTS `auth_rate_limits`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `auth_rate_limits` (
  `bucket` char(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `attempts` int(10) unsigned NOT NULL DEFAULT 0,
  `window_started` datetime NOT NULL,
  PRIMARY KEY (`bucket`),
  KEY `idx_auth_window_started` (`window_started`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `auth_rate_limits`
--

LOCK TABLES `auth_rate_limits` WRITE;
/*!40000 ALTER TABLE `auth_rate_limits` DISABLE KEYS */;
INSERT INTO `auth_rate_limits` VALUES ('2a2a70875b16211482653db13a7964f5b037c5c55a8f4509a0c8838978e07064',1,'2026-09-28 16:50:44'),('3b7a781e2297d395100faf31377320d923edef5d1d34be2da46e211770a12043',1,'2026-09-28 16:50:44'),('674dcc95a6c069401bc91c33b34af72a4fb8e76c512ff04a04e5fc43cd98dc0f',2,'2026-09-28 18:39:38'),('b4828a415e4271dc886992cd44452e70ce4c97ff8cc7a0fad2dff249eb838f93',2,'2026-09-28 18:39:38');
/*!40000 ALTER TABLE `auth_rate_limits` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `backup_log`
--

DROP TABLE IF EXISTS `backup_log`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `backup_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `filename` varchar(255) NOT NULL,
  `size_bytes` bigint(20) unsigned NOT NULL DEFAULT 0,
  `status` enum('success','failed') NOT NULL,
  `message` text DEFAULT NULL,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `fk_backup_user` (`created_by`),
  KEY `idx_backup_log_unit` (`unit_id`),
  CONSTRAINT `fk_backup_log_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `fk_backup_user` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `backup_log`
--

LOCK TABLES `backup_log` WRITE;
/*!40000 ALTER TABLE `backup_log` DISABLE KEYS */;
/*!40000 ALTER TABLE `backup_log` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `booking_history`
--

DROP TABLE IF EXISTS `booking_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `booking_history` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `booking_id` bigint(20) unsigned NOT NULL,
  `changed_by_user_id` bigint(20) unsigned DEFAULT NULL,
  `changed_by_type` enum('attendee','officer','system') NOT NULL DEFAULT 'system',
  `field_name` varchar(100) NOT NULL,
  `old_value` text DEFAULT NULL,
  `new_value` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_history_booking` (`booking_id`,`created_at`),
  KEY `fk_history_user` (`changed_by_user_id`),
  CONSTRAINT `fk_history_booking` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_history_user` FOREIGN KEY (`changed_by_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `booking_history`
--

LOCK TABLES `booking_history` WRITE;
/*!40000 ALTER TABLE `booking_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `booking_history` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `bookings`
--

DROP TABLE IF EXISTS `bookings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `bookings` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `booking_reference` varchar(50) NOT NULL,
  `booking_code_hash` varchar(255) NOT NULL,
  `booking_code_lookup` char(64) DEFAULT NULL,
  `status` enum('active','cancelled','waiting','offered','declined') NOT NULL DEFAULT 'active',
  `attendance` enum('meeting_and_festive_board','meeting_only','apology') NOT NULL,
  `salutation` varchar(30) NOT NULL,
  `first_name` varchar(100) NOT NULL,
  `surname` varchar(100) NOT NULL,
  `email` varchar(254) NOT NULL,
  `phone` varchar(30) DEFAULT NULL,
  `future_contact_consent` tinyint(1) NOT NULL DEFAULT 0,
  `is_lodge_member` tinyint(1) NOT NULL DEFAULT 0,
  `attendee_type` enum('lodge_member','visiting_member','special_event_guest','ladies_evening_guest','white_table_guest','blue_table_guest') NOT NULL DEFAULT 'visiting_member',
  `attendee_type_label` varchar(120) DEFAULT NULL,
  `lodge_name` varchar(150) DEFAULT NULL,
  `lodge_number` varchar(30) DEFAULT NULL,
  `masonic_rank` varchar(150) DEFAULT NULL,
  `provincial_rank` varchar(150) DEFAULT NULL,
  `grand_rank` varchar(150) DEFAULT NULL,
  `dining` tinyint(1) NOT NULL DEFAULT 0,
  `dietary_requirements` text DEFAULT NULL,
  `allergy_details` text DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `payment_selection` enum('pay','provincial_visit_pay','grand_lodge_visit_pay','provincial_visit','grand_lodge_visit','not_required') NOT NULL DEFAULT 'not_required',
  `dining_subtotal` decimal(10,2) NOT NULL DEFAULT 0.00,
  `raffle_ticket_quantity` int(10) unsigned NOT NULL DEFAULT 0,
  `raffle_ticket_unit_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `raffle_subtotal` decimal(10,2) NOT NULL DEFAULT 0.00,
  `total_charge` decimal(10,2) NOT NULL DEFAULT 0.00,
  `amount_received` decimal(10,2) NOT NULL DEFAULT 0.00,
  `refund_amount` decimal(10,2) NOT NULL DEFAULT 0.00,
  `payment_status` enum('unpaid','paid','exempt','not_required','refunded') NOT NULL DEFAULT 'not_required',
  `payment_method` varchar(50) DEFAULT NULL,
  `payment_reference` varchar(100) DEFAULT NULL,
  `paid_at` datetime DEFAULT NULL,
  `refunded_at` datetime DEFAULT NULL,
  `treasurer_notes` text DEFAULT NULL,
  `payment_updated_by` bigint(20) unsigned DEFAULT NULL,
  `arrived` tinyint(1) NOT NULL DEFAULT 0,
  `arrived_at` datetime DEFAULT NULL,
  `checked_in_by` bigint(20) unsigned DEFAULT NULL,
  `confirmation_sent_at` datetime DEFAULT NULL,
  `calendar_sent_at` datetime DEFAULT NULL,
  `test_booking` tinyint(1) NOT NULL DEFAULT 0,
  `cancelled_at` datetime DEFAULT NULL,
  `offer_expires_at` datetime DEFAULT NULL,
  `anonymised_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_booking_reference` (`booking_reference`),
  KEY `idx_booking_meeting` (`meeting_id`),
  KEY `idx_booking_email` (`email`),
  KEY `idx_booking_status` (`meeting_id`,`status`),
  KEY `idx_booking_payment` (`meeting_id`,`payment_status`),
  KEY `fk_payment_updated_by` (`payment_updated_by`),
  KEY `fk_booking_checked_in_by` (`checked_in_by`),
  KEY `idx_booking_code_lookup` (`booking_code_lookup`),
  CONSTRAINT `fk_booking_checked_in_by` FOREIGN KEY (`checked_in_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_booking_meeting` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`),
  CONSTRAINT `fk_payment_updated_by` FOREIGN KEY (`payment_updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `bookings`
--

LOCK TABLES `bookings` WRITE;
/*!40000 ALTER TABLE `bookings` DISABLE KEYS */;
/*!40000 ALTER TABLE `bookings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `calendar_feed_tokens`
--

DROP TABLE IF EXISTS `calendar_feed_tokens`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `calendar_feed_tokens` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL,
  `scope_type` enum('my','province','unit') NOT NULL,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `token_hash` char(64) NOT NULL,
  `label` varchar(100) NOT NULL,
  `include_private` tinyint(1) NOT NULL DEFAULT 0,
  `expires_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `last_used_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_calendar_feed_token` (`token_hash`),
  KEY `idx_calendar_feed_user` (`user_id`,`revoked_at`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  CONSTRAINT `calendar_feed_tokens_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_feed_tokens_ibfk_2` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_feed_tokens_ibfk_3` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_calendar_feed_scope` CHECK (`scope_type` = 'my' and `province_id` is null and `unit_id` is null or `scope_type` = 'province' and `province_id` is not null and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `calendar_feed_tokens`
--

LOCK TABLES `calendar_feed_tokens` WRITE;
/*!40000 ALTER TABLE `calendar_feed_tokens` DISABLE KEYS */;
/*!40000 ALTER TABLE `calendar_feed_tokens` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `calendar_planning_entries`
--

DROP TABLE IF EXISTS `calendar_planning_entries`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `calendar_planning_entries` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('province','unit') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `template_id` bigint(20) unsigned DEFAULT NULL,
  `entry_kind` enum('rehearsal','lodge_of_instruction','installation','provincial_visit','special_event','summons_deadline','dining_deadline','reporting_date','officer_task') NOT NULL,
  `title` varchar(200) NOT NULL,
  `description` varchar(500) DEFAULT NULL,
  `order_key` varchar(40) DEFAULT NULL,
  `venue_id` bigint(20) unsigned DEFAULT NULL,
  `venue_text` varchar(300) DEFAULT NULL,
  `timezone` varchar(64) NOT NULL DEFAULT 'Europe/London',
  `starts_at` datetime NOT NULL,
  `ends_at` datetime DEFAULT NULL,
  `task_due_at` datetime DEFAULT NULL,
  `owner_user_id` bigint(20) unsigned DEFAULT NULL,
  `visibility` enum('members','officers','private') NOT NULL DEFAULT 'officers',
  `status` enum('draft','confirmed','cancelled','completed') NOT NULL DEFAULT 'draft',
  `override_conflict` tinyint(1) NOT NULL DEFAULT 0,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_calendar_entry_scope` (`scope_type`,`province_id`,`unit_id`,`starts_at`,`status`),
  KEY `idx_calendar_owner` (`owner_user_id`,`task_due_at`,`status`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `template_id` (`template_id`),
  KEY `venue_id` (`venue_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `calendar_planning_entries_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_planning_entries_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_planning_entries_ibfk_3` FOREIGN KEY (`template_id`) REFERENCES `calendar_recurring_templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `calendar_planning_entries_ibfk_4` FOREIGN KEY (`venue_id`) REFERENCES `calendar_venues` (`id`) ON DELETE SET NULL,
  CONSTRAINT `calendar_planning_entries_ibfk_5` FOREIGN KEY (`owner_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `calendar_planning_entries_ibfk_6` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_calendar_entry_scope` CHECK (`scope_type` = 'province' and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `calendar_planning_entries`
--

LOCK TABLES `calendar_planning_entries` WRITE;
/*!40000 ALTER TABLE `calendar_planning_entries` DISABLE KEYS */;
/*!40000 ALTER TABLE `calendar_planning_entries` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `calendar_recurrence_exceptions`
--

DROP TABLE IF EXISTS `calendar_recurrence_exceptions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `calendar_recurrence_exceptions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `template_id` bigint(20) unsigned NOT NULL,
  `occurrence_date` date NOT NULL,
  `exception_kind` enum('cancel','replace') NOT NULL,
  `replacement_entry_id` bigint(20) unsigned DEFAULT NULL,
  `note` varchar(300) DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_calendar_exception` (`template_id`,`occurrence_date`),
  KEY `replacement_entry_id` (`replacement_entry_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `calendar_recurrence_exceptions_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `calendar_recurring_templates` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_recurrence_exceptions_ibfk_2` FOREIGN KEY (`replacement_entry_id`) REFERENCES `calendar_planning_entries` (`id`) ON DELETE SET NULL,
  CONSTRAINT `calendar_recurrence_exceptions_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `calendar_recurrence_exceptions`
--

LOCK TABLES `calendar_recurrence_exceptions` WRITE;
/*!40000 ALTER TABLE `calendar_recurrence_exceptions` DISABLE KEYS */;
/*!40000 ALTER TABLE `calendar_recurrence_exceptions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `calendar_recurring_templates`
--

DROP TABLE IF EXISTS `calendar_recurring_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `calendar_recurring_templates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('province','unit') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `entry_kind` enum('rehearsal','lodge_of_instruction','installation','provincial_visit','special_event','reporting_date','officer_task') NOT NULL,
  `title` varchar(200) NOT NULL,
  `description` varchar(500) DEFAULT NULL,
  `order_key` varchar(40) DEFAULT NULL,
  `venue_id` bigint(20) unsigned DEFAULT NULL,
  `timezone` varchar(64) NOT NULL DEFAULT 'Europe/London',
  `local_start_time` time NOT NULL,
  `duration_minutes` smallint(5) unsigned NOT NULL DEFAULT 60,
  `frequency` enum('weekly','monthly','yearly') NOT NULL,
  `recurrence_interval` smallint(5) unsigned NOT NULL DEFAULT 1,
  `start_date` date NOT NULL,
  `until_date` date DEFAULT NULL,
  `occurrence_count` smallint(5) unsigned DEFAULT NULL,
  `owner_user_id` bigint(20) unsigned DEFAULT NULL,
  `visibility` enum('members','officers','private') NOT NULL DEFAULT 'officers',
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_calendar_template_scope` (`scope_type`,`province_id`,`unit_id`,`active`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `venue_id` (`venue_id`),
  KEY `owner_user_id` (`owner_user_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `calendar_recurring_templates_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_recurring_templates_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_recurring_templates_ibfk_3` FOREIGN KEY (`venue_id`) REFERENCES `calendar_venues` (`id`) ON DELETE SET NULL,
  CONSTRAINT `calendar_recurring_templates_ibfk_4` FOREIGN KEY (`owner_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `calendar_recurring_templates_ibfk_5` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_calendar_template_scope` CHECK (`scope_type` = 'province' and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `calendar_recurring_templates`
--

LOCK TABLES `calendar_recurring_templates` WRITE;
/*!40000 ALTER TABLE `calendar_recurring_templates` DISABLE KEYS */;
/*!40000 ALTER TABLE `calendar_recurring_templates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `calendar_reminder_rules`
--

DROP TABLE IF EXISTS `calendar_reminder_rules`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `calendar_reminder_rules` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `entry_id` bigint(20) unsigned NOT NULL,
  `minutes_before` int(10) unsigned NOT NULL,
  `recipient_user_id` bigint(20) unsigned NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `last_queued_for` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_calendar_reminder` (`entry_id`,`minutes_before`,`recipient_user_id`),
  KEY `recipient_user_id` (`recipient_user_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `calendar_reminder_rules_ibfk_1` FOREIGN KEY (`entry_id`) REFERENCES `calendar_planning_entries` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_reminder_rules_ibfk_2` FOREIGN KEY (`recipient_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_reminder_rules_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `calendar_reminder_rules`
--

LOCK TABLES `calendar_reminder_rules` WRITE;
/*!40000 ALTER TABLE `calendar_reminder_rules` DISABLE KEYS */;
/*!40000 ALTER TABLE `calendar_reminder_rules` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `calendar_venues`
--

DROP TABLE IF EXISTS `calendar_venues`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `calendar_venues` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `name` varchar(200) NOT NULL,
  `address` varchar(500) DEFAULT NULL,
  `timezone` varchar(64) NOT NULL DEFAULT 'Europe/London',
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_calendar_venue` (`unit_id`,`name`),
  KEY `idx_calendar_venue_province` (`province_id`,`active`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `calendar_venues_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_venues_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `calendar_venues_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `calendar_venues`
--

LOCK TABLES `calendar_venues` WRITE;
/*!40000 ALTER TABLE `calendar_venues` DISABLE KEYS */;
/*!40000 ALTER TABLE `calendar_venues` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `candidate_admissions`
--

DROP TABLE IF EXISTS `candidate_admissions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `candidate_admissions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `candidate_id` bigint(20) unsigned NOT NULL,
  `member_id` bigint(20) unsigned NOT NULL,
  `ceremony_date` date NOT NULL,
  `terminology` varchar(80) NOT NULL,
  `confirmed_by` bigint(20) unsigned NOT NULL,
  `confirmed_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_candidate_admission` (`candidate_id`),
  UNIQUE KEY `uq_admission_member` (`member_id`),
  KEY `fk_admission_actor` (`confirmed_by`),
  CONSTRAINT `fk_admission_actor` FOREIGN KEY (`confirmed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_admission_candidate` FOREIGN KEY (`candidate_id`) REFERENCES `unit_candidates` (`id`),
  CONSTRAINT `fk_admission_member` FOREIGN KEY (`member_id`) REFERENCES `unit_members` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `candidate_admissions`
--

LOCK TABLES `candidate_admissions` WRITE;
/*!40000 ALTER TABLE `candidate_admissions` DISABLE KEYS */;
/*!40000 ALTER TABLE `candidate_admissions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `candidate_history`
--

DROP TABLE IF EXISTS `candidate_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `candidate_history` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `candidate_id` bigint(20) unsigned NOT NULL,
  `actor_id` bigint(20) unsigned NOT NULL,
  `action_key` varchar(60) NOT NULL,
  `from_stage` varchar(30) DEFAULT NULL,
  `to_stage` varchar(30) DEFAULT NULL,
  `occurred_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_candidate_history` (`candidate_id`,`occurred_at`),
  KEY `fk_candidate_history_actor` (`actor_id`),
  CONSTRAINT `fk_candidate_history_actor` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_candidate_history_candidate` FOREIGN KEY (`candidate_id`) REFERENCES `unit_candidates` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `candidate_history`
--

LOCK TABLES `candidate_history` WRITE;
/*!40000 ALTER TABLE `candidate_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `candidate_history` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `catering_handoff_delivery`
--

DROP TABLE IF EXISTS `catering_handoff_delivery`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catering_handoff_delivery` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `handoff_id` bigint(20) unsigned NOT NULL,
  `status` enum('delivered','acknowledged') NOT NULL,
  `method` enum('manual','email','other') NOT NULL DEFAULT 'manual',
  `acknowledgement_reference` varchar(190) DEFAULT NULL,
  `recorded_by` bigint(20) unsigned NOT NULL,
  `recorded_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_handoff_delivery` (`handoff_id`,`recorded_at`,`id`),
  KEY `recorded_by` (`recorded_by`),
  CONSTRAINT `catering_handoff_delivery_ibfk_1` FOREIGN KEY (`handoff_id`) REFERENCES `catering_handoffs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `catering_handoff_delivery_ibfk_2` FOREIGN KEY (`recorded_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `catering_handoff_delivery`
--

LOCK TABLES `catering_handoff_delivery` WRITE;
/*!40000 ALTER TABLE `catering_handoff_delivery` DISABLE KEYS */;
/*!40000 ALTER TABLE `catering_handoff_delivery` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `catering_handoffs`
--

DROP TABLE IF EXISTS `catering_handoffs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catering_handoffs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `programme_id` bigint(20) unsigned NOT NULL,
  `handoff_no` int(10) unsigned NOT NULL,
  `parent_handoff_id` bigint(20) unsigned DEFAULT NULL,
  `menu_version_id` bigint(20) unsigned NOT NULL,
  `snapshot_json` longtext NOT NULL,
  `comparison_json` longtext DEFAULT NULL,
  `approved_by` bigint(20) unsigned NOT NULL,
  `approved_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_catering_handoff` (`programme_id`,`handoff_no`),
  KEY `parent_handoff_id` (`parent_handoff_id`),
  KEY `menu_version_id` (`menu_version_id`),
  KEY `approved_by` (`approved_by`),
  CONSTRAINT `catering_handoffs_ibfk_1` FOREIGN KEY (`programme_id`) REFERENCES `event_programmes` (`id`),
  CONSTRAINT `catering_handoffs_ibfk_2` FOREIGN KEY (`parent_handoff_id`) REFERENCES `catering_handoffs` (`id`),
  CONSTRAINT `catering_handoffs_ibfk_3` FOREIGN KEY (`menu_version_id`) REFERENCES `programme_menu_versions` (`id`),
  CONSTRAINT `catering_handoffs_ibfk_4` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `catering_handoffs`
--

LOCK TABLES `catering_handoffs` WRITE;
/*!40000 ALTER TABLE `catering_handoffs` DISABLE KEYS */;
/*!40000 ALTER TABLE `catering_handoffs` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER catering_handoff_no_update BEFORE UPDATE ON catering_handoffs FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Approved catering snapshots are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER catering_handoff_no_delete BEFORE DELETE ON catering_handoffs FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Catering handoffs are append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `communication_log`
--

DROP TABLE IF EXISTS `communication_log`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `communication_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `meeting_id` bigint(20) unsigned DEFAULT NULL,
  `booking_id` bigint(20) unsigned DEFAULT NULL,
  `template_key` varchar(80) DEFAULT NULL,
  `recipient` varchar(254) NOT NULL,
  `subject` varchar(250) NOT NULL,
  `body_html` mediumtext DEFAULT NULL,
  `status` enum('queued','sent','failed') NOT NULL DEFAULT 'queued',
  `error_message` text DEFAULT NULL,
  `retry_count` int(10) unsigned NOT NULL DEFAULT 0,
  `last_attempt_at` datetime DEFAULT NULL,
  `sent_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `sent_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_communication_meeting` (`meeting_id`,`created_at`),
  KEY `fk_communication_booking` (`booking_id`),
  KEY `fk_communication_user` (`sent_by`),
  KEY `idx_communication_log_unit` (`unit_id`),
  CONSTRAINT `fk_communication_booking` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_communication_log_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `fk_communication_meeting` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_communication_user` FOREIGN KEY (`sent_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `communication_log`
--

LOCK TABLES `communication_log` WRITE;
/*!40000 ALTER TABLE `communication_log` DISABLE KEYS */;
/*!40000 ALTER TABLE `communication_log` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `communication_suppressions`
--

DROP TABLE IF EXISTS `communication_suppressions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `communication_suppressions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `contact_hash` char(64) NOT NULL,
  `channel` enum('email','phone','post','all') NOT NULL DEFAULT 'email',
  `reason` enum('objection','consent_withdrawal','erasure') NOT NULL,
  `source_case_id` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_communication_suppression` (`unit_id`,`contact_hash`,`channel`),
  KEY `fk_suppression_case` (`source_case_id`),
  CONSTRAINT `fk_suppression_case` FOREIGN KEY (`source_case_id`) REFERENCES `data_governance_cases` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_suppression_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `communication_suppressions`
--

LOCK TABLES `communication_suppressions` WRITE;
/*!40000 ALTER TABLE `communication_suppressions` DISABLE KEYS */;
/*!40000 ALTER TABLE `communication_suppressions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `contact_messages`
--

DROP TABLE IF EXISTS `contact_messages`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `contact_messages` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `name` varchar(200) NOT NULL,
  `email` varchar(254) NOT NULL,
  `subject` varchar(150) NOT NULL,
  `other_subject` varchar(200) DEFAULT NULL,
  `message` text NOT NULL,
  `recipients` text NOT NULL,
  `status` enum('new','sent','failed','archived') NOT NULL DEFAULT 'new',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_contact_status` (`status`,`created_at`),
  KEY `idx_contact_messages_unit` (`unit_id`),
  CONSTRAINT `fk_contact_messages_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `contact_messages`
--

LOCK TABLES `contact_messages` WRITE;
/*!40000 ALTER TABLE `contact_messages` DISABLE KEYS */;
/*!40000 ALTER TABLE `contact_messages` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `custom_orders`
--

DROP TABLE IF EXISTS `custom_orders`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `custom_orders` (
  `unit_id` bigint(20) unsigned NOT NULL,
  `order_key` varchar(40) NOT NULL,
  `order_name` varchar(150) NOT NULL,
  `member_noun` varchar(50) NOT NULL DEFAULT 'Member',
  `body_noun` varchar(50) NOT NULL DEFAULT 'Lodge',
  `salutations` text DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`unit_id`,`order_key`),
  UNIQUE KEY `uq_custom_order_name` (`order_name`),
  CONSTRAINT `fk_custom_orders_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `custom_orders`
--

LOCK TABLES `custom_orders` WRITE;
/*!40000 ALTER TABLE `custom_orders` DISABLE KEYS */;
/*!40000 ALTER TABLE `custom_orders` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `data_governance_case_events`
--

DROP TABLE IF EXISTS `data_governance_case_events`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `data_governance_case_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint(20) unsigned NOT NULL,
  `actor_id` bigint(20) unsigned NOT NULL,
  `event_key` varchar(80) NOT NULL,
  `restricted_note` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_governance_event` (`case_id`,`created_at`),
  KEY `fk_governance_event_actor` (`actor_id`),
  CONSTRAINT `fk_governance_event_actor` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_governance_event_case` FOREIGN KEY (`case_id`) REFERENCES `data_governance_cases` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `data_governance_case_events`
--

LOCK TABLES `data_governance_case_events` WRITE;
/*!40000 ALTER TABLE `data_governance_case_events` DISABLE KEYS */;
/*!40000 ALTER TABLE `data_governance_case_events` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `data_governance_case_people`
--

DROP TABLE IF EXISTS `data_governance_case_people`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `data_governance_case_people` (
  `case_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `link_status` enum('possible','verified','excluded') NOT NULL DEFAULT 'possible',
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  PRIMARY KEY (`case_id`,`person_id`),
  KEY `fk_governance_person_person` (`person_id`),
  KEY `fk_governance_person_reviewer` (`reviewed_by`),
  CONSTRAINT `fk_governance_person_case` FOREIGN KEY (`case_id`) REFERENCES `data_governance_cases` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_governance_person_person` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_governance_person_reviewer` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `data_governance_case_people`
--

LOCK TABLES `data_governance_case_people` WRITE;
/*!40000 ALTER TABLE `data_governance_case_people` DISABLE KEYS */;
/*!40000 ALTER TABLE `data_governance_case_people` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `data_governance_cases`
--

DROP TABLE IF EXISTS `data_governance_cases`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `data_governance_cases` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `request_type` enum('access','correction','consent_withdrawal','restriction','erasure') NOT NULL,
  `request_received_at` datetime NOT NULL,
  `requester_name` varchar(200) NOT NULL,
  `requester_contact` varchar(254) DEFAULT NULL,
  `identity_status` enum('unverified','verified','failed') NOT NULL DEFAULT 'unverified',
  `identity_verified_at` datetime DEFAULT NULL,
  `identity_verified_by` bigint(20) unsigned DEFAULT NULL,
  `identity_method` varchar(80) DEFAULT NULL,
  `scope_summary` varchar(500) NOT NULL,
  `responsible_officer_id` bigint(20) unsigned DEFAULT NULL,
  `deadline_at` datetime NOT NULL,
  `status` enum('received','identity_check','review','restricted','decided','completed','rejected') NOT NULL DEFAULT 'received',
  `decision_code` enum('pending','approved','partially_approved','refused','retained_obligation','withdrawal_recorded') NOT NULL DEFAULT 'pending',
  `decision_summary` text DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `completed_by` bigint(20) unsigned DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_governance_case_queue` (`unit_id`,`status`,`deadline_at`),
  KEY `idx_governance_handler` (`responsible_officer_id`,`status`),
  KEY `fk_governance_case_verifier` (`identity_verified_by`),
  KEY `fk_governance_case_completer` (`completed_by`),
  KEY `fk_governance_case_creator` (`created_by`),
  CONSTRAINT `fk_governance_case_completer` FOREIGN KEY (`completed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_governance_case_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_governance_case_handler` FOREIGN KEY (`responsible_officer_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_governance_case_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `fk_governance_case_verifier` FOREIGN KEY (`identity_verified_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `data_governance_cases`
--

LOCK TABLES `data_governance_cases` WRITE;
/*!40000 ALTER TABLE `data_governance_cases` DISABLE KEYS */;
/*!40000 ALTER TABLE `data_governance_cases` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `data_governance_exports`
--

DROP TABLE IF EXISTS `data_governance_exports`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `data_governance_exports` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint(20) unsigned NOT NULL,
  `token_hash` char(64) NOT NULL,
  `payload_cipher` longtext NOT NULL,
  `expires_at` datetime NOT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `downloaded_at` datetime DEFAULT NULL,
  `downloaded_by` bigint(20) unsigned DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_governance_export_token` (`token_hash`),
  KEY `idx_governance_export_case` (`case_id`,`expires_at`),
  KEY `fk_governance_export_creator` (`created_by`),
  KEY `fk_governance_export_downloader` (`downloaded_by`),
  CONSTRAINT `fk_governance_export_case` FOREIGN KEY (`case_id`) REFERENCES `data_governance_cases` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_governance_export_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_governance_export_downloader` FOREIGN KEY (`downloaded_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `data_governance_exports`
--

LOCK TABLES `data_governance_exports` WRITE;
/*!40000 ALTER TABLE `data_governance_exports` DISABLE KEYS */;
/*!40000 ALTER TABLE `data_governance_exports` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `data_governance_source_reviews`
--

DROP TABLE IF EXISTS `data_governance_source_reviews`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `data_governance_source_reviews` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint(20) unsigned NOT NULL,
  `data_class` enum('person','membership','candidate','contact','booking','guest','message','document','welfare') NOT NULL,
  `source_id` bigint(20) unsigned NOT NULL,
  `subject_person_id` bigint(20) unsigned DEFAULT NULL,
  `review_status` enum('pending','include','exclude','redact') NOT NULL DEFAULT 'pending',
  `third_party_status` enum('not_applicable','pending','cleared','redacted','excluded') NOT NULL DEFAULT 'pending',
  `restricted_note` text DEFAULT NULL,
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_governance_source` (`case_id`,`data_class`,`source_id`),
  KEY `idx_governance_source_review` (`case_id`,`review_status`,`third_party_status`),
  KEY `fk_governance_source_person` (`subject_person_id`),
  KEY `fk_governance_source_reviewer` (`reviewed_by`),
  CONSTRAINT `fk_governance_source_case` FOREIGN KEY (`case_id`) REFERENCES `data_governance_cases` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_governance_source_person` FOREIGN KEY (`subject_person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_governance_source_reviewer` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `data_governance_source_reviews`
--

LOCK TABLES `data_governance_source_reviews` WRITE;
/*!40000 ALTER TABLE `data_governance_source_reviews` DISABLE KEYS */;
/*!40000 ALTER TABLE `data_governance_source_reviews` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_assignment_changes`
--

DROP TABLE IF EXISTS `dc_assignment_changes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_assignment_changes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `programme_id` bigint(20) unsigned NOT NULL,
  `version_no` int(10) unsigned NOT NULL,
  `assignment_id` bigint(20) unsigned DEFAULT NULL,
  `change_kind` enum('assigned','accepted','declined','replaced','withdrawn','approved','published') NOT NULL,
  `before_json` text DEFAULT NULL,
  `after_json` text DEFAULT NULL,
  `changed_by` bigint(20) unsigned DEFAULT NULL,
  `changed_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_dc_change_version` (`programme_id`,`version_no`,`id`),
  KEY `assignment_id` (`assignment_id`),
  KEY `changed_by` (`changed_by`),
  CONSTRAINT `dc_assignment_changes_ibfk_1` FOREIGN KEY (`programme_id`) REFERENCES `dc_event_programmes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_assignment_changes_ibfk_2` FOREIGN KEY (`assignment_id`) REFERENCES `dc_programme_assignments` (`id`) ON DELETE SET NULL,
  CONSTRAINT `dc_assignment_changes_ibfk_3` FOREIGN KEY (`changed_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_assignment_changes`
--

LOCK TABLES `dc_assignment_changes` WRITE;
/*!40000 ALTER TABLE `dc_assignment_changes` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_assignment_changes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_ceremony_templates`
--

DROP TABLE IF EXISTS `dc_ceremony_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_ceremony_templates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('province','unit') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `order_key` varchar(40) NOT NULL,
  `title` varchar(200) NOT NULL,
  `ceremony_term` varchar(100) NOT NULL,
  `structure_json` mediumtext NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_dc_template_scope` (`scope_type`,`province_id`,`unit_id`,`order_key`,`active`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `dc_ceremony_templates_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_ceremony_templates_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_ceremony_templates_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_dc_template_scope` CHECK (`scope_type` = 'province' and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_ceremony_templates`
--

LOCK TABLES `dc_ceremony_templates` WRITE;
/*!40000 ALTER TABLE `dc_ceremony_templates` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_ceremony_templates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_event_programmes`
--

DROP TABLE IF EXISTS `dc_event_programmes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_event_programmes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `template_id` bigint(20) unsigned DEFAULT NULL,
  `title` varchar(200) NOT NULL,
  `status` enum('draft','approved','published','superseded') NOT NULL DEFAULT 'draft',
  `version_no` int(10) unsigned NOT NULL DEFAULT 1,
  `approved_by` bigint(20) unsigned DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `published_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dc_programme_meeting` (`meeting_id`),
  KEY `idx_dc_programme_unit` (`unit_id`,`status`),
  KEY `template_id` (`template_id`),
  KEY `approved_by` (`approved_by`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `dc_event_programmes_ibfk_1` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_event_programmes_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_event_programmes_ibfk_3` FOREIGN KEY (`template_id`) REFERENCES `dc_ceremony_templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `dc_event_programmes_ibfk_4` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `dc_event_programmes_ibfk_5` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_event_programmes`
--

LOCK TABLES `dc_event_programmes` WRITE;
/*!40000 ALTER TABLE `dc_event_programmes` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_event_programmes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_private_exports`
--

DROP TABLE IF EXISTS `dc_private_exports`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_private_exports` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `token_hash` char(64) NOT NULL,
  `payload_cipher` mediumtext NOT NULL,
  `expires_at` datetime NOT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `downloaded_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dc_export_token` (`token_hash`),
  KEY `idx_dc_export_expiry` (`unit_id`,`expires_at`,`revoked_at`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `dc_private_exports_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_private_exports_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_private_exports`
--

LOCK TABLES `dc_private_exports` WRITE;
/*!40000 ALTER TABLE `dc_private_exports` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_private_exports` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_private_notes`
--

DROP TABLE IF EXISTS `dc_private_notes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_private_notes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned DEFAULT NULL,
  `programme_id` bigint(20) unsigned DEFAULT NULL,
  `note_cipher` mediumtext NOT NULL,
  `retention_until` date NOT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `deleted_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_dc_note_scope` (`unit_id`,`person_id`,`programme_id`,`retention_until`),
  KEY `person_id` (`person_id`),
  KEY `programme_id` (`programme_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `dc_private_notes_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_private_notes_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE SET NULL,
  CONSTRAINT `dc_private_notes_ibfk_3` FOREIGN KEY (`programme_id`) REFERENCES `dc_event_programmes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_private_notes_ibfk_4` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_private_notes`
--

LOCK TABLES `dc_private_notes` WRITE;
/*!40000 ALTER TABLE `dc_private_notes` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_private_notes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_programme_assignments`
--

DROP TABLE IF EXISTS `dc_programme_assignments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_programme_assignments` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `programme_id` bigint(20) unsigned NOT NULL,
  `role_key` varchar(80) NOT NULL,
  `role_label` varchar(150) NOT NULL,
  `person_id` bigint(20) unsigned DEFAULT NULL,
  `understudy_person_id` bigint(20) unsigned DEFAULT NULL,
  `assignment_source` enum('suggested','manual') NOT NULL DEFAULT 'manual',
  `status` enum('suggested','invited','accepted','declined','replaced','withdrawn') NOT NULL DEFAULT 'suggested',
  `availability` enum('unknown','available','unavailable') NOT NULL DEFAULT 'unknown',
  `accepted_at` datetime DEFAULT NULL,
  `responded_at` datetime DEFAULT NULL,
  `updated_by` bigint(20) unsigned NOT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dc_programme_role` (`programme_id`,`role_key`),
  KEY `idx_dc_assignment_people` (`person_id`,`understudy_person_id`,`status`),
  KEY `understudy_person_id` (`understudy_person_id`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `dc_programme_assignments_ibfk_1` FOREIGN KEY (`programme_id`) REFERENCES `dc_event_programmes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_programme_assignments_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE SET NULL,
  CONSTRAINT `dc_programme_assignments_ibfk_3` FOREIGN KEY (`understudy_person_id`) REFERENCES `people` (`id`) ON DELETE SET NULL,
  CONSTRAINT `dc_programme_assignments_ibfk_4` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_dc_different_understudy` CHECK (`person_id` is null or `understudy_person_id` is null or `person_id` <> `understudy_person_id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_programme_assignments`
--

LOCK TABLES `dc_programme_assignments` WRITE;
/*!40000 ALTER TABLE `dc_programme_assignments` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_programme_assignments` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_rehearsal_attendance`
--

DROP TABLE IF EXISTS `dc_rehearsal_attendance`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_rehearsal_attendance` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `rehearsal_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `attendance` enum('invited','attended','apology','absent') NOT NULL DEFAULT 'invited',
  `recorded_by` bigint(20) unsigned NOT NULL,
  `recorded_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dc_rehearsal_person` (`rehearsal_id`,`person_id`),
  KEY `person_id` (`person_id`),
  KEY `recorded_by` (`recorded_by`),
  CONSTRAINT `dc_rehearsal_attendance_ibfk_1` FOREIGN KEY (`rehearsal_id`) REFERENCES `dc_rehearsals` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_rehearsal_attendance_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_rehearsal_attendance_ibfk_3` FOREIGN KEY (`recorded_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_rehearsal_attendance`
--

LOCK TABLES `dc_rehearsal_attendance` WRITE;
/*!40000 ALTER TABLE `dc_rehearsal_attendance` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_rehearsal_attendance` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_rehearsals`
--

DROP TABLE IF EXISTS `dc_rehearsals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_rehearsals` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `programme_id` bigint(20) unsigned DEFAULT NULL,
  `calendar_entry_id` bigint(20) unsigned NOT NULL,
  `rehearsal_type` enum('rehearsal','lodge_of_instruction') NOT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dc_rehearsal_calendar` (`calendar_entry_id`),
  KEY `programme_id` (`programme_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `dc_rehearsals_ibfk_1` FOREIGN KEY (`programme_id`) REFERENCES `dc_event_programmes` (`id`) ON DELETE SET NULL,
  CONSTRAINT `dc_rehearsals_ibfk_2` FOREIGN KEY (`calendar_entry_id`) REFERENCES `calendar_planning_entries` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_rehearsals_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_rehearsals`
--

LOCK TABLES `dc_rehearsals` WRITE;
/*!40000 ALTER TABLE `dc_rehearsals` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_rehearsals` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_template_roles`
--

DROP TABLE IF EXISTS `dc_template_roles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_template_roles` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `template_id` bigint(20) unsigned NOT NULL,
  `role_key` varchar(80) NOT NULL,
  `role_label` varchar(150) NOT NULL,
  `required` tinyint(1) NOT NULL DEFAULT 1,
  `display_order` smallint(5) unsigned NOT NULL DEFAULT 0,
  `instructions_cipher` mediumtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dc_template_role` (`template_id`,`role_key`),
  CONSTRAINT `dc_template_roles_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `dc_ceremony_templates` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_template_roles`
--

LOCK TABLES `dc_template_roles` WRITE;
/*!40000 ALTER TABLE `dc_template_roles` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_template_roles` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dc_volunteer_profiles`
--

DROP TABLE IF EXISTS `dc_volunteer_profiles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dc_volunteer_profiles` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `preferred_roles_json` text DEFAULT NULL,
  `availability_notes_cipher` mediumtext DEFAULT NULL,
  `experience_cipher` mediumtext DEFAULT NULL,
  `consented_at` datetime NOT NULL,
  `withdrawn_at` datetime DEFAULT NULL,
  `retention_until` date DEFAULT NULL,
  `updated_by` bigint(20) unsigned NOT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dc_volunteer` (`unit_id`,`person_id`),
  KEY `idx_dc_volunteer_active` (`unit_id`,`withdrawn_at`,`retention_until`),
  KEY `person_id` (`person_id`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `dc_volunteer_profiles_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_volunteer_profiles_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dc_volunteer_profiles_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dc_volunteer_profiles`
--

LOCK TABLES `dc_volunteer_profiles` WRITE;
/*!40000 ALTER TABLE `dc_volunteer_profiles` DISABLE KEYS */;
/*!40000 ALTER TABLE `dc_volunteer_profiles` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `diner_course_choices`
--

DROP TABLE IF EXISTS `diner_course_choices`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `diner_course_choices` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) unsigned NOT NULL,
  `course_id` bigint(20) unsigned NOT NULL,
  `dish_id` bigint(20) unsigned NOT NULL,
  `supplement` decimal(10,2) NOT NULL DEFAULT 0.00,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_diner_course_choice` (`order_id`,`course_id`),
  KEY `idx_dish_totals` (`dish_id`,`order_id`),
  KEY `course_id` (`course_id`),
  CONSTRAINT `diner_course_choices_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `diner_menu_orders` (`id`) ON DELETE CASCADE,
  CONSTRAINT `diner_course_choices_ibfk_2` FOREIGN KEY (`course_id`) REFERENCES `programme_menu_courses` (`id`),
  CONSTRAINT `diner_course_choices_ibfk_3` FOREIGN KEY (`dish_id`) REFERENCES `programme_menu_dishes` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `diner_course_choices`
--

LOCK TABLES `diner_course_choices` WRITE;
/*!40000 ALTER TABLE `diner_course_choices` DISABLE KEYS */;
/*!40000 ALTER TABLE `diner_course_choices` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `diner_menu_orders`
--

DROP TABLE IF EXISTS `diner_menu_orders`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `diner_menu_orders` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `diner_id` bigint(20) unsigned NOT NULL,
  `menu_version_id` bigint(20) unsigned NOT NULL,
  `status` enum('current','needs_reselection','cancelled','superseded') NOT NULL DEFAULT 'current',
  `base_charge` decimal(10,2) NOT NULL DEFAULT 0.00,
  `supplement_total` decimal(10,2) NOT NULL DEFAULT 0.00,
  `submitted_by_type` enum('attendee','officer','system') NOT NULL,
  `submitted_by_user_id` bigint(20) unsigned DEFAULT NULL,
  `late_reason` varchar(1000) DEFAULT NULL,
  `submitted_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_diner_menu_order` (`diner_id`,`menu_version_id`),
  KEY `idx_menu_order_status` (`menu_version_id`,`status`),
  KEY `submitted_by_user_id` (`submitted_by_user_id`),
  CONSTRAINT `diner_menu_orders_ibfk_1` FOREIGN KEY (`diner_id`) REFERENCES `programme_diners` (`id`) ON DELETE CASCADE,
  CONSTRAINT `diner_menu_orders_ibfk_2` FOREIGN KEY (`menu_version_id`) REFERENCES `programme_menu_versions` (`id`),
  CONSTRAINT `diner_menu_orders_ibfk_3` FOREIGN KEY (`submitted_by_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=75 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `diner_menu_orders`
--

LOCK TABLES `diner_menu_orders` WRITE;
/*!40000 ALTER TABLE `diner_menu_orders` DISABLE KEYS */;
/*!40000 ALTER TABLE `diner_menu_orders` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `diner_order_history`
--

DROP TABLE IF EXISTS `diner_order_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `diner_order_history` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `diner_id` bigint(20) unsigned NOT NULL,
  `order_id` bigint(20) unsigned DEFAULT NULL,
  `action` varchar(60) NOT NULL,
  `detail_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`detail_json`)),
  `actor_type` enum('attendee','officer','system') NOT NULL,
  `actor_user_id` bigint(20) unsigned DEFAULT NULL,
  `occurred_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_diner_history` (`diner_id`,`occurred_at`,`id`),
  KEY `order_id` (`order_id`),
  KEY `actor_user_id` (`actor_user_id`),
  CONSTRAINT `diner_order_history_ibfk_1` FOREIGN KEY (`diner_id`) REFERENCES `programme_diners` (`id`) ON DELETE CASCADE,
  CONSTRAINT `diner_order_history_ibfk_2` FOREIGN KEY (`order_id`) REFERENCES `diner_menu_orders` (`id`) ON DELETE SET NULL,
  CONSTRAINT `diner_order_history_ibfk_3` FOREIGN KEY (`actor_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `diner_order_history`
--

LOCK TABLES `diner_order_history` WRITE;
/*!40000 ALTER TABLE `diner_order_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `diner_order_history` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER diner_order_history_no_update BEFORE UPDATE ON diner_order_history FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Diner order history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER diner_order_history_no_delete BEFORE DELETE ON diner_order_history FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Diner order history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `dining_room_template_tables`
--

DROP TABLE IF EXISTS `dining_room_template_tables`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dining_room_template_tables` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `template_id` bigint(20) unsigned NOT NULL,
  `stable_key` char(36) NOT NULL,
  `table_number` varchar(30) NOT NULL,
  `table_name` varchar(100) DEFAULT NULL,
  `shape` enum('round','rectangular') NOT NULL DEFAULT 'round',
  `is_top_table` tinyint(1) NOT NULL DEFAULT 0,
  `x_pos` decimal(8,2) NOT NULL,
  `y_pos` decimal(8,2) NOT NULL,
  `width` decimal(8,2) NOT NULL,
  `height` decimal(8,2) NOT NULL,
  `capacity` smallint(5) unsigned NOT NULL,
  `display_order` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_template_table_key` (`template_id`,`stable_key`),
  UNIQUE KEY `uq_template_table_number` (`template_id`,`table_number`),
  CONSTRAINT `dining_room_template_tables_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `dining_room_templates` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_template_table_size` CHECK (`width` > 0 and `height` > 0 and `capacity` > 0)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dining_room_template_tables`
--

LOCK TABLES `dining_room_template_tables` WRITE;
/*!40000 ALTER TABLE `dining_room_template_tables` DISABLE KEYS */;
/*!40000 ALTER TABLE `dining_room_template_tables` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dining_room_templates`
--

DROP TABLE IF EXISTS `dining_room_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dining_room_templates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `name` varchar(160) NOT NULL,
  `room_width` decimal(8,2) NOT NULL DEFAULT 100.00,
  `room_height` decimal(8,2) NOT NULL DEFAULT 70.00,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_room_template` (`unit_id`,`name`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `dining_room_templates_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `dining_room_templates_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dining_room_templates`
--

LOCK TABLES `dining_room_templates` WRITE;
/*!40000 ALTER TABLE `dining_room_templates` DISABLE KEYS */;
/*!40000 ALTER TABLE `dining_room_templates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `dining_tables`
--

DROP TABLE IF EXISTS `dining_tables`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dining_tables` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `table_name` varchar(100) NOT NULL,
  `capacity` int(10) unsigned NOT NULL DEFAULT 8,
  `display_order` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dining_table` (`meeting_id`,`table_name`),
  CONSTRAINT `fk_table_meeting` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dining_tables`
--

LOCK TABLES `dining_tables` WRITE;
/*!40000 ALTER TABLE `dining_tables` DISABLE KEYS */;
/*!40000 ALTER TABLE `dining_tables` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `document_folders`
--

DROP TABLE IF EXISTS `document_folders`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `document_folders` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('province','unit') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `stable_key` varchar(60) NOT NULL,
  `display_label` varchar(100) NOT NULL,
  `built_in` tinyint(1) NOT NULL DEFAULT 0,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `scope_key` varchar(90) GENERATED ALWAYS AS (concat(`scope_type`,':',`province_id`,':',ifnull(`unit_id`,0))) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_document_folder` (`scope_key`,`stable_key`),
  KEY `idx_document_folder_scope` (`scope_type`,`province_id`,`unit_id`,`active`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `document_folders_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `document_folders_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `document_folders_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `chk_document_folder_scope` CHECK (`scope_type` = 'province' and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null)
) ENGINE=InnoDB AUTO_INCREMENT=161 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `document_folders`
--

LOCK TABLES `document_folders` WRITE;
/*!40000 ALTER TABLE `document_folders` DISABLE KEYS */;
/*!40000 ALTER TABLE `document_folders` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `document_storage_quotas`
--

DROP TABLE IF EXISTS `document_storage_quotas`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `document_storage_quotas` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('province','unit') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `quota_bytes` bigint(20) unsigned NOT NULL DEFAULT 536870912,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `scope_key` varchar(90) GENERATED ALWAYS AS (concat(`scope_type`,':',`province_id`,':',ifnull(`unit_id`,0))) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_document_quota` (`scope_key`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `document_storage_quotas_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `document_storage_quotas_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `document_storage_quotas_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `chk_document_quota_scope` CHECK (`scope_type` = 'province' and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `document_storage_quotas`
--

LOCK TABLES `document_storage_quotas` WRITE;
/*!40000 ALTER TABLE `document_storage_quotas` DISABLE KEYS */;
/*!40000 ALTER TABLE `document_storage_quotas` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `documents`
--

DROP TABLE IF EXISTS `documents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `documents` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `title` varchar(200) NOT NULL,
  `description` varchar(500) DEFAULT NULL,
  `document_url` text NOT NULL,
  `category` enum('summons','minutes','bylaws','constitutions','forms_guidance','other') NOT NULL DEFAULT 'other',
  `visibility` enum('public','members','officers','administrators') NOT NULL DEFAULT 'members',
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `display_order` int(10) unsigned NOT NULL DEFAULT 0,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_documents_category_visibility` (`category`,`visibility`,`active`,`display_order`),
  KEY `fk_document_user` (`created_by`),
  KEY `idx_documents_unit` (`unit_id`),
  CONSTRAINT `fk_document_user` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_documents_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `documents`
--

LOCK TABLES `documents` WRITE;
/*!40000 ALTER TABLE `documents` DISABLE KEYS */;
/*!40000 ALTER TABLE `documents` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `email_templates`
--

DROP TABLE IF EXISTS `email_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `email_templates` (
  `unit_id` bigint(20) unsigned NOT NULL,
  `template_key` varchar(80) NOT NULL,
  `display_name` varchar(150) NOT NULL,
  `subject_template` varchar(250) NOT NULL,
  `body_template` mediumtext NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 1,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`unit_id`,`template_key`),
  KEY `fk_email_template_user` (`updated_by`),
  CONSTRAINT `fk_email_template_user` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_email_templates_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `email_templates`
--

LOCK TABLES `email_templates` WRITE;
/*!40000 ALTER TABLE `email_templates` DISABLE KEYS */;
INSERT INTO `email_templates` VALUES (134,'attendee_meeting_invitation','Previous attendee meeting invitation','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'booking_cancelled','Booking cancelled','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'booking_code','Booking code','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'booking_confirmation','Booking confirmation','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'guest_meeting_invitation','Previous guest meeting invitation','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'meeting_changed','Meeting details changed','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'meeting_reminder','Meeting reminder','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'payment_reminder','Payment reminder','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'place_confirmed','Waiting-list place confirmed','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'place_offered','Waiting-list place offered','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'summons_email','Summons or invitation email','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44'),(134,'waiting_list','Waiting list confirmation','Review this template before enabling','This template is disabled. Replace this draft before enabling.',0,NULL,'2026-09-28 16:50:44');
/*!40000 ALTER TABLE `email_templates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `event_day_pack_people`
--

DROP TABLE IF EXISTS `event_day_pack_people`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `event_day_pack_people` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `pack_id` bigint(20) unsigned NOT NULL,
  `person_type` enum('booking','guest') NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `display_name` varchar(240) NOT NULL,
  `booking_reference` varchar(50) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_pack_person` (`pack_id`,`person_type`,`person_id`),
  KEY `idx_pack_people` (`pack_id`,`display_name`,`id`),
  CONSTRAINT `event_day_pack_people_ibfk_1` FOREIGN KEY (`pack_id`) REFERENCES `event_day_packs` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `event_day_pack_people`
--

LOCK TABLES `event_day_pack_people` WRITE;
/*!40000 ALTER TABLE `event_day_pack_people` DISABLE KEYS */;
/*!40000 ALTER TABLE `event_day_pack_people` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `event_day_packs`
--

DROP TABLE IF EXISTS `event_day_packs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `event_day_packs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `programme_id` bigint(20) unsigned NOT NULL,
  `seating_snapshot_id` bigint(20) unsigned NOT NULL,
  `generated_by` bigint(20) unsigned NOT NULL,
  `generated_at` datetime NOT NULL DEFAULT current_timestamp(),
  `expires_at` datetime NOT NULL,
  `purged_at` datetime DEFAULT NULL,
  `source_fingerprint` char(64) NOT NULL,
  `snapshot_json` longtext DEFAULT NULL,
  `restricted_snapshot_cipher` longtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_event_pack_event` (`meeting_id`,`generated_at`,`id`),
  KEY `idx_event_pack_expiry` (`expires_at`,`purged_at`),
  KEY `unit_id` (`unit_id`),
  KEY `programme_id` (`programme_id`),
  KEY `seating_snapshot_id` (`seating_snapshot_id`),
  KEY `generated_by` (`generated_by`),
  CONSTRAINT `event_day_packs_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `event_day_packs_ibfk_2` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`),
  CONSTRAINT `event_day_packs_ibfk_3` FOREIGN KEY (`programme_id`) REFERENCES `event_programmes` (`id`),
  CONSTRAINT `event_day_packs_ibfk_4` FOREIGN KEY (`seating_snapshot_id`) REFERENCES `programme_table_plan_snapshots` (`id`),
  CONSTRAINT `event_day_packs_ibfk_5` FOREIGN KEY (`generated_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `event_day_packs`
--

LOCK TABLES `event_day_packs` WRITE;
/*!40000 ALTER TABLE `event_day_packs` DISABLE KEYS */;
/*!40000 ALTER TABLE `event_day_packs` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `event_programmes`
--

DROP TABLE IF EXISTS `event_programmes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `event_programmes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `programme_key` varchar(140) NOT NULL,
  `title` varchar(200) NOT NULL,
  `capacity` int(10) unsigned NOT NULL,
  `dining_mode` enum('fixed','choice') NOT NULL DEFAULT 'fixed',
  `menu_choice_enabled` tinyint(1) NOT NULL DEFAULT 0,
  `menu_choice_cutoff` datetime DEFAULT NULL,
  `published_menu_version_id` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_programme_unit_key` (`unit_id`,`programme_key`),
  UNIQUE KEY `uq_programme_id_unit` (`id`,`unit_id`),
  KEY `fk_programme_published_menu` (`published_menu_version_id`),
  CONSTRAINT `fk_programme_published_menu` FOREIGN KEY (`published_menu_version_id`) REFERENCES `programme_menu_versions` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_programme_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `event_programmes`
--

LOCK TABLES `event_programmes` WRITE;
/*!40000 ALTER TABLE `event_programmes` DISABLE KEYS */;
/*!40000 ALTER TABLE `event_programmes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_allocations`
--

DROP TABLE IF EXISTS `finance_allocations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_allocations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `payment_entry_id` bigint(20) unsigned NOT NULL,
  `charge_entry_id` bigint(20) unsigned NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_finance_allocation` (`payment_entry_id`,`charge_entry_id`),
  KEY `idx_finance_charge_allocation` (`charge_entry_id`),
  CONSTRAINT `finance_allocations_ibfk_1` FOREIGN KEY (`payment_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `finance_allocations_ibfk_2` FOREIGN KEY (`charge_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` > 0)
) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_allocations`
--

LOCK TABLES `finance_allocations` WRITE;
/*!40000 ALTER TABLE `finance_allocations` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_allocations` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER finance_allocation_no_update BEFORE UPDATE ON finance_allocations FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Finance allocations are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER finance_allocation_no_delete BEFORE DELETE ON finance_allocations FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Finance allocations are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `finance_bank_account_history`
--

DROP TABLE IF EXISTS `finance_bank_account_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_bank_account_history` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `bank_account_id` bigint(20) unsigned NOT NULL,
  `scope_key` varchar(80) NOT NULL,
  `old_sort_mask` varchar(30) DEFAULT NULL,
  `old_account_mask` varchar(50) DEFAULT NULL,
  `new_sort_mask` varchar(30) NOT NULL,
  `new_account_mask` varchar(50) NOT NULL,
  `changed_by` bigint(20) unsigned NOT NULL,
  `changed_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `changed_by` (`changed_by`),
  KEY `idx_bank_history` (`bank_account_id`,`changed_at`,`id`),
  CONSTRAINT `finance_bank_account_history_ibfk_1` FOREIGN KEY (`bank_account_id`) REFERENCES `finance_bank_accounts` (`id`),
  CONSTRAINT `finance_bank_account_history_ibfk_2` FOREIGN KEY (`changed_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_bank_account_history`
--

LOCK TABLES `finance_bank_account_history` WRITE;
/*!40000 ALTER TABLE `finance_bank_account_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_bank_account_history` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_bank_accounts`
--

DROP TABLE IF EXISTS `finance_bank_accounts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_bank_accounts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_key` varchar(80) NOT NULL,
  `scope_type` enum('unit','province') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `issuer_name` varchar(180) NOT NULL,
  `account_name_cipher` longtext NOT NULL,
  `sort_code_cipher` longtext NOT NULL,
  `account_number_cipher` longtext NOT NULL,
  `sort_code_mask` varchar(30) NOT NULL,
  `account_number_mask` varchar(50) NOT NULL,
  `updated_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_finance_bank_scope` (`scope_key`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `finance_bank_accounts_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `finance_bank_accounts_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_bank_accounts_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_bank_accounts`
--

LOCK TABLES `finance_bank_accounts` WRITE;
/*!40000 ALTER TABLE `finance_bank_accounts` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_bank_accounts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_cash_entries`
--

DROP TABLE IF EXISTS `finance_cash_entries`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_cash_entries` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `ledger_entry_id` bigint(20) unsigned DEFAULT NULL,
  `fund_id` bigint(20) unsigned DEFAULT NULL,
  `direction` enum('in','out') NOT NULL,
  `category` enum('event_payment','event_refund','subscription_payment','opening_balance','donation','purchase_bill','expense_claim','charity_disbursement','other') NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `effective_at` datetime NOT NULL,
  `source_type` varchar(40) DEFAULT NULL,
  `source_id` bigint(20) unsigned DEFAULT NULL,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_cash_ledger` (`ledger_entry_id`),
  KEY `idx_cash_unit` (`unit_id`,`effective_at`,`id`),
  KEY `idx_cash_fund` (`fund_id`,`effective_at`,`id`),
  KEY `province_id` (`province_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `finance_cash_entries_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `finance_cash_entries_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_cash_entries_ibfk_3` FOREIGN KEY (`ledger_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `finance_cash_entries_ibfk_4` FOREIGN KEY (`fund_id`) REFERENCES `finance_funds` (`id`),
  CONSTRAINT `finance_cash_entries_ibfk_5` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` > 0)
) ENGINE=InnoDB AUTO_INCREMENT=69 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_cash_entries`
--

LOCK TABLES `finance_cash_entries` WRITE;
/*!40000 ALTER TABLE `finance_cash_entries` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_cash_entries` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER finance_cash_no_update BEFORE UPDATE ON finance_cash_entries FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Cash entries are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER finance_cash_no_delete BEFORE DELETE ON finance_cash_entries FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Cash entries are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `finance_credit_notes`
--

DROP TABLE IF EXISTS `finance_credit_notes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_credit_notes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` bigint(20) unsigned NOT NULL,
  `issuer_scope_key` varchar(80) NOT NULL,
  `credit_number` varchar(60) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `reason` varchar(500) NOT NULL,
  `ledger_entry_id` bigint(20) unsigned NOT NULL,
  `snapshot_cipher` longtext NOT NULL,
  `snapshot_hash` char(64) NOT NULL,
  `issued_by` bigint(20) unsigned NOT NULL,
  `issued_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_credit_scope_number` (`issuer_scope_key`,`credit_number`),
  KEY `idx_credit_invoice` (`invoice_id`,`id`),
  KEY `ledger_entry_id` (`ledger_entry_id`),
  KEY `issued_by` (`issued_by`),
  CONSTRAINT `finance_credit_notes_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `finance_invoices` (`id`),
  CONSTRAINT `finance_credit_notes_ibfk_2` FOREIGN KEY (`ledger_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `finance_credit_notes_ibfk_3` FOREIGN KEY (`issued_by`) REFERENCES `users` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` > 0)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_credit_notes`
--

LOCK TABLES `finance_credit_notes` WRITE;
/*!40000 ALTER TABLE `finance_credit_notes` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_credit_notes` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER credit_note_no_update BEFORE UPDATE ON finance_credit_notes FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Credit notes are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER credit_note_no_delete BEFORE DELETE ON finance_credit_notes FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Credit notes are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `finance_expense_items`
--

DROP TABLE IF EXISTS `finance_expense_items`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_expense_items` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `item_type` enum('purchase_bill','expense_claim') NOT NULL,
  `claimant_user_id` bigint(20) unsigned DEFAULT NULL,
  `claimant_name` varchar(180) DEFAULT NULL,
  `supplier` varchar(180) DEFAULT NULL,
  `description` varchar(500) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `fund_id` bigint(20) unsigned DEFAULT NULL,
  `state` enum('draft','submitted','approved','paid','rejected') NOT NULL DEFAULT 'draft',
  `finance_note_cipher` longtext DEFAULT NULL,
  `submitted_by` bigint(20) unsigned DEFAULT NULL,
  `submitted_at` datetime DEFAULT NULL,
  `approved_by` bigint(20) unsigned DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `rejected_by` bigint(20) unsigned DEFAULT NULL,
  `rejected_at` datetime DEFAULT NULL,
  `paid_by` bigint(20) unsigned DEFAULT NULL,
  `paid_at` datetime DEFAULT NULL,
  `ledger_entry_id` bigint(20) unsigned DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_expense_unit` (`unit_id`,`state`,`id`),
  KEY `province_id` (`province_id`),
  KEY `claimant_user_id` (`claimant_user_id`),
  KEY `fund_id` (`fund_id`),
  KEY `submitted_by` (`submitted_by`),
  KEY `approved_by` (`approved_by`),
  KEY `rejected_by` (`rejected_by`),
  KEY `paid_by` (`paid_by`),
  KEY `ledger_entry_id` (`ledger_entry_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `finance_expense_items_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `finance_expense_items_ibfk_10` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `finance_expense_items_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_expense_items_ibfk_3` FOREIGN KEY (`claimant_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `finance_expense_items_ibfk_4` FOREIGN KEY (`fund_id`) REFERENCES `finance_funds` (`id`),
  CONSTRAINT `finance_expense_items_ibfk_5` FOREIGN KEY (`submitted_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `finance_expense_items_ibfk_6` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `finance_expense_items_ibfk_7` FOREIGN KEY (`rejected_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `finance_expense_items_ibfk_8` FOREIGN KEY (`paid_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `finance_expense_items_ibfk_9` FOREIGN KEY (`ledger_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` > 0)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_expense_items`
--

LOCK TABLES `finance_expense_items` WRITE;
/*!40000 ALTER TABLE `finance_expense_items` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_expense_items` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_expense_receipts`
--

DROP TABLE IF EXISTS `finance_expense_receipts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_expense_receipts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `expense_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `storage_key` char(64) NOT NULL,
  `original_filename` varchar(180) NOT NULL,
  `mime_type` varchar(100) NOT NULL,
  `byte_size` bigint(20) unsigned NOT NULL,
  `sha256` char(64) NOT NULL,
  `uploaded_by` bigint(20) unsigned NOT NULL,
  `uploaded_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_expense_storage` (`storage_key`),
  KEY `idx_expense_receipt` (`expense_id`,`id`),
  KEY `unit_id` (`unit_id`),
  KEY `uploaded_by` (`uploaded_by`),
  CONSTRAINT `finance_expense_receipts_ibfk_1` FOREIGN KEY (`expense_id`) REFERENCES `finance_expense_items` (`id`),
  CONSTRAINT `finance_expense_receipts_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_expense_receipts_ibfk_3` FOREIGN KEY (`uploaded_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_expense_receipts`
--

LOCK TABLES `finance_expense_receipts` WRITE;
/*!40000 ALTER TABLE `finance_expense_receipts` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_expense_receipts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_funds`
--

DROP TABLE IF EXISTS `finance_funds`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_funds` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `name` varchar(160) NOT NULL,
  `fund_type` enum('operating','charity_designated') NOT NULL DEFAULT 'operating',
  `purpose` varchar(500) DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_finance_fund` (`unit_id`,`name`),
  KEY `idx_finance_fund_scope` (`unit_id`,`fund_type`,`active`),
  KEY `province_id` (`province_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `finance_funds_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `finance_funds_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_funds_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_funds`
--

LOCK TABLES `finance_funds` WRITE;
/*!40000 ALTER TABLE `finance_funds` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_funds` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_invoice_events`
--

DROP TABLE IF EXISTS `finance_invoice_events`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_invoice_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` bigint(20) unsigned NOT NULL,
  `event_key` varchar(50) NOT NULL,
  `actor_id` bigint(20) unsigned NOT NULL,
  `details_json` varchar(1000) DEFAULT NULL,
  `occurred_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_invoice_event` (`invoice_id`,`id`),
  KEY `actor_id` (`actor_id`),
  CONSTRAINT `finance_invoice_events_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `finance_invoices` (`id`),
  CONSTRAINT `finance_invoice_events_ibfk_2` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_invoice_events`
--

LOCK TABLES `finance_invoice_events` WRITE;
/*!40000 ALTER TABLE `finance_invoice_events` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_invoice_events` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_invoice_issue_snapshots`
--

DROP TABLE IF EXISTS `finance_invoice_issue_snapshots`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_invoice_issue_snapshots` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` bigint(20) unsigned NOT NULL,
  `snapshot_cipher` longtext NOT NULL,
  `snapshot_hash` char(64) NOT NULL,
  `issued_by` bigint(20) unsigned NOT NULL,
  `issued_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_invoice_issue_snapshot` (`invoice_id`),
  KEY `issued_by` (`issued_by`),
  CONSTRAINT `finance_invoice_issue_snapshots_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `finance_invoices` (`id`),
  CONSTRAINT `finance_invoice_issue_snapshots_ibfk_2` FOREIGN KEY (`issued_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_invoice_issue_snapshots`
--

LOCK TABLES `finance_invoice_issue_snapshots` WRITE;
/*!40000 ALTER TABLE `finance_invoice_issue_snapshots` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_invoice_issue_snapshots` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER invoice_snapshot_no_update BEFORE UPDATE ON finance_invoice_issue_snapshots FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Issued invoice snapshots are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER invoice_snapshot_no_delete BEFORE DELETE ON finance_invoice_issue_snapshots FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Issued invoice snapshots are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `finance_invoice_lines`
--

DROP TABLE IF EXISTS `finance_invoice_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_invoice_lines` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` bigint(20) unsigned NOT NULL,
  `line_number` smallint(5) unsigned NOT NULL,
  `description` varchar(500) NOT NULL,
  `quantity` decimal(10,2) NOT NULL DEFAULT 1.00,
  `unit_price` decimal(12,2) NOT NULL,
  `vat_rate` decimal(5,2) NOT NULL DEFAULT 0.00,
  `net_amount` decimal(12,2) NOT NULL,
  `vat_amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `line_total` decimal(12,2) NOT NULL,
  `ledger_entry_id` bigint(20) unsigned DEFAULT NULL,
  `source_type` enum('booking_charge','subscription_charge','manual_charge') NOT NULL,
  `source_id` bigint(20) unsigned DEFAULT NULL,
  `approved_by` bigint(20) unsigned DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_invoice_line` (`invoice_id`,`line_number`),
  KEY `idx_invoice_line_ledger` (`ledger_entry_id`),
  KEY `approved_by` (`approved_by`),
  CONSTRAINT `finance_invoice_lines_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `finance_invoices` (`id`),
  CONSTRAINT `finance_invoice_lines_ibfk_2` FOREIGN KEY (`ledger_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `finance_invoice_lines_ibfk_3` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `CONSTRAINT_1` CHECK (`quantity` > 0),
  CONSTRAINT `CONSTRAINT_2` CHECK (`vat_rate` >= 0 and `vat_rate` <= 100),
  CONSTRAINT `CONSTRAINT_3` CHECK (`line_total` = `net_amount` + `vat_amount`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_invoice_lines`
--

LOCK TABLES `finance_invoice_lines` WRITE;
/*!40000 ALTER TABLE `finance_invoice_lines` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_invoice_lines` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_invoice_mailings`
--

DROP TABLE IF EXISTS `finance_invoice_mailings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_invoice_mailings` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` bigint(20) unsigned NOT NULL,
  `mail_queue_id` bigint(20) unsigned NOT NULL,
  `recipient` varchar(254) NOT NULL,
  `queued_by` bigint(20) unsigned NOT NULL,
  `queued_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_invoice_mail_queue` (`mail_queue_id`),
  KEY `invoice_id` (`invoice_id`),
  KEY `queued_by` (`queued_by`),
  CONSTRAINT `finance_invoice_mailings_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `finance_invoices` (`id`),
  CONSTRAINT `finance_invoice_mailings_ibfk_2` FOREIGN KEY (`mail_queue_id`) REFERENCES `outbound_mail_queue` (`id`),
  CONSTRAINT `finance_invoice_mailings_ibfk_3` FOREIGN KEY (`queued_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_invoice_mailings`
--

LOCK TABLES `finance_invoice_mailings` WRITE;
/*!40000 ALTER TABLE `finance_invoice_mailings` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_invoice_mailings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_invoice_payment_allocations`
--

DROP TABLE IF EXISTS `finance_invoice_payment_allocations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_invoice_payment_allocations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` bigint(20) unsigned NOT NULL,
  `payment_entry_id` bigint(20) unsigned NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `allocated_by` bigint(20) unsigned NOT NULL,
  `allocated_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_invoice_payment` (`invoice_id`,`payment_entry_id`),
  KEY `payment_entry_id` (`payment_entry_id`),
  KEY `allocated_by` (`allocated_by`),
  CONSTRAINT `finance_invoice_payment_allocations_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `finance_invoices` (`id`),
  CONSTRAINT `finance_invoice_payment_allocations_ibfk_2` FOREIGN KEY (`payment_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `finance_invoice_payment_allocations_ibfk_3` FOREIGN KEY (`allocated_by`) REFERENCES `users` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` > 0)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_invoice_payment_allocations`
--

LOCK TABLES `finance_invoice_payment_allocations` WRITE;
/*!40000 ALTER TABLE `finance_invoice_payment_allocations` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_invoice_payment_allocations` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_invoices`
--

DROP TABLE IF EXISTS `finance_invoices`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_invoices` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `scope_type` enum('unit','province') NOT NULL DEFAULT 'unit',
  `issuer_scope_key` varchar(80) DEFAULT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `invoice_number` varchar(60) DEFAULT NULL,
  `person_id` bigint(20) unsigned DEFAULT NULL,
  `booking_id` bigint(20) unsigned DEFAULT NULL,
  `recipient_name` varchar(220) NOT NULL DEFAULT '',
  `recipient_email` varchar(254) DEFAULT NULL,
  `issued_on` date DEFAULT NULL,
  `due_on` date DEFAULT NULL,
  `total` decimal(12,2) NOT NULL DEFAULT 0.00,
  `currency_code` char(3) NOT NULL DEFAULT 'GBP',
  `replaces_invoice_id` bigint(20) unsigned DEFAULT NULL,
  `status` enum('draft','issued','partly_paid','paid','voided','credited') NOT NULL DEFAULT 'draft',
  `created_by` bigint(20) unsigned NOT NULL,
  `issued_by` bigint(20) unsigned DEFAULT NULL,
  `issued_at` datetime DEFAULT NULL,
  `voided_by` bigint(20) unsigned DEFAULT NULL,
  `voided_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_invoice_scope_number` (`issuer_scope_key`,`invoice_number`),
  KEY `person_id` (`person_id`),
  KEY `created_by` (`created_by`),
  KEY `idx_invoice_unit` (`unit_id`),
  KEY `idx_invoice_scope` (`issuer_scope_key`,`status`,`id`),
  KEY `idx_invoice_booking` (`booking_id`),
  KEY `fk_invoice_province` (`province_id`),
  KEY `fk_invoice_issuer` (`issued_by`),
  KEY `fk_invoice_voider` (`voided_by`),
  KEY `fk_invoice_replacement` (`replaces_invoice_id`),
  CONSTRAINT `finance_invoices_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_invoices_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `finance_invoices_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_invoice_booking` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`),
  CONSTRAINT `fk_invoice_issuer` FOREIGN KEY (`issued_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_invoice_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `fk_invoice_replacement` FOREIGN KEY (`replaces_invoice_id`) REFERENCES `finance_invoices` (`id`),
  CONSTRAINT `fk_invoice_voider` FOREIGN KEY (`voided_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_invoices`
--

LOCK TABLES `finance_invoices` WRITE;
/*!40000 ALTER TABLE `finance_invoices` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_invoices` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_ledger_entries`
--

DROP TABLE IF EXISTS `finance_ledger_entries`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_ledger_entries` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `meeting_id` bigint(20) unsigned DEFAULT NULL,
  `booking_id` bigint(20) unsigned DEFAULT NULL,
  `person_id` bigint(20) unsigned DEFAULT NULL,
  `member_id` bigint(20) unsigned DEFAULT NULL,
  `entry_type` enum('charge','adjustment','exemption','payment','refund','reversal') NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `balance_delta` decimal(12,2) NOT NULL,
  `original_entry_id` bigint(20) unsigned DEFAULT NULL,
  `effective_at` datetime NOT NULL,
  `method` varchar(50) DEFAULT NULL,
  `safe_reference` varchar(100) DEFAULT NULL,
  `finance_note_cipher` longtext DEFAULT NULL,
  `source` enum('legacy','officer','reconciliation') NOT NULL DEFAULT 'officer',
  `source_type` varchar(40) DEFAULT NULL,
  `source_id` bigint(20) unsigned DEFAULT NULL,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_finance_reversal` (`original_entry_id`),
  KEY `idx_finance_booking` (`booking_id`,`id`),
  KEY `idx_finance_event` (`meeting_id`,`effective_at`,`id`),
  KEY `idx_finance_unit` (`unit_id`,`effective_at`,`id`),
  KEY `province_id` (`province_id`),
  KEY `created_by` (`created_by`),
  KEY `idx_finance_person` (`unit_id`,`person_id`,`effective_at`,`id`),
  KEY `idx_finance_source` (`unit_id`,`source_type`,`source_id`),
  KEY `fk_finance_person` (`person_id`),
  KEY `fk_finance_member` (`member_id`),
  CONSTRAINT `finance_ledger_entries_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `finance_ledger_entries_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_ledger_entries_ibfk_3` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`),
  CONSTRAINT `finance_ledger_entries_ibfk_4` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`),
  CONSTRAINT `finance_ledger_entries_ibfk_5` FOREIGN KEY (`original_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `finance_ledger_entries_ibfk_6` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_finance_member` FOREIGN KEY (`member_id`) REFERENCES `unit_members` (`id`),
  CONSTRAINT `fk_finance_person` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` > 0),
  CONSTRAINT `CONSTRAINT_2` CHECK (`entry_type` in ('charge','refund') and `balance_delta` > 0 or `entry_type` in ('exemption','payment') and `balance_delta` < 0 or `entry_type` in ('adjustment','reversal'))
) ENGINE=InnoDB AUTO_INCREMENT=185 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_ledger_entries`
--

LOCK TABLES `finance_ledger_entries` WRITE;
/*!40000 ALTER TABLE `finance_ledger_entries` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_ledger_entries` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER finance_entry_no_update BEFORE UPDATE ON finance_ledger_entries FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Finance ledger entries are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER finance_entry_no_delete BEFORE DELETE ON finance_ledger_entries FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Finance ledger entries are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `finance_opening_balances`
--

DROP TABLE IF EXISTS `finance_opening_balances`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_opening_balances` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `as_of_date` date NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `balance_kind` enum('amount_due','credit') NOT NULL,
  `ledger_entry_id` bigint(20) unsigned NOT NULL,
  `reason` varchar(500) NOT NULL,
  `approved_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_opening_balance` (`unit_id`,`person_id`,`as_of_date`),
  KEY `person_id` (`person_id`),
  KEY `ledger_entry_id` (`ledger_entry_id`),
  KEY `approved_by` (`approved_by`),
  CONSTRAINT `finance_opening_balances_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_opening_balances_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `finance_opening_balances_ibfk_3` FOREIGN KEY (`ledger_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `finance_opening_balances_ibfk_4` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` > 0)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_opening_balances`
--

LOCK TABLES `finance_opening_balances` WRITE;
/*!40000 ALTER TABLE `finance_opening_balances` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_opening_balances` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `finance_year_end_snapshots`
--

DROP TABLE IF EXISTS `finance_year_end_snapshots`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `finance_year_end_snapshots` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `period_start` date NOT NULL,
  `period_end` date NOT NULL,
  `snapshot_number` int(10) unsigned NOT NULL,
  `status` enum('draft','reviewed','locked') NOT NULL DEFAULT 'draft',
  `payload_json` longtext NOT NULL,
  `source_hash` char(64) NOT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  `locked_by` bigint(20) unsigned DEFAULT NULL,
  `locked_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_year_snapshot` (`unit_id`,`period_start`,`period_end`,`snapshot_number`),
  KEY `idx_year_snapshot` (`unit_id`,`period_end`,`status`),
  KEY `province_id` (`province_id`),
  KEY `created_by` (`created_by`),
  KEY `reviewed_by` (`reviewed_by`),
  KEY `locked_by` (`locked_by`),
  CONSTRAINT `finance_year_end_snapshots_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `finance_year_end_snapshots_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `finance_year_end_snapshots_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `finance_year_end_snapshots_ibfk_4` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `finance_year_end_snapshots_ibfk_5` FOREIGN KEY (`locked_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `CONSTRAINT_1` CHECK (`period_start` <= `period_end`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `finance_year_end_snapshots`
--

LOCK TABLES `finance_year_end_snapshots` WRITE;
/*!40000 ALTER TABLE `finance_year_end_snapshots` DISABLE KEYS */;
/*!40000 ALTER TABLE `finance_year_end_snapshots` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `guest_contacts`
--

DROP TABLE IF EXISTS `guest_contacts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `guest_contacts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `sponsor_email` varchar(254) NOT NULL,
  `salutation` varchar(30) NOT NULL,
  `first_name` varchar(100) NOT NULL,
  `surname` varchar(100) NOT NULL,
  `email` varchar(254) NOT NULL,
  `masonic_rank` varchar(150) DEFAULT NULL,
  `provincial_rank` varchar(150) DEFAULT NULL,
  `grand_rank` varchar(150) DEFAULT NULL,
  `lodge_name` varchar(150) DEFAULT NULL,
  `lodge_number` varchar(30) DEFAULT NULL,
  `dietary_requirements` text DEFAULT NULL,
  `allergy_details` text DEFAULT NULL,
  `consented_at` datetime NOT NULL,
  `consent_text` text DEFAULT NULL,
  `consent_version` varchar(40) DEFAULT NULL,
  `source_booking_id` bigint(20) unsigned DEFAULT NULL,
  `retention_expires_at` datetime DEFAULT NULL,
  `last_booked_at` datetime NOT NULL,
  `consent_withdrawn_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_guest_contact_unit_sponsor` (`unit_id`,`sponsor_email`,`email`),
  KEY `idx_guest_contact_email` (`email`),
  KEY `idx_guest_contact_consent` (`consent_withdrawn_at`,`last_booked_at`),
  KEY `idx_guest_contacts_unit` (`unit_id`),
  KEY `idx_guest_contact_expiry` (`unit_id`,`retention_expires_at`),
  KEY `idx_guest_contact_source` (`source_booking_id`),
  CONSTRAINT `fk_guest_contact_source_booking` FOREIGN KEY (`source_booking_id`) REFERENCES `bookings` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_guest_contacts_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `guest_contacts`
--

LOCK TABLES `guest_contacts` WRITE;
/*!40000 ALTER TABLE `guest_contacts` DISABLE KEYS */;
/*!40000 ALTER TABLE `guest_contacts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `guest_directory_rate_limits`
--

DROP TABLE IF EXISTS `guest_directory_rate_limits`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `guest_directory_rate_limits` (
  `unit_id` bigint(20) unsigned NOT NULL,
  `bucket` char(64) NOT NULL,
  `attempts` smallint(5) unsigned NOT NULL DEFAULT 0,
  `window_started` datetime NOT NULL,
  PRIMARY KEY (`unit_id`,`bucket`),
  CONSTRAINT `fk_guest_directory_rate_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `guest_directory_rate_limits`
--

LOCK TABLES `guest_directory_rate_limits` WRITE;
/*!40000 ALTER TABLE `guest_directory_rate_limits` DISABLE KEYS */;
/*!40000 ALTER TABLE `guest_directory_rate_limits` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `guest_invitations`
--

DROP TABLE IF EXISTS `guest_invitations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `guest_invitations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `guest_contact_id` bigint(20) unsigned NOT NULL,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `status` enum('queued','sent','failed') NOT NULL,
  `sent_at` datetime DEFAULT NULL,
  `failure_message` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_guest_meeting_invitation` (`guest_contact_id`,`meeting_id`),
  KEY `fk_guest_invitation_meeting` (`meeting_id`),
  CONSTRAINT `fk_guest_invitation_contact` FOREIGN KEY (`guest_contact_id`) REFERENCES `guest_contacts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_guest_invitation_meeting` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `guest_invitations`
--

LOCK TABLES `guest_invitations` WRITE;
/*!40000 ALTER TABLE `guest_invitations` DISABLE KEYS */;
/*!40000 ALTER TABLE `guest_invitations` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `guests`
--

DROP TABLE IF EXISTS `guests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `guests` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `booking_id` bigint(20) unsigned NOT NULL,
  `salutation` varchar(30) NOT NULL,
  `first_name` varchar(100) NOT NULL,
  `surname` varchar(100) NOT NULL,
  `email` varchar(254) DEFAULT NULL,
  `retention_consent` tinyint(1) NOT NULL DEFAULT 0,
  `guest_contact_id` bigint(20) unsigned DEFAULT NULL,
  `masonic_rank` varchar(150) DEFAULT NULL,
  `provincial_rank` varchar(150) DEFAULT NULL,
  `grand_rank` varchar(150) DEFAULT NULL,
  `lodge_name` varchar(150) DEFAULT NULL,
  `lodge_number` varchar(30) DEFAULT NULL,
  `dining` tinyint(1) NOT NULL DEFAULT 0,
  `dietary_requirements` text DEFAULT NULL,
  `allergy_details` text DEFAULT NULL,
  `dining_charge` decimal(10,2) NOT NULL DEFAULT 0.00,
  `arrived` tinyint(1) NOT NULL DEFAULT 0,
  `arrived_at` datetime DEFAULT NULL,
  `checked_in_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_guest_booking` (`booking_id`),
  KEY `idx_guest_email` (`email`),
  KEY `idx_guest_contact` (`guest_contact_id`),
  KEY `idx_guest_arrival` (`arrived`,`arrived_at`),
  KEY `fk_guest_checked_in_by` (`checked_in_by`),
  CONSTRAINT `fk_guest_booking` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_guest_checked_in_by` FOREIGN KEY (`checked_in_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_guest_contact` FOREIGN KEY (`guest_contact_id`) REFERENCES `guest_contacts` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `guests`
--

LOCK TABLES `guests` WRITE;
/*!40000 ALTER TABLE `guests` DISABLE KEYS */;
/*!40000 ALTER TABLE `guests` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `historical_migration_reconciliation`
--

DROP TABLE IF EXISTS `historical_migration_reconciliation`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `historical_migration_reconciliation` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `filename` varchar(255) NOT NULL,
  `checksum` char(64) NOT NULL,
  `status` enum('present_unverified','reconciled','not_applied') NOT NULL DEFAULT 'present_unverified',
  `notes` text DEFAULT NULL,
  `reconciled_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_historical_filename` (`filename`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `historical_migration_reconciliation`
--

LOCK TABLES `historical_migration_reconciliation` WRITE;
/*!40000 ALTER TABLE `historical_migration_reconciliation` DISABLE KEYS */;
/*!40000 ALTER TABLE `historical_migration_reconciliation` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `import_conflicts`
--

DROP TABLE IF EXISTS `import_conflicts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `import_conflicts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `import_run_id` bigint(20) unsigned NOT NULL,
  `source_table` varchar(100) NOT NULL,
  `source_id` varchar(191) NOT NULL,
  `conflict_type` varchar(100) NOT NULL,
  `details_json` longtext DEFAULT NULL,
  `resolution` varchar(100) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `fk_import_conflict_run` (`import_run_id`),
  CONSTRAINT `fk_import_conflict_run` FOREIGN KEY (`import_run_id`) REFERENCES `import_runs` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `import_conflicts`
--

LOCK TABLES `import_conflicts` WRITE;
/*!40000 ALTER TABLE `import_conflicts` DISABLE KEYS */;
/*!40000 ALTER TABLE `import_conflicts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `import_id_map`
--

DROP TABLE IF EXISTS `import_id_map`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `import_id_map` (
  `source_installation_id` bigint(20) unsigned NOT NULL,
  `source_table` varchar(100) NOT NULL,
  `source_id` varchar(191) NOT NULL,
  `destination_table` varchar(100) NOT NULL,
  `destination_id` varchar(191) NOT NULL,
  `natural_key_hash` char(64) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`source_installation_id`,`source_table`,`source_id`),
  KEY `idx_import_destination` (`destination_table`,`destination_id`),
  CONSTRAINT `fk_import_map_source` FOREIGN KEY (`source_installation_id`) REFERENCES `source_installations` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `import_id_map`
--

LOCK TABLES `import_id_map` WRITE;
/*!40000 ALTER TABLE `import_id_map` DISABLE KEYS */;
/*!40000 ALTER TABLE `import_id_map` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `import_runs`
--

DROP TABLE IF EXISTS `import_runs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `import_runs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `source_installation_id` bigint(20) unsigned NOT NULL,
  `dry_run` tinyint(1) NOT NULL DEFAULT 1,
  `status` enum('running','complete','failed') NOT NULL DEFAULT 'running',
  `started_at` datetime NOT NULL DEFAULT current_timestamp(),
  `completed_at` datetime DEFAULT NULL,
  `report_json` longtext DEFAULT NULL,
  `error_message` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_import_run_source` (`source_installation_id`),
  CONSTRAINT `fk_import_run_source` FOREIGN KEY (`source_installation_id`) REFERENCES `source_installations` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `import_runs`
--

LOCK TABLES `import_runs` WRITE;
/*!40000 ALTER TABLE `import_runs` DISABLE KEYS */;
/*!40000 ALTER TABLE `import_runs` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `invoice_issuer_settings`
--

DROP TABLE IF EXISTS `invoice_issuer_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `invoice_issuer_settings` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `issuer_scope_key` varchar(80) NOT NULL,
  `scope_type` enum('unit','province') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `issuer_name` varchar(180) NOT NULL,
  `issuer_address` varchar(1000) NOT NULL,
  `issuer_email` varchar(254) DEFAULT NULL,
  `registration_number` varchar(100) DEFAULT NULL,
  `vat_treatment` enum('not_registered','registered','outside_scope') NOT NULL DEFAULT 'not_registered',
  `vat_number` varchar(80) DEFAULT NULL,
  `default_vat_rate` decimal(5,2) NOT NULL DEFAULT 0.00,
  `invoice_prefix` varchar(30) NOT NULL DEFAULT 'INV-',
  `invoice_padding` tinyint(3) unsigned NOT NULL DEFAULT 5,
  `next_invoice_number` bigint(20) unsigned NOT NULL DEFAULT 1,
  `credit_prefix` varchar(30) NOT NULL DEFAULT 'CN-',
  `credit_padding` tinyint(3) unsigned NOT NULL DEFAULT 5,
  `next_credit_number` bigint(20) unsigned NOT NULL DEFAULT 1,
  `payment_terms_days` smallint(5) unsigned NOT NULL DEFAULT 14,
  `payment_terms_text` varchar(1000) DEFAULT NULL,
  `payment_instructions` varchar(2000) DEFAULT NULL,
  `updated_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_invoice_issuer_scope` (`issuer_scope_key`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `invoice_issuer_settings_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `invoice_issuer_settings_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `invoice_issuer_settings_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`invoice_padding` between 1 and 12),
  CONSTRAINT `CONSTRAINT_2` CHECK (`credit_padding` between 1 and 12),
  CONSTRAINT `CONSTRAINT_3` CHECK (`default_vat_rate` >= 0 and `default_vat_rate` <= 100)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `invoice_issuer_settings`
--

LOCK TABLES `invoice_issuer_settings` WRITE;
/*!40000 ALTER TABLE `invoice_issuer_settings` DISABLE KEYS */;
/*!40000 ALTER TABLE `invoice_issuer_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `kiosk_sessions`
--

DROP TABLE IF EXISTS `kiosk_sessions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `kiosk_sessions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `token_hash` char(64) NOT NULL,
  `user_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `expires_at` datetime NOT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `token_hash` (`token_hash`),
  KEY `idx_kiosk_expiry` (`expires_at`),
  KEY `user_id` (`user_id`),
  KEY `unit_id` (`unit_id`),
  CONSTRAINT `kiosk_sessions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `kiosk_sessions_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `kiosk_sessions`
--

LOCK TABLES `kiosk_sessions` WRITE;
/*!40000 ALTER TABLE `kiosk_sessions` DISABLE KEYS */;
/*!40000 ALTER TABLE `kiosk_sessions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `lodge_settings`
--

DROP TABLE IF EXISTS `lodge_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `lodge_settings` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `lodge_name` varchar(150) NOT NULL,
  `lodge_number` varchar(30) NOT NULL,
  `lodge_short_name` varchar(100) DEFAULT NULL,
  `order_name` varchar(150) DEFAULT NULL,
  `province_name` varchar(200) DEFAULT NULL,
  `lodge_logo_url` text DEFAULT NULL,
  `lodge_honours_logo_url` text DEFAULT NULL,
  `province_logo_url` text DEFAULT NULL,
  `order_logo_url` text DEFAULT NULL,
  `companion_order_logo_url` text DEFAULT NULL,
  `charity_logo_url` text DEFAULT NULL,
  `primary_colour` varchar(7) NOT NULL DEFAULT '#990033',
  `secondary_colour` varchar(7) NOT NULL DEFAULT '#122849',
  `accent_colour` varchar(7) NOT NULL DEFAULT '#C7A646',
  `background_colour` varchar(7) NOT NULL DEFAULT '#F7F1E3',
  `panel_colour` varchar(7) NOT NULL DEFAULT '#FFFDFA',
  `text_colour` varchar(7) NOT NULL DEFAULT '#27231E',
  `heading_font` varchar(120) NOT NULL DEFAULT 'Georgia, serif',
  `body_font` varchar(120) NOT NULL DEFAULT 'system-ui, sans-serif',
  `browser_title` varchar(200) DEFAULT NULL,
  `favicon_url` text DEFAULT NULL,
  `secretary_email` varchar(254) DEFAULT NULL,
  `treasurer_email` varchar(254) DEFAULT NULL,
  `dining_steward_email` varchar(254) DEFAULT NULL,
  `director_of_ceremonies_email` varchar(254) DEFAULT NULL,
  `almoner_email` varchar(254) DEFAULT NULL,
  `general_email` varchar(254) DEFAULT NULL,
  `legal_contact_email` varchar(254) DEFAULT NULL,
  `email_display_name` varchar(150) DEFAULT NULL,
  `provincial_website_url` text DEFAULT NULL,
  `provincial_website_label` varchar(150) DEFAULT NULL,
  `order_website_url` text DEFAULT NULL,
  `order_website_label` varchar(150) DEFAULT NULL,
  `book_of_constitutions_url` text DEFAULT NULL,
  `bylaws_url` text DEFAULT NULL,
  `timezone` varchar(80) NOT NULL DEFAULT 'Europe/London',
  `currency_code` char(3) NOT NULL DEFAULT 'GBP',
  `booking_reference_prefix` varchar(30) DEFAULT NULL,
  `retention_meetings` int(10) unsigned NOT NULL DEFAULT 4,
  `retention_months` int(10) unsigned NOT NULL DEFAULT 18,
  `automatic_backup` tinyint(1) NOT NULL DEFAULT 1,
  `backup_retention_days` int(10) unsigned NOT NULL DEFAULT 30,
  `health_alert_email` varchar(254) DEFAULT NULL,
  `bank_account_name` varchar(150) DEFAULT NULL,
  `bank_sort_code` varchar(20) DEFAULT NULL,
  `bank_account_number` varchar(40) DEFAULT NULL,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_lodge_settings_unit` (`unit_id`),
  KEY `fk_lodge_settings_user` (`updated_by`),
  KEY `idx_lodge_settings_unit` (`unit_id`),
  CONSTRAINT `fk_lodge_settings_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `fk_lodge_settings_user` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `lodge_settings`
--

LOCK TABLES `lodge_settings` WRITE;
/*!40000 ALTER TABLE `lodge_settings` DISABLE KEYS */;
INSERT INTO `lodge_settings` VALUES (1,134,'test','0000',NULL,'Craft','test',NULL,NULL,NULL,NULL,NULL,NULL,'#990033','#122849','#C7A646','#F7F1E3','#FFFDFA','#27231E','Georgia, serif','system-ui, sans-serif',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Europe/London','GBP','U134',4,18,1,30,NULL,NULL,NULL,NULL,1,'2026-09-28 16:50:44');
/*!40000 ALTER TABLE `lodge_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `login_challenges`
--

DROP TABLE IF EXISTS `login_challenges`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `login_challenges` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL,
  `code_hash` varchar(255) NOT NULL,
  `expires_at` datetime NOT NULL,
  `attempts` int(10) unsigned NOT NULL DEFAULT 0,
  `used_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_login_challenge_user` (`user_id`,`expires_at`),
  CONSTRAINT `fk_login_challenge_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `login_challenges`
--

LOCK TABLES `login_challenges` WRITE;
/*!40000 ALTER TABLE `login_challenges` DISABLE KEYS */;
/*!40000 ALTER TABLE `login_challenges` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `meeting_agenda_items`
--

DROP TABLE IF EXISTS `meeting_agenda_items`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meeting_agenda_items` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `agenda_id` bigint(20) unsigned NOT NULL,
  `logical_key` char(32) NOT NULL,
  `version_no` int(10) unsigned NOT NULL,
  `item_no` int(10) unsigned NOT NULL,
  `heading` varchar(220) NOT NULL,
  `body_text` text DEFAULT NULL,
  `proposer_person_id` bigint(20) unsigned DEFAULT NULL,
  `responsible_role` varchar(120) DEFAULT NULL,
  `resolution_text` text DEFAULT NULL,
  `sensitivity` enum('general','committee','welfare','finance') NOT NULL DEFAULT 'general',
  `approved_for_general` tinyint(1) NOT NULL DEFAULT 0,
  `item_status` enum('draft','approved','withdrawn') NOT NULL DEFAULT 'draft',
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_agenda_item_version` (`agenda_id`,`logical_key`,`version_no`),
  KEY `idx_agenda_items` (`agenda_id`,`version_no`,`item_no`),
  KEY `proposer_person_id` (`proposer_person_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `meeting_agenda_items_ibfk_1` FOREIGN KEY (`agenda_id`) REFERENCES `meeting_agendas` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_agenda_items_ibfk_2` FOREIGN KEY (`proposer_person_id`) REFERENCES `people` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_agenda_items_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meeting_agenda_items`
--

LOCK TABLES `meeting_agenda_items` WRITE;
/*!40000 ALTER TABLE `meeting_agenda_items` DISABLE KEYS */;
/*!40000 ALTER TABLE `meeting_agenda_items` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `meeting_agenda_template_items`
--

DROP TABLE IF EXISTS `meeting_agenda_template_items`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meeting_agenda_template_items` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `template_id` bigint(20) unsigned NOT NULL,
  `version_no` int(10) unsigned NOT NULL,
  `item_no` int(10) unsigned NOT NULL,
  `heading` varchar(220) NOT NULL,
  `item_type` enum('opening','minutes','matters','ceremony','motion','report','business','closing','other') NOT NULL DEFAULT 'business',
  `responsible_role` varchar(120) DEFAULT NULL,
  `resolution_placeholder` text DEFAULT NULL,
  `sensitivity` enum('general','committee','welfare','finance') NOT NULL DEFAULT 'general',
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_agenda_template_item` (`template_id`,`version_no`,`item_no`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `meeting_agenda_template_items_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `meeting_agenda_templates` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_agenda_template_items_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meeting_agenda_template_items`
--

LOCK TABLES `meeting_agenda_template_items` WRITE;
/*!40000 ALTER TABLE `meeting_agenda_template_items` DISABLE KEYS */;
/*!40000 ALTER TABLE `meeting_agenda_template_items` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `meeting_agenda_templates`
--

DROP TABLE IF EXISTS `meeting_agenda_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meeting_agenda_templates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('province','unit') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `name` varchar(160) NOT NULL,
  `order_key` varchar(40) NOT NULL DEFAULT 'craft',
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `current_version` int(10) unsigned NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `scope_key` varchar(90) GENERATED ALWAYS AS (concat(`scope_type`,':',`province_id`,':',ifnull(`unit_id`,0))) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_agenda_template` (`scope_key`,`name`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `meeting_agenda_templates_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_agenda_templates_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_agenda_templates_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_agenda_template_scope` CHECK (`scope_type` = 'province' and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meeting_agenda_templates`
--

LOCK TABLES `meeting_agenda_templates` WRITE;
/*!40000 ALTER TABLE `meeting_agenda_templates` DISABLE KEYS */;
/*!40000 ALTER TABLE `meeting_agenda_templates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `meeting_agendas`
--

DROP TABLE IF EXISTS `meeting_agendas`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meeting_agendas` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `scope_type` enum('province','unit') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `template_id` bigint(20) unsigned DEFAULT NULL,
  `title` varchar(220) NOT NULL,
  `status` enum('draft','review','approved','superseded','archived') NOT NULL DEFAULT 'draft',
  `version_no` int(10) unsigned NOT NULL DEFAULT 1,
  `approved_by` bigint(20) unsigned DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_meeting_agenda_scope` (`meeting_id`,`scope_type`,`province_id`,`unit_id`),
  KEY `idx_agenda_scope` (`scope_type`,`province_id`,`unit_id`,`status`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `template_id` (`template_id`),
  KEY `approved_by` (`approved_by`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `meeting_agendas_ibfk_1` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_agendas_ibfk_2` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_agendas_ibfk_3` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_agendas_ibfk_4` FOREIGN KEY (`template_id`) REFERENCES `meeting_agenda_templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_agendas_ibfk_5` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_agendas_ibfk_6` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meeting_agendas`
--

LOCK TABLES `meeting_agendas` WRITE;
/*!40000 ALTER TABLE `meeting_agendas` DISABLE KEYS */;
/*!40000 ALTER TABLE `meeting_agendas` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `meeting_menu`
--

DROP TABLE IF EXISTS `meeting_menu`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meeting_menu` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `course_name` varchar(100) NOT NULL,
  `dish` text NOT NULL,
  `vegetarian_alternative` text DEFAULT NULL,
  `vegan_alternative` text DEFAULT NULL,
  `pescetarian_alternative` text DEFAULT NULL,
  `kosher_alternative` text DEFAULT NULL,
  `halal_alternative` text DEFAULT NULL,
  `hindu_alternative` text DEFAULT NULL,
  `sikh_alternative` text DEFAULT NULL,
  `display_order` int(10) unsigned NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_menu_meeting` (`meeting_id`,`display_order`),
  CONSTRAINT `fk_menu_meeting` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meeting_menu`
--

LOCK TABLES `meeting_menu` WRITE;
/*!40000 ALTER TABLE `meeting_menu` DISABLE KEYS */;
/*!40000 ALTER TABLE `meeting_menu` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `meeting_minutes_actions`
--

DROP TABLE IF EXISTS `meeting_minutes_actions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meeting_minutes_actions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `snapshot_id` bigint(20) unsigned NOT NULL,
  `agenda_item_key` char(32) DEFAULT NULL,
  `title` varchar(250) NOT NULL,
  `responsible_role` varchar(80) NOT NULL,
  `due_at` datetime DEFAULT NULL,
  `status` enum('open','completed','cancelled') NOT NULL DEFAULT 'open',
  `action_task_id` bigint(20) unsigned DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `completed_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_minutes_action` (`snapshot_id`,`status`,`due_at`),
  KEY `action_task_id` (`action_task_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `meeting_minutes_actions_ibfk_1` FOREIGN KEY (`snapshot_id`) REFERENCES `meeting_publication_snapshots` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_minutes_actions_ibfk_2` FOREIGN KEY (`action_task_id`) REFERENCES `action_centre_tasks` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_minutes_actions_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meeting_minutes_actions`
--

LOCK TABLES `meeting_minutes_actions` WRITE;
/*!40000 ALTER TABLE `meeting_minutes_actions` DISABLE KEYS */;
/*!40000 ALTER TABLE `meeting_minutes_actions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `meeting_publication_recipients`
--

DROP TABLE IF EXISTS `meeting_publication_recipients`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meeting_publication_recipients` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `snapshot_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned DEFAULT NULL,
  `recipient_email` varchar(254) DEFAULT NULL,
  `audience_source` enum('unit_member','province_relationship','booking_attendee') NOT NULL,
  `notice_class` enum('essential','optional') NOT NULL DEFAULT 'essential',
  `delivery_method` enum('email','post','both','none') NOT NULL DEFAULT 'none',
  `email_eligible` tinyint(1) NOT NULL DEFAULT 0,
  `postal_eligible` tinyint(1) NOT NULL DEFAULT 0,
  `postal_address_cipher` mediumtext DEFAULT NULL,
  `postal_address_source` varchar(40) DEFAULT NULL,
  `postal_verified_at` datetime DEFAULT NULL,
  `delivery_issue` enum('missing_email','missing_address','preference_none') DEFAULT NULL,
  `mail_queue_id` bigint(20) unsigned DEFAULT NULL,
  `queued_at` datetime DEFAULT NULL,
  `sent_at` datetime DEFAULT NULL,
  `delivery_status` enum('pending','queued','sent','failed','suppressed') NOT NULL DEFAULT 'pending',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_publication_person` (`snapshot_id`,`person_id`),
  KEY `person_id` (`person_id`),
  KEY `mail_queue_id` (`mail_queue_id`),
  CONSTRAINT `meeting_publication_recipients_ibfk_1` FOREIGN KEY (`snapshot_id`) REFERENCES `meeting_publication_snapshots` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_publication_recipients_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_publication_recipients_ibfk_3` FOREIGN KEY (`mail_queue_id`) REFERENCES `outbound_mail_queue` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=77 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meeting_publication_recipients`
--

LOCK TABLES `meeting_publication_recipients` WRITE;
/*!40000 ALTER TABLE `meeting_publication_recipients` DISABLE KEYS */;
/*!40000 ALTER TABLE `meeting_publication_recipients` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `meeting_publication_snapshots`
--

DROP TABLE IF EXISTS `meeting_publication_snapshots`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meeting_publication_snapshots` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `agenda_id` bigint(20) unsigned NOT NULL,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `publication_type` enum('summons','minutes','minutes_correction','minutes_addendum') NOT NULL,
  `publication_no` int(10) unsigned NOT NULL,
  `amendment_no` int(10) unsigned NOT NULL DEFAULT 0,
  `parent_snapshot_id` bigint(20) unsigned DEFAULT NULL,
  `status` enum('approved','issued','review','confirmed','locked','archived') NOT NULL,
  `title` varchar(250) NOT NULL,
  `event_fingerprint` char(64) NOT NULL,
  `content_json` longtext NOT NULL,
  `document_id` bigint(20) unsigned DEFAULT NULL,
  `province_document_id` bigint(20) unsigned DEFAULT NULL,
  `document_version_id` bigint(20) unsigned DEFAULT NULL,
  `province_document_version_id` bigint(20) unsigned DEFAULT NULL,
  `approved_by` bigint(20) unsigned NOT NULL,
  `approved_at` datetime NOT NULL,
  `issued_at` datetime DEFAULT NULL,
  `confirmed_at` datetime DEFAULT NULL,
  `confirmed_meeting_id` bigint(20) unsigned DEFAULT NULL,
  `signed_off_by` bigint(20) unsigned DEFAULT NULL,
  `signed_off_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_publication_number` (`agenda_id`,`publication_type`,`publication_no`,`amendment_no`),
  KEY `idx_publication_meeting` (`meeting_id`,`publication_type`,`status`),
  KEY `parent_snapshot_id` (`parent_snapshot_id`),
  KEY `document_id` (`document_id`),
  KEY `province_document_id` (`province_document_id`),
  KEY `document_version_id` (`document_version_id`),
  KEY `province_document_version_id` (`province_document_version_id`),
  KEY `approved_by` (`approved_by`),
  KEY `confirmed_meeting_id` (`confirmed_meeting_id`),
  KEY `signed_off_by` (`signed_off_by`),
  CONSTRAINT `meeting_publication_snapshots_ibfk_1` FOREIGN KEY (`agenda_id`) REFERENCES `meeting_agendas` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_publication_snapshots_ibfk_10` FOREIGN KEY (`signed_off_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_publication_snapshots_ibfk_2` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `meeting_publication_snapshots_ibfk_3` FOREIGN KEY (`parent_snapshot_id`) REFERENCES `meeting_publication_snapshots` (`id`),
  CONSTRAINT `meeting_publication_snapshots_ibfk_4` FOREIGN KEY (`document_id`) REFERENCES `tenant_documents` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_publication_snapshots_ibfk_5` FOREIGN KEY (`province_document_id`) REFERENCES `province_documents` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_publication_snapshots_ibfk_6` FOREIGN KEY (`document_version_id`) REFERENCES `tenant_document_versions` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_publication_snapshots_ibfk_7` FOREIGN KEY (`province_document_version_id`) REFERENCES `province_document_versions` (`id`) ON DELETE SET NULL,
  CONSTRAINT `meeting_publication_snapshots_ibfk_8` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`),
  CONSTRAINT `meeting_publication_snapshots_ibfk_9` FOREIGN KEY (`confirmed_meeting_id`) REFERENCES `meetings` (`id`) ON DELETE SET NULL,
  CONSTRAINT `chk_publication_document` CHECK (`document_id` is null or `province_document_id` is null)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meeting_publication_snapshots`
--

LOCK TABLES `meeting_publication_snapshots` WRITE;
/*!40000 ALTER TABLE `meeting_publication_snapshots` DISABLE KEYS */;
/*!40000 ALTER TABLE `meeting_publication_snapshots` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER meeting_publication_no_update_locked BEFORE UPDATE ON meeting_publication_snapshots FOR EACH ROW SET NEW.status=IF(OLD.status='locked','locked',NEW.status), NEW.content_json=IF(OLD.status='locked',OLD.content_json,NEW.content_json), NEW.event_fingerprint=IF(OLD.status='locked',OLD.event_fingerprint,NEW.event_fingerprint) */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER meeting_publication_no_delete BEFORE DELETE ON meeting_publication_snapshots FOR EACH ROW
 SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Publication snapshots are append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `meetings`
--

DROP TABLE IF EXISTS `meetings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `meetings` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `programme_id` bigint(20) unsigned DEFAULT NULL,
  `event_slug` varchar(120) NOT NULL,
  `event_type` varchar(30) NOT NULL DEFAULT 'regular',
  `lodge_name` varchar(150) NOT NULL DEFAULT 'Your Lodge',
  `lodge_number` varchar(20) NOT NULL DEFAULT '0',
  `masonic_order` varchar(40) NOT NULL DEFAULT 'craft',
  `linked_event_group` varchar(100) DEFAULT NULL,
  `title` varchar(200) NOT NULL,
  `meeting_date` date NOT NULL,
  `meeting_start` datetime NOT NULL,
  `meeting_end` datetime DEFAULT NULL,
  `booking_deadline` datetime NOT NULL,
  `venue_name` varchar(200) NOT NULL,
  `venue_address` text DEFAULT NULL,
  `dining_capacity` int(10) unsigned NOT NULL DEFAULT 80,
  `member_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `visitor_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `special_event_enabled` tinyint(1) NOT NULL DEFAULT 0,
  `special_event_official_visits` tinyint(1) NOT NULL DEFAULT 0,
  `special_event_type` enum('none','ladies_evening','white_table','blue_table','other') NOT NULL DEFAULT 'none',
  `special_event_label` varchar(120) DEFAULT NULL,
  `special_event_description` text DEFAULT NULL,
  `raffle_enabled` tinyint(1) NOT NULL DEFAULT 0,
  `raffle_sales_unit` enum('ticket','strip') NOT NULL DEFAULT 'ticket',
  `raffle_ticket_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `raffle_max_per_booking` int(10) unsigned DEFAULT NULL,
  `raffle_description` varchar(500) DEFAULT NULL,
  `template_source_id` bigint(20) unsigned DEFAULT NULL,
  `summons_url` text DEFAULT NULL,
  `document_kind` varchar(12) NOT NULL DEFAULT 'summons',
  `toast_list_url` text DEFAULT NULL,
  `alms_collection_url` text DEFAULT NULL,
  `menu_note` text DEFAULT NULL,
  `bookings_open` tinyint(1) NOT NULL DEFAULT 1,
  `calendar_invite_enabled` tinyint(1) NOT NULL DEFAULT 0,
  `lifecycle_status` enum('draft','open','closed','completed','archived','cancelled') NOT NULL DEFAULT 'open',
  `test_mode` tinyint(1) NOT NULL DEFAULT 0,
  `archived` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_meeting_unit_slug` (`unit_id`,`event_slug`),
  KEY `idx_meeting_date` (`meeting_date`),
  KEY `idx_meeting_order` (`masonic_order`),
  KEY `idx_meeting_linked_group` (`linked_event_group`),
  KEY `idx_meeting_status` (`archived`,`bookings_open`),
  KEY `idx_meeting_lifecycle` (`lifecycle_status`,`meeting_date`),
  KEY `idx_meeting_public_booking` (`archived`,`bookings_open`,`lifecycle_status`,`booking_deadline`,`meeting_date`),
  KEY `idx_meeting_unit_public` (`unit_id`,`archived`,`bookings_open`,`lifecycle_status`,`booking_deadline`),
  KEY `idx_meeting_programme` (`programme_id`,`unit_id`),
  CONSTRAINT `fk_meeting_programme_unit` FOREIGN KEY (`programme_id`, `unit_id`) REFERENCES `event_programmes` (`id`, `unit_id`),
  CONSTRAINT `fk_meeting_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=132 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `meetings`
--

LOCK TABLES `meetings` WRITE;
/*!40000 ALTER TABLE `meetings` DISABLE KEYS */;
/*!40000 ALTER TABLE `meetings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `member_booking_links`
--

DROP TABLE IF EXISTS `member_booking_links`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `member_booking_links` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `person_id` bigint(20) unsigned NOT NULL,
  `booking_id` bigint(20) unsigned NOT NULL,
  `verified_by` bigint(20) unsigned NOT NULL,
  `verified_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_member_booking` (`booking_id`),
  KEY `idx_member_booking_person` (`person_id`,`booking_id`),
  KEY `verified_by` (`verified_by`),
  CONSTRAINT `member_booking_links_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_booking_links_ibfk_2` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_booking_links_ibfk_3` FOREIGN KEY (`verified_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `member_booking_links`
--

LOCK TABLES `member_booking_links` WRITE;
/*!40000 ALTER TABLE `member_booking_links` DISABLE KEYS */;
/*!40000 ALTER TABLE `member_booking_links` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `member_communication_preferences`
--

DROP TABLE IF EXISTS `member_communication_preferences`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `member_communication_preferences` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `person_id` bigint(20) unsigned NOT NULL,
  `scope_type` enum('platform','province','unit') NOT NULL,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `event_invitations` tinyint(1) NOT NULL DEFAULT 0,
  `general_messages` tinyint(1) NOT NULL DEFAULT 0,
  `service_messages` tinyint(1) NOT NULL DEFAULT 1,
  `preferred_channel` enum('email','phone','post','none') NOT NULL DEFAULT 'email',
  `updated_by` bigint(20) unsigned NOT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `scope_key` varchar(90) GENERATED ALWAYS AS (concat(`scope_type`,':',ifnull(`province_id`,0),':',ifnull(`unit_id`,0))) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_member_preference_scope` (`person_id`,`scope_key`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `member_communication_preferences_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_communication_preferences_ibfk_2` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_communication_preferences_ibfk_3` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_communication_preferences_ibfk_4` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_member_preference_scope` CHECK (`scope_type` = 'platform' and `province_id` is null and `unit_id` is null or `scope_type` = 'province' and `province_id` is not null and `unit_id` is null or `scope_type` = 'unit' and `unit_id` is not null)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `member_communication_preferences`
--

LOCK TABLES `member_communication_preferences` WRITE;
/*!40000 ALTER TABLE `member_communication_preferences` DISABLE KEYS */;
/*!40000 ALTER TABLE `member_communication_preferences` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `member_correction_requests`
--

DROP TABLE IF EXISTS `member_correction_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `member_correction_requests` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `person_id` bigint(20) unsigned NOT NULL,
  `scope_type` enum('profile','unit_membership','province_relationship') NOT NULL,
  `scope_id` bigint(20) unsigned DEFAULT NULL,
  `field_key` varchar(60) NOT NULL,
  `requested_value` varchar(500) NOT NULL,
  `reason` varchar(1000) DEFAULT NULL,
  `status` enum('open','accepted','partially_accepted','declined','withdrawn') NOT NULL DEFAULT 'open',
  `submitted_by` bigint(20) unsigned NOT NULL,
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `submitted_at` datetime NOT NULL DEFAULT current_timestamp(),
  `reviewed_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_member_correction` (`person_id`,`status`,`submitted_at`),
  KEY `submitted_by` (`submitted_by`),
  KEY `reviewed_by` (`reviewed_by`),
  CONSTRAINT `member_correction_requests_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_correction_requests_ibfk_2` FOREIGN KEY (`submitted_by`) REFERENCES `users` (`id`),
  CONSTRAINT `member_correction_requests_ibfk_3` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `member_correction_requests`
--

LOCK TABLES `member_correction_requests` WRITE;
/*!40000 ALTER TABLE `member_correction_requests` DISABLE KEYS */;
/*!40000 ALTER TABLE `member_correction_requests` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `member_milestones`
--

DROP TABLE IF EXISTS `member_milestones`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `member_milestones` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `member_id` bigint(20) unsigned NOT NULL,
  `milestone_key` varchar(60) NOT NULL,
  `terminology` varchar(80) NOT NULL,
  `ceremony_date` date NOT NULL,
  `confirmed_by` bigint(20) unsigned NOT NULL,
  `confirmed_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_member_milestone` (`member_id`,`milestone_key`),
  KEY `fk_milestone_actor` (`confirmed_by`),
  CONSTRAINT `fk_milestone_actor` FOREIGN KEY (`confirmed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_milestone_member` FOREIGN KEY (`member_id`) REFERENCES `unit_members` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `member_milestones`
--

LOCK TABLES `member_milestones` WRITE;
/*!40000 ALTER TABLE `member_milestones` DISABLE KEYS */;
/*!40000 ALTER TABLE `member_milestones` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `member_offices`
--

DROP TABLE IF EXISTS `member_offices`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `member_offices` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `member_id` bigint(20) unsigned NOT NULL,
  `office_name` varchar(150) NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_member_office` (`member_id`,`start_date`),
  CONSTRAINT `fk_member_office_member` FOREIGN KEY (`member_id`) REFERENCES `unit_members` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_office_dates` CHECK (`end_date` is null or `end_date` >= `start_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `member_offices`
--

LOCK TABLES `member_offices` WRITE;
/*!40000 ALTER TABLE `member_offices` DISABLE KEYS */;
/*!40000 ALTER TABLE `member_offices` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `member_ranks`
--

DROP TABLE IF EXISTS `member_ranks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `member_ranks` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `member_id` bigint(20) unsigned NOT NULL,
  `rank_scope` enum('masonic','provincial','grand') NOT NULL,
  `rank_name` varchar(150) NOT NULL,
  `attained_date` date DEFAULT NULL,
  `ended_date` date DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_member_rank` (`member_id`,`rank_scope`,`rank_name`),
  CONSTRAINT `fk_member_rank_member` FOREIGN KEY (`member_id`) REFERENCES `unit_members` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `member_ranks`
--

LOCK TABLES `member_ranks` WRITE;
/*!40000 ALTER TABLE `member_ranks` DISABLE KEYS */;
/*!40000 ALTER TABLE `member_ranks` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `member_visible_communications`
--

DROP TABLE IF EXISTS `member_visible_communications`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `member_visible_communications` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `person_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `communication_id` bigint(20) unsigned DEFAULT NULL,
  `subject` varchar(250) NOT NULL,
  `summary` text DEFAULT NULL,
  `sent_at` datetime NOT NULL,
  `visible_from` datetime NOT NULL DEFAULT current_timestamp(),
  `revoked_at` datetime DEFAULT NULL,
  `linked_by` bigint(20) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_member_communication` (`person_id`,`unit_id`,`province_id`,`revoked_at`,`sent_at`),
  KEY `unit_id` (`unit_id`),
  KEY `province_id` (`province_id`),
  KEY `communication_id` (`communication_id`),
  KEY `linked_by` (`linked_by`),
  CONSTRAINT `member_visible_communications_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_visible_communications_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_visible_communications_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `member_visible_communications_ibfk_4` FOREIGN KEY (`communication_id`) REFERENCES `communication_log` (`id`) ON DELETE SET NULL,
  CONSTRAINT `member_visible_communications_ibfk_5` FOREIGN KEY (`linked_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_member_communication_scope` CHECK (`unit_id` is null <> (`province_id` is null))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `member_visible_communications`
--

LOCK TABLES `member_visible_communications` WRITE;
/*!40000 ALTER TABLE `member_visible_communications` DISABLE KEYS */;
/*!40000 ALTER TABLE `member_visible_communications` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `migration_history`
--

DROP TABLE IF EXISTS `migration_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `migration_history` (
  `version` varchar(12) NOT NULL,
  `name` varchar(200) NOT NULL,
  `checksum` char(64) NOT NULL,
  `applied_at` datetime NOT NULL DEFAULT current_timestamp(),
  `execution_ms` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `migration_history`
--

LOCK TABLES `migration_history` WRITE;
/*!40000 ALTER TABLE `migration_history` DISABLE KEYS */;
INSERT INTO `migration_history` VALUES ('202609240001','Multi-Province and multi-unit security foundation','9c2133ea25711808e2e899bc37222a316bcca7c5e19664f3b1f8202d4c37431a','2026-09-27 21:01:01',0),('202609240002','Tenant catalogue, unit identifiers and membership role scopes','9106c46bcb26766f662c3c920426306898939c03739cb8eca0ca662353763a43','2026-09-27 21:01:01',0),('202609240003','Authentication rate limits','85e430feb2c8388e0ca6d3144f3c546085a4458792521524bb90aadf5878816d','2026-09-27 21:01:05',0),('202609240004','Scoped roles','ff1d3c871c97c7b954177975a2e27523bb267a63a5387e950c15027fd6ea123c','2026-09-27 21:01:05',0),('202609240005','Provincial administration','6d024f677c39a31e4a7c8fcfc773776d1c499f07f834079a920f337e2bd032d6','2026-09-27 21:01:05',0),('202609240006','Unit archive','8439fdea56e975062f70da1a01d9b42328329e6ed946c4740a0bc20bd8c3c1c6','2026-09-27 21:01:05',0),('202609240007','Province administrator invitations','7bdd92bb6f3b2cdaac81978d0c99f3af03b0684d96dcc5d3150807a4e214deb9','2026-09-27 21:01:05',0),('202609240008','Directional unit links','527089d1cf894def903200c6a305e4a7705860c43abe2ac45c9caeca1ef36803','2026-09-27 21:01:05',0),('202609240009','Tenant events','f6f6de76f1e22ffb0fb12154865ddf4ab692a43f91ca3e92e566adf5f233279f','2026-09-27 21:01:05',0),('202609240010','Event programmes','5fdf1b4a9c19259b772ec7128a7ff71dcb395aaaec3f70764eb539716c89d05c','2026-09-27 21:01:05',0),('202609240011','Public slug redirects','77a7a0c9a81d7e0b8815f1fe7bf67e09de9a727e8dd71f0fb7d21884ed6e38b4','2026-09-27 21:01:05',0),('202609240012','Guest directory consent','518869354375c9bb6db8d68c551aded10eda94043cc12c859dfc65db1d0183af','2026-09-27 21:01:05',0),('202609240013','Province secretary role','3f4129960e4d1c11b45cd163d712f70e71e987a18acb5bd84646475ba9d6300c','2026-09-27 21:01:05',0),('202609240014','Arrival and Province events','d965b1e0e25b50b6e5e72a5c10bd12dc71365d79643542fb222b55a233604a0d','2026-09-27 21:01:05',0),('202609240015','Province Order unique names','c81c2233ba9417d2698adbe132234120e0a29a342fc43ce4ae65be06af146a63','2026-09-27 21:01:05',0),('202609240016','Province Order charity logos','041032b506e5ca2a5974d7036f1a7afe40ac217d03052c82af7c1ddbd817d1af','2026-09-27 21:01:05',0),('202609250017','Tenant documents','49655857aafbefdc5a34e9725b2a0fc9e6122bb44876b4b82f0861d856ec358c','2026-09-27 21:01:05',0),('202609250018','Direct roles and unassigned units','b3c88f9db71ed544bf99c4f5b840b974ae0f485aa32fdd216df6fc186f0de36c','2026-09-27 21:01:05',0),('202609250019','Mail queue','2109156dc3ac203cb264b2b9634e14abc611cc3bce94ff0db6cddf23333ffd23','2026-09-27 21:01:05',0),('202609250020','Scheduled jobs','a7379359d5e1337b922162feb1d97020e25019ddc5da90d478b94f8b0a6e5c65','2026-09-27 21:01:05',0),('202609250021','Scoped reports and activity','cb8e4286c8395af5f06efb68f761c5002e94fbf94cb5cf90fe8e01bdc6247001','2026-09-27 21:01:05',0),('202609270022','Account MFA, session assurance and periodic scoped access reviews','e7dc2c6837312845915007d164d24bcb31f8153baae72d59bcf1b6d11b5e98bf','2026-09-27 21:01:04',0),('202609270023','Scoped permission sets and event grants','6a782f0f6c08e394f99af8fe1fd4685a626d3fa3737710e696249b7b43e8b078','2026-09-27 21:01:04',0),('202609270024','Unit members contacts candidates and reviewed identity resolution','491e0ad842af876c51f764aa5cda83bef99d67da58322f4fdfc1af991015d5a2','2026-09-27 21:01:05',0),('202609270025','Staged people CSV import and reconciliation','aea330de7f5acbd65696e132241e0587ce5a64b33f201958fdb55f6b6a5fd9c3','2026-09-27 21:01:05',0),('202609270026','Restricted data governance cases exports retention and suppression','54307884b267b3a404329a2651ef002855a2476585fc74d602c092afd3327cea','2026-09-27 21:01:05',0),('202609270027','Signed-in memberships hub, role action centre and officer handover','1dc83eded545752258beb07619b83d0c9b2f5b287d42791cae619eab2566edbc','2026-09-27 22:15:49',0),('202609270028','Scoped unit Province and member calendars','2fcdb5eb1be85fe6a67f6d8004938f8992e94fe65cb669dbe2c6d868bfd8f70a','2026-09-27 22:32:47',0),('202609280029','Director of Ceremonies workspaces','8de5572ea242bc0b958cb1ce2630d13b0497a424314769a29bbea3ce7f81700d','2026-09-28 06:45:44',0),('202609280030','Structured Province and unit file manager','9ef68ad20129840d6b29b2393997db8dde3203860952bd7aedc49f4ae1e97b28','2026-09-28 06:58:45',0),('202609280031','Unit and Province asset registers','b309d34d7207fd7d9e6f265985f08c94d01c42d2e310ea68517818b77f30caf2','2026-09-28 07:12:43',0),('202609280032','Structured agendas, summons and minutes','09ca7c1c7a095e6ae2eefa86046ca238df00a8c81896841de3d7d0417f72d133','2026-09-28 07:28:33',0),('202609280033','Per-unit postal delivery and print queue','fd046ee6a375f4c96668f104a417b8722e3d1ee21fd571ef343e7ce2eff9f9b3','2026-09-28 07:42:00',0),('202609280034','Versioned annual and installation returns','923851c105e9f4f1bae2a2fc0fe0016d1f2ef13183e14de67a3b6434d0815f35','2026-09-28 11:52:31',0),('202609280035','Per-diner menu choices and catering handoffs','4a3423c643f66e7e297f035ba8aebbc85a9427dcafd091411f0d59cb2f8d9813','2026-09-28 12:05:29',0),('202609280036','Shared-programme dining table plans','0dacdc414f50965e47ca560ea6e3a88c0f6d392c22baaa78a7ec793200fefeaa','2026-09-28 12:35:06',0),('202609280037','Short-lived event-day packs and offline check-in reconciliation','ce91e2ef0a40c71750ddb373b6cd55be201a0fe5d9aadec9d7b371fd4f75f40e','2026-09-28 16:55:55',0),('202609280038','Immutable finance ledger and protected bank accounts','1cf687164bfa50ad0b122c76502e60dfd30d7bc5acd8653072cf60c6f995210d','2026-09-28 17:14:59',0),('202609280039','Subscriptions expenses designated funds and year end snapshots','d5c9563517d40259dd85a68279b82c79ba8121bb053c6b0d86785e999c652001','2026-09-28 17:34:35',0),('202609280040','Versioned invoices issuer numbering payments and credit notes','20cbb8421c7d6c6c50de3691a247df5b8f2a23b07768fd5715e1c1436fe3d580','2026-09-28 18:09:29',0),('202609280041','Scoped Almoner welfare cases and restricted finance sharing','0baadeff19e684c20aa68762ee5890ce7eaa9118e01be5a462999380b9bc5fc3','2026-09-28 18:28:32',0);
/*!40000 ALTER TABLE `migration_history` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `officer_handover_items`
--

DROP TABLE IF EXISTS `officer_handover_items`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `officer_handover_items` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `handover_id` bigint(20) unsigned NOT NULL,
  `item_key` varchar(80) NOT NULL,
  `item_label` varchar(250) NOT NULL,
  `restricted_note` text DEFAULT NULL,
  `outgoing_confirmed_at` datetime DEFAULT NULL,
  `incoming_confirmed_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_handover_item` (`handover_id`,`item_key`),
  CONSTRAINT `officer_handover_items_ibfk_1` FOREIGN KEY (`handover_id`) REFERENCES `officer_handovers` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `officer_handover_items`
--

LOCK TABLES `officer_handover_items` WRITE;
/*!40000 ALTER TABLE `officer_handover_items` DISABLE KEYS */;
/*!40000 ALTER TABLE `officer_handover_items` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `officer_handovers`
--

DROP TABLE IF EXISTS `officer_handovers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `officer_handovers` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `role_key` varchar(50) NOT NULL,
  `outgoing_membership_id` bigint(20) unsigned NOT NULL,
  `incoming_membership_id` bigint(20) unsigned NOT NULL,
  `handover_at` datetime NOT NULL,
  `status` enum('draft','active','completed','cancelled') NOT NULL DEFAULT 'draft',
  `created_by` bigint(20) unsigned NOT NULL,
  `completed_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `completed_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_handover_unit` (`unit_id`,`status`,`handover_at`),
  KEY `outgoing_membership_id` (`outgoing_membership_id`),
  KEY `incoming_membership_id` (`incoming_membership_id`),
  KEY `created_by` (`created_by`),
  KEY `completed_by` (`completed_by`),
  CONSTRAINT `officer_handovers_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `officer_handovers_ibfk_2` FOREIGN KEY (`outgoing_membership_id`) REFERENCES `user_memberships` (`id`),
  CONSTRAINT `officer_handovers_ibfk_3` FOREIGN KEY (`incoming_membership_id`) REFERENCES `user_memberships` (`id`),
  CONSTRAINT `officer_handovers_ibfk_4` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `officer_handovers_ibfk_5` FOREIGN KEY (`completed_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `chk_handover_memberships` CHECK (`outgoing_membership_id` <> `incoming_membership_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `officer_handovers`
--

LOCK TABLES `officer_handovers` WRITE;
/*!40000 ALTER TABLE `officer_handovers` DISABLE KEYS */;
/*!40000 ALTER TABLE `officer_handovers` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `offline_checkin_batches`
--

DROP TABLE IF EXISTS `offline_checkin_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `offline_checkin_batches` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `pack_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `status` enum('review','approved','applied','cancelled') NOT NULL DEFAULT 'review',
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  `applied_by` bigint(20) unsigned DEFAULT NULL,
  `applied_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_offline_batch_event` (`meeting_id`,`status`,`created_at`),
  KEY `pack_id` (`pack_id`),
  KEY `unit_id` (`unit_id`),
  KEY `created_by` (`created_by`),
  KEY `reviewed_by` (`reviewed_by`),
  KEY `applied_by` (`applied_by`),
  CONSTRAINT `offline_checkin_batches_ibfk_1` FOREIGN KEY (`pack_id`) REFERENCES `event_day_packs` (`id`),
  CONSTRAINT `offline_checkin_batches_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `offline_checkin_batches_ibfk_3` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`),
  CONSTRAINT `offline_checkin_batches_ibfk_4` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `offline_checkin_batches_ibfk_5` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `offline_checkin_batches_ibfk_6` FOREIGN KEY (`applied_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `offline_checkin_batches`
--

LOCK TABLES `offline_checkin_batches` WRITE;
/*!40000 ALTER TABLE `offline_checkin_batches` DISABLE KEYS */;
/*!40000 ALTER TABLE `offline_checkin_batches` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `offline_checkin_rows`
--

DROP TABLE IF EXISTS `offline_checkin_rows`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `offline_checkin_rows` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint(20) unsigned NOT NULL,
  `person_type` enum('booking','guest') NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `marked_arrived_at` datetime DEFAULT NULL,
  `review_state` enum('ready','duplicate','conflict') NOT NULL,
  `review_decision` enum('pending','apply','skip') NOT NULL DEFAULT 'pending',
  `result_state` enum('pending','applied','duplicate','conflict','skipped') NOT NULL DEFAULT 'pending',
  `live_arrived_at_review` datetime DEFAULT NULL,
  `detail_code` varchar(60) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_offline_batch_person` (`batch_id`,`person_type`,`person_id`),
  CONSTRAINT `offline_checkin_rows_ibfk_1` FOREIGN KEY (`batch_id`) REFERENCES `offline_checkin_batches` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `offline_checkin_rows`
--

LOCK TABLES `offline_checkin_rows` WRITE;
/*!40000 ALTER TABLE `offline_checkin_rows` DISABLE KEYS */;
/*!40000 ALTER TABLE `offline_checkin_rows` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `order_rank_settings`
--

DROP TABLE IF EXISTS `order_rank_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `order_rank_settings` (
  `unit_id` bigint(20) unsigned NOT NULL,
  `order_key` varchar(40) NOT NULL,
  `salutations` text DEFAULT NULL,
  `salutation_rank_links` longtext DEFAULT NULL,
  `masonic_ranks` text DEFAULT NULL,
  `active_provincial_ranks` text DEFAULT NULL,
  `past_provincial_ranks` text DEFAULT NULL,
  `active_grand_ranks` text DEFAULT NULL,
  `past_grand_ranks` text DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`unit_id`,`order_key`),
  CONSTRAINT `fk_order_rank_settings_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `order_rank_settings`
--

LOCK TABLES `order_rank_settings` WRITE;
/*!40000 ALTER TABLE `order_rank_settings` DISABLE KEYS */;
INSERT INTO `order_rank_settings` VALUES (134,'craft','Bro\nWBro\nVWBro\nRWBro\nMWBro','{\"Bro\":[{\"scope\":\"masonic\",\"rank\":\"Entered Apprentice\"},{\"scope\":\"masonic\",\"rank\":\"Fellow Craft\"},{\"scope\":\"masonic\",\"rank\":\"Master Mason\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Pursuivant\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Pursuivant\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Organist\"}],\"WBro\":[{\"scope\":\"provincial\",\"rank\":\"Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Assistant Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Senior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Junior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Treasurer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Inspector\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Charity Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Membership Officer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Communications Officer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Learning and Development Officer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Senior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Junior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Organise\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Pursuivant\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Steward\"},{\"scope\":\"grand\",\"rank\":\"Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Superintendent of Works\"},{\"scope\":\"grand\",\"rank\":\"Senior Grand Deacon\"},{\"scope\":\"grand\",\"rank\":\"Junior Grand Deacon\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Directors of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Sword Bearers\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Superintendents of Works\"},{\"scope\":\"grand\",\"rank\":\"Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Grand Pursuivant\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Pursiuvant\"},{\"scope\":\"grand\",\"rank\":\"Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Assistant Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Senior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Junior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Treasurer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Inspector\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Charity Steward\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Superintendent of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Senior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Membership Officer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Communications Officer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Learning and Development Officer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Senior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Junior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Junior Grand Deacon\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Directors of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Sword Bearers\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Superintendents of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Pursuivant\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Pursiuvant\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Organise\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Pursuivant\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Steward\"},{\"scope\":\"masonic\",\"rank\":\"Worshipful Master\"},{\"scope\":\"masonic\",\"rank\":\"Immediate Past Master\"},{\"scope\":\"masonic\",\"rank\":\"Past Master\"}],\"VWBro\":[{\"scope\":\"provincial\",\"rank\":\"Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Deputy Provincial Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Grand Chancellor\"},{\"scope\":\"grand\",\"rank\":\"President of the Masonic Charitable Foundation\"},{\"scope\":\"grand\",\"rank\":\"Deputy President of the Board of General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Deputy President of the Masonic Charitable Foundation\"},{\"scope\":\"grand\",\"rank\":\"Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Grand Superintendent of Works\"},{\"scope\":\"grand\",\"rank\":\"Grand Inspector\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Chancellor\"},{\"scope\":\"grand\",\"rank\":\"Past President of the Masonic Charitable Foundation\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy President of the Board of General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy President of the Masonic Charitable Foundation\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Superintendent of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Inspector\"}],\"RWBro\":[{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Senior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Junior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"President of the Board of General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Senior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Past Junior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Past President of the Board of General Purposes\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Master\"}],\"MWBro\":[{\"scope\":\"grand\",\"rank\":\"Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Pro Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Pro Grand Master\"}]}','Entered Apprentice\nFellow Craft\nMaster Mason\nWorshipful Master\nImmediate Past Master\nPast Master','Provincial Grand Master\nDeputy Provincial Grand Master\nAssistant Provincial Grand Master\nProvincial Senior Grand Warden\nProvincial Junior Grand Warden\nProvincial Grand Chaplain\nProvincial Grand Treasurer\nProvincial Grand Registrar\nProvincial Grand Secretary\nProvincial Grand Director of Ceremonies\nProvincial Grand Sword Bearer\nProvincial Grand Superintendent of Works\nProvincial Deputy Grand Chaplain\nProvincial Deputy Grand Registrar\nProvincial Deputy Grand Secretary\nProvincial Deputy Grand Director of Ceremonies\nProvincial Deputy Grand Sword Bearer\nProvincial Deputy Grand Superintendent of Works\nProvincial Assistant Grand Inspector\nProvincial Grand Almoner\nProvincial Grand Charity Steward\nProvincial Grand Membership Officer\nProvincial Grand Communications Officer\nProvincial Grand Learning and Development Officer\nProvincial Senior Grand Deacon\nProvincial Junior Grand Deacon\nProvincial Assistant Grand Chaplain\nProvincial Assistant Grand Registrar\nProvincial Assistant Grand Secretary\nProvincial Assistant Grand Director of Ceremonies\nProvincial Assistant Grand Sword Bearer\nProvincial Assistant Grand Superintendent of Works\nProvincial Grand Organise\nProvincial Standard Bearer\nProvincial Assistant Grand Standard Bearer\nProvincial Deputy Grand Organist\nProvincial Grand Pursuivant\nProvincial Grand Tyler\nProvincial Grand Steward','Past Provincial Grand Master\nPast Deputy Provincial Grand Master\nPast Assistant Provincial Grand Master\nPast Provincial Senior Grand Warden\nPast Provincial Junior Grand Warden\nPast Provincial Grand Chaplain\nPast Provincial Grand Treasurer\nPast Provincial Grand Registrar\nPast Provincial Grand Secretary\nPast Provincial Grand Director of Ceremonies\nPast Provincial Grand Sword Bearer\nPast Provincial Grand Superintendent of Works\nPast Provincial Deputy Grand Chaplain\nPast Provincial Deputy Grand Registrar\nPast Provincial Deputy Grand Secretary\nPast Provincial Deputy Grand Director of Ceremonies\nPast Provincial Deputy Grand Sword Bearer\nPast Provincial Deputy Grand Superintendent of Works\nPast Provincial Assistant Grand Inspector\nPast Provincial Grand Almoner\nPast Provincial Grand Charity Steward\nPast Provincial Grand Membership Officer\nPast Provincial Grand Communications Officer\nPast Provincial Grand Learning and Development Officer\nPast Provincial Senior Grand Deacon\nPast Provincial Junior Grand Deacon\nPast Provincial Assistant Grand Chaplain\nPast Provincial Assistant Grand Registrar\nPast Provincial Assistant Grand Secretary\nPast Provincial Assistant Grand Director of Ceremonies\nPast Provincial Assistant Grand Sword Bearer\nPast Provincial Assistant Grand Superintendent of Works\nPast Provincial Grand Organise\nPast Provincial Standard Bearer\nPast Provincial Assistant Grand Standard Bearer\nPast Provincial Deputy Grand Organist\nPast Provincial Grand Pursuivant\nPast Provincial Grand Tyler\nPast Provincial Grand Steward','Grand Master\nPro Grand Master\nDeputy Grand Master\nAssistant Grand Master\nSenior Grand Warden\nJunior Grand Warden\nPresident of the Board of General Purposes\nGrand Chaplain\nGrand Registrar\nGrand Secretary\nGrand Chancellor\nPresident of the Masonic Charitable Foundation\nDeputy President of the Board of General Purposes\nDeputy President of the Masonic Charitable Foundation\nGrand Director of Ceremonies\nGrand Sword Bearer\nGrand Superintendent of Works\nGrand Inspector\nGrand Treasurer\nDeputy Grand Chaplain\nDeputy Grand Registrar\nDeputy Grand Director of Ceremonies\nDeputy Grand Sword Bearer\nDeputy Grand Superintendent of Works\nSenior Grand Deacon\nJunior Grand Deacon\nAssistant Grand Chaplain\nAssistant Grand Registrar\nAssistant Grand Directors of Ceremonies\nAssistant Grand Sword Bearers\nAssistant Grand Superintendents of Works\nGrand Organist\nGrand Standard Bearer\nDeputy Grand Organist\nGrand Pursuivant\nAssistant Grand Pursiuvant\nGrand Steward','Past Grand Master\nPast Pro Grand Master\nPast Deputy Grand Master\nPast Assistant Grand Master\nPast Senior Grand Warden\nPast Junior Grand Warden\nPast President of the Board of General Purposes\nPast Grand Chaplain\nPast Grand Registrar\nPast Grand Secretary\nPast Grand Chancellor\nPast President of the Masonic Charitable Foundation\nPast Deputy President of the Board of General Purposes\nPast Deputy President of the Masonic Charitable Foundation\nPast Grand Director of Ceremonies\nPast Grand Sword Bearer\nPast Grand Superintendent of Works\nPast Grand Inspector\nPast Grand Treasurer\nPast Deputy Grand Chaplain\nPast Deputy Grand Registrar\nPast Deputy Grand Director of Ceremonies\nPast Deputy Grand Sword Bearer\nPast Deputy Grand Superintendent of Works\nPast Senior Grand Deacon\nPast Junior Grand Deacon\nPast Assistant Grand Chaplain\nPast Assistant Grand Registrar\nPast Assistant Grand Directors of Ceremonies\nPast Assistant Grand Sword Bearers\nPast Assistant Grand Superintendents of Works\nPast Grand Organist\nPast Grand Standard Bearer\nPast Deputy Grand Organist\nPast Grand Pursuivant\nPast Assistant Grand Pursiuvant\nPast Grand Steward','2026-09-28 16:50:44');
/*!40000 ALTER TABLE `order_rank_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `outbound_mail_queue`
--

DROP TABLE IF EXISTS `outbound_mail_queue`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `outbound_mail_queue` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `communication_id` bigint(20) unsigned DEFAULT NULL,
  `booking_id` bigint(20) unsigned DEFAULT NULL,
  `invoice_id` bigint(20) unsigned DEFAULT NULL,
  `reminder_id` bigint(20) unsigned DEFAULT NULL,
  `contact_id` bigint(20) unsigned DEFAULT NULL,
  `attendee_invitation_id` bigint(20) unsigned DEFAULT NULL,
  `guest_invitation_id` bigint(20) unsigned DEFAULT NULL,
  `recipient` varchar(254) NOT NULL,
  `recipient_key` varchar(254) GENERATED ALWAYS AS (lcase(trim(`recipient`))) STORED,
  `subject` varchar(250) NOT NULL,
  `body_html` mediumtext NOT NULL,
  `attachments_json` mediumtext DEFAULT NULL,
  `message_kind` varchar(80) NOT NULL DEFAULT 'general',
  `status` enum('queued','sending','sent','failed','bounced') NOT NULL DEFAULT 'queued',
  `attempts` tinyint(3) unsigned NOT NULL DEFAULT 0,
  `max_attempts` tinyint(3) unsigned NOT NULL DEFAULT 5,
  `next_attempt_at` datetime NOT NULL DEFAULT current_timestamp(),
  `lease_token` char(32) DEFAULT NULL,
  `locked_until` datetime DEFAULT NULL,
  `sent_at` datetime DEFAULT NULL,
  `last_error_code` varchar(40) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `offer_booking_id` bigint(20) unsigned DEFAULT NULL,
  `offer_expires_at` datetime DEFAULT NULL,
  `authorising_user_id` bigint(20) unsigned DEFAULT NULL,
  `required_capability` varchar(80) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_mail_ready` (`status`,`next_attempt_at`,`id`),
  KEY `idx_mail_tenant_recipient` (`unit_id`,`recipient_key`,`id`),
  KEY `communication_id` (`communication_id`),
  KEY `booking_id` (`booking_id`),
  KEY `reminder_id` (`reminder_id`),
  KEY `contact_id` (`contact_id`),
  KEY `attendee_invitation_id` (`attendee_invitation_id`),
  KEY `guest_invitation_id` (`guest_invitation_id`),
  KEY `idx_offer_mail` (`offer_booking_id`,`offer_expires_at`,`status`),
  KEY `idx_mail_authority` (`authorising_user_id`,`status`),
  KEY `idx_mail_province` (`province_id`,`status`),
  KEY `idx_mail_invoice` (`invoice_id`,`status`),
  CONSTRAINT `fk_mail_invoice` FOREIGN KEY (`invoice_id`) REFERENCES `finance_invoices` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_mail_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE SET NULL,
  CONSTRAINT `outbound_mail_queue_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE SET NULL,
  CONSTRAINT `outbound_mail_queue_ibfk_2` FOREIGN KEY (`communication_id`) REFERENCES `communication_log` (`id`) ON DELETE SET NULL,
  CONSTRAINT `outbound_mail_queue_ibfk_3` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`) ON DELETE SET NULL,
  CONSTRAINT `outbound_mail_queue_ibfk_4` FOREIGN KEY (`reminder_id`) REFERENCES `reminders` (`id`) ON DELETE SET NULL,
  CONSTRAINT `outbound_mail_queue_ibfk_5` FOREIGN KEY (`contact_id`) REFERENCES `contact_messages` (`id`) ON DELETE SET NULL,
  CONSTRAINT `outbound_mail_queue_ibfk_6` FOREIGN KEY (`attendee_invitation_id`) REFERENCES `attendee_invitations` (`id`) ON DELETE SET NULL,
  CONSTRAINT `outbound_mail_queue_ibfk_7` FOREIGN KEY (`guest_invitation_id`) REFERENCES `guest_invitations` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `outbound_mail_queue`
--

LOCK TABLES `outbound_mail_queue` WRITE;
/*!40000 ALTER TABLE `outbound_mail_queue` DISABLE KEYS */;
INSERT INTO `outbound_mail_queue` VALUES (1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'cajtaylor@gmail.com','cajtaylor@gmail.com','Account security notification','<p>A new sign-in completed.</p><p>If this was not you, contact your platform administrator using your usual trusted contact details.</p>','[]','security_notification','queued',0,5,'2026-09-27 22:07:51',NULL,NULL,NULL,NULL,'2026-09-27 22:07:51','2026-09-27 22:07:51',NULL,NULL,NULL,NULL),(7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'cajtaylor@gmail.com','cajtaylor@gmail.com','Account security notification','<p>A new sign-in completed.</p><p>If this was not you, contact your platform administrator using your usual trusted contact details.</p>','[]','security_notification','queued',0,5,'2026-09-28 08:32:26',NULL,NULL,NULL,NULL,'2026-09-28 08:32:26','2026-09-28 08:32:26',NULL,NULL,NULL,NULL),(10,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'cajtaylor@gmail.com','cajtaylor@gmail.com','Account security notification','<p>A new sign-in completed.</p><p>If this was not you, contact your platform administrator using your usual trusted contact details.</p>','[]','security_notification','queued',0,5,'2026-09-28 12:03:06',NULL,NULL,NULL,NULL,'2026-09-28 12:03:06','2026-09-28 12:03:06',NULL,NULL,NULL,NULL),(12,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'cajtaylor@gmail.com','cajtaylor@gmail.com','Account security notification','<p>A new sign-in completed.</p><p>If this was not you, contact your platform administrator using your usual trusted contact details.</p>','[]','security_notification','queued',0,5,'2026-09-28 16:49:49',NULL,NULL,NULL,NULL,'2026-09-28 16:49:49','2026-09-28 16:49:49',NULL,NULL,NULL,NULL),(15,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'cajtaylor@gmail.com','cajtaylor@gmail.com','Account security notification','<p>A new sign-in completed.</p><p>If this was not you, contact your platform administrator using your usual trusted contact details.</p>','[]','security_notification','queued',0,5,'2026-09-28 18:39:43',NULL,NULL,NULL,NULL,'2026-09-28 18:39:43','2026-09-28 18:39:43',NULL,NULL,NULL,NULL);
/*!40000 ALTER TABLE `outbound_mail_queue` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `password_reset_tokens`
--

DROP TABLE IF EXISTS `password_reset_tokens`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `password_reset_tokens` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL,
  `selector` char(16) NOT NULL,
  `token_hash` char(64) NOT NULL,
  `expires_at` datetime NOT NULL,
  `used_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_password_reset_selector` (`selector`),
  KEY `fk_password_reset_user` (`user_id`),
  CONSTRAINT `fk_password_reset_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `password_reset_tokens`
--

LOCK TABLES `password_reset_tokens` WRITE;
/*!40000 ALTER TABLE `password_reset_tokens` DISABLE KEYS */;
/*!40000 ALTER TABLE `password_reset_tokens` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `people`
--

DROP TABLE IF EXISTS `people`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `people` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `salutation` varchar(30) DEFAULT NULL,
  `first_name` varchar(100) NOT NULL,
  `surname` varchar(100) NOT NULL,
  `email` varchar(254) DEFAULT NULL,
  `phone` varchar(30) DEFAULT NULL,
  `identity_verified_at` datetime DEFAULT NULL,
  `identity_verified_by` bigint(20) unsigned DEFAULT NULL,
  `legacy_guest_contact_id` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_people_user` (`user_id`),
  UNIQUE KEY `uq_people_legacy_guest` (`legacy_guest_contact_id`),
  KEY `idx_people_name` (`surname`,`first_name`),
  KEY `idx_people_email` (`email`),
  KEY `fk_people_verifier` (`identity_verified_by`),
  CONSTRAINT `fk_people_guest_contact` FOREIGN KEY (`legacy_guest_contact_id`) REFERENCES `guest_contacts` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_people_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_people_verifier` FOREIGN KEY (`identity_verified_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=128 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `people`
--

LOCK TABLES `people` WRITE;
/*!40000 ALTER TABLE `people` DISABLE KEYS */;
/*!40000 ALTER TABLE `people` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `people_import_actions`
--

DROP TABLE IF EXISTS `people_import_actions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `people_import_actions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `row_id` bigint(20) unsigned NOT NULL,
  `entity_table` varchar(64) NOT NULL,
  `entity_id` bigint(20) unsigned NOT NULL,
  `expected_updated_at` datetime DEFAULT NULL,
  `undone_at` datetime DEFAULT NULL,
  `undo_note` varchar(191) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_people_import_action_row` (`row_id`,`id`),
  CONSTRAINT `fk_people_import_action_row` FOREIGN KEY (`row_id`) REFERENCES `people_import_rows` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `people_import_actions`
--

LOCK TABLES `people_import_actions` WRITE;
/*!40000 ALTER TABLE `people_import_actions` DISABLE KEYS */;
/*!40000 ALTER TABLE `people_import_actions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `people_import_batches`
--

DROP TABLE IF EXISTS `people_import_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `people_import_batches` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('unit','province') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `source_name` varchar(255) NOT NULL,
  `source_sha256` char(64) NOT NULL,
  `source_size` int(10) unsigned NOT NULL,
  `source_system` varchar(100) NOT NULL,
  `mapping_json` longtext NOT NULL,
  `mapping_sha256` char(64) NOT NULL,
  `idempotency_key` char(64) NOT NULL,
  `status` enum('preview','committing','committed','committed_with_errors','failed','undone','undo_partial') NOT NULL DEFAULT 'preview',
  `dry_run` tinyint(1) NOT NULL DEFAULT 1,
  `accepted_count` int(10) unsigned NOT NULL DEFAULT 0,
  `rejected_count` int(10) unsigned NOT NULL DEFAULT 0,
  `unresolved_count` int(10) unsigned NOT NULL DEFAULT 0,
  `applied_count` int(10) unsigned NOT NULL DEFAULT 0,
  `failed_count` int(10) unsigned NOT NULL DEFAULT 0,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `confirmed_at` datetime DEFAULT NULL,
  `committed_at` datetime DEFAULT NULL,
  `undo_until` datetime DEFAULT NULL,
  `undone_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_people_import_idempotency` (`idempotency_key`),
  KEY `idx_people_import_scope` (`scope_type`,`province_id`,`unit_id`,`status`),
  KEY `fk_people_import_province` (`province_id`),
  KEY `fk_people_import_unit` (`unit_id`),
  KEY `fk_people_import_actor` (`created_by`),
  CONSTRAINT `fk_people_import_actor` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_people_import_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `fk_people_import_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `people_import_batches`
--

LOCK TABLES `people_import_batches` WRITE;
/*!40000 ALTER TABLE `people_import_batches` DISABLE KEYS */;
/*!40000 ALTER TABLE `people_import_batches` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `people_import_duplicate_suggestions`
--

DROP TABLE IF EXISTS `people_import_duplicate_suggestions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `people_import_duplicate_suggestions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `row_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `score` smallint(5) unsigned NOT NULL,
  `signals_json` longtext NOT NULL,
  `decision` enum('pending','use_existing','create_separate','dismissed') NOT NULL DEFAULT 'pending',
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_people_import_suggestion` (`row_id`,`person_id`),
  KEY `idx_people_import_suggestion_person` (`person_id`),
  KEY `fk_people_import_suggestion_reviewer` (`reviewed_by`),
  CONSTRAINT `fk_people_import_suggestion_person` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_people_import_suggestion_reviewer` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_people_import_suggestion_row` FOREIGN KEY (`row_id`) REFERENCES `people_import_rows` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `people_import_duplicate_suggestions`
--

LOCK TABLES `people_import_duplicate_suggestions` WRITE;
/*!40000 ALTER TABLE `people_import_duplicate_suggestions` DISABLE KEYS */;
/*!40000 ALTER TABLE `people_import_duplicate_suggestions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `people_import_rows`
--

DROP TABLE IF EXISTS `people_import_rows`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `people_import_rows` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint(20) unsigned NOT NULL,
  `row_number` int(10) unsigned NOT NULL,
  `source_unit_slug` varchar(191) DEFAULT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `record_type` varchar(32) NOT NULL,
  `row_fingerprint` char(64) NOT NULL,
  `raw_json` longtext NOT NULL,
  `normalized_json` longtext NOT NULL,
  `status` enum('accepted','rejected','unresolved','applied','failed','undone') NOT NULL,
  `validation_errors` longtext DEFAULT NULL,
  `resolved_person_id` bigint(20) unsigned DEFAULT NULL,
  `resolution` enum('new','existing') DEFAULT NULL,
  `applied_at` datetime DEFAULT NULL,
  `failure_code` varchar(80) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_people_import_row` (`batch_id`,`row_number`),
  KEY `idx_people_import_row_status` (`batch_id`,`status`,`row_number`),
  KEY `idx_people_import_row_unit` (`unit_id`),
  KEY `fk_people_import_row_person` (`resolved_person_id`),
  CONSTRAINT `fk_people_import_row_batch` FOREIGN KEY (`batch_id`) REFERENCES `people_import_batches` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_people_import_row_person` FOREIGN KEY (`resolved_person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_people_import_row_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `people_import_rows`
--

LOCK TABLES `people_import_rows` WRITE;
/*!40000 ALTER TABLE `people_import_rows` DISABLE KEYS */;
/*!40000 ALTER TABLE `people_import_rows` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `permission_grant_reviews`
--

DROP TABLE IF EXISTS `permission_grant_reviews`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `permission_grant_reviews` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `grant_id` bigint(20) unsigned NOT NULL,
  `reviewer_id` bigint(20) unsigned NOT NULL,
  `decision` enum('retain','revoke') NOT NULL,
  `previous_expires_at` datetime DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  `next_review_at` datetime DEFAULT NULL,
  `reviewed_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_permission_review_due` (`grant_id`,`next_review_at`),
  KEY `fk_permission_review_actor` (`reviewer_id`),
  CONSTRAINT `fk_permission_review_actor` FOREIGN KEY (`reviewer_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_permission_review_grant` FOREIGN KEY (`grant_id`) REFERENCES `scoped_permission_grants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `permission_grant_reviews`
--

LOCK TABLES `permission_grant_reviews` WRITE;
/*!40000 ALTER TABLE `permission_grant_reviews` DISABLE KEYS */;
/*!40000 ALTER TABLE `permission_grant_reviews` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `permission_set_capabilities`
--

DROP TABLE IF EXISTS `permission_set_capabilities`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `permission_set_capabilities` (
  `permission_set_id` bigint(20) unsigned NOT NULL,
  `capability_key` varchar(80) NOT NULL,
  PRIMARY KEY (`permission_set_id`,`capability_key`),
  CONSTRAINT `fk_permission_cap_set` FOREIGN KEY (`permission_set_id`) REFERENCES `permission_sets` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `permission_set_capabilities`
--

LOCK TABLES `permission_set_capabilities` WRITE;
/*!40000 ALTER TABLE `permission_set_capabilities` DISABLE KEYS */;
/*!40000 ALTER TABLE `permission_set_capabilities` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `permission_sets`
--

DROP TABLE IF EXISTS `permission_sets`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `permission_sets` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `scope_type` enum('platform','province','unit','event') NOT NULL,
  `source_role` varchar(50) DEFAULT NULL,
  `owner_province_id` bigint(20) unsigned DEFAULT NULL,
  `owner_unit_id` bigint(20) unsigned DEFAULT NULL,
  `built_in` tinyint(1) NOT NULL DEFAULT 0,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_permission_set_owner_name` (`scope_type`,`owner_province_id`,`owner_unit_id`,`name`),
  KEY `idx_permission_set_owner` (`owner_province_id`,`owner_unit_id`,`active`),
  KEY `fk_permission_set_unit` (`owner_unit_id`),
  KEY `fk_permission_set_creator` (`created_by`),
  CONSTRAINT `fk_permission_set_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_permission_set_province` FOREIGN KEY (`owner_province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_permission_set_unit` FOREIGN KEY (`owner_unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_permission_set_owner` CHECK (`scope_type` = 'platform' and `owner_province_id` is null and `owner_unit_id` is null or `scope_type` = 'province' and `owner_province_id` is not null and `owner_unit_id` is null or `scope_type` in ('unit','event') and `owner_province_id` is null and `owner_unit_id` is not null)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `permission_sets`
--

LOCK TABLES `permission_sets` WRITE;
/*!40000 ALTER TABLE `permission_sets` DISABLE KEYS */;
/*!40000 ALTER TABLE `permission_sets` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `person_attendance_history`
--

DROP TABLE IF EXISTS `person_attendance_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `person_attendance_history` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `event_date` date NOT NULL,
  `event_title` varchar(255) NOT NULL,
  `attendance_status` enum('attended','apology','absent','unknown') NOT NULL DEFAULT 'unknown',
  `source_row_id` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_person_attendance_import` (`source_row_id`),
  KEY `idx_person_attendance_unit_date` (`unit_id`,`event_date`),
  KEY `idx_person_attendance_person` (`person_id`),
  CONSTRAINT `fk_person_attendance_person` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_person_attendance_row` FOREIGN KEY (`source_row_id`) REFERENCES `people_import_rows` (`id`),
  CONSTRAINT `fk_person_attendance_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `person_attendance_history`
--

LOCK TABLES `person_attendance_history` WRITE;
/*!40000 ALTER TABLE `person_attendance_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `person_attendance_history` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `person_duplicate_reviews`
--

DROP TABLE IF EXISTS `person_duplicate_reviews`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `person_duplicate_reviews` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_a_id` bigint(20) unsigned NOT NULL,
  `person_b_id` bigint(20) unsigned NOT NULL,
  `status` enum('pending','same_person','different_people') NOT NULL DEFAULT 'pending',
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  `canonical_person_id` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_duplicate_pair` (`unit_id`,`person_a_id`,`person_b_id`),
  KEY `fk_duplicate_a` (`person_a_id`),
  KEY `fk_duplicate_b` (`person_b_id`),
  KEY `fk_duplicate_reviewer` (`reviewed_by`),
  KEY `fk_duplicate_canonical` (`canonical_person_id`),
  CONSTRAINT `fk_duplicate_a` FOREIGN KEY (`person_a_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_duplicate_b` FOREIGN KEY (`person_b_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_duplicate_canonical` FOREIGN KEY (`canonical_person_id`) REFERENCES `people` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_duplicate_reviewer` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_duplicate_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_duplicate_order` CHECK (`person_a_id` < `person_b_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `person_duplicate_reviews`
--

LOCK TABLES `person_duplicate_reviews` WRITE;
/*!40000 ALTER TABLE `person_duplicate_reviews` DISABLE KEYS */;
/*!40000 ALTER TABLE `person_duplicate_reviews` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `person_import_keys`
--

DROP TABLE IF EXISTS `person_import_keys`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `person_import_keys` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_type` enum('unit','province') NOT NULL,
  `scope_id` bigint(20) unsigned NOT NULL,
  `source_system` varchar(100) NOT NULL,
  `external_person_id` varchar(191) NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `source_row_id` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_person_import_key` (`scope_type`,`scope_id`,`source_system`,`external_person_id`),
  KEY `idx_person_import_key_person` (`person_id`),
  KEY `fk_person_import_key_row` (`source_row_id`),
  CONSTRAINT `fk_person_import_key_person` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_person_import_key_row` FOREIGN KEY (`source_row_id`) REFERENCES `people_import_rows` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `person_import_keys`
--

LOCK TABLES `person_import_keys` WRITE;
/*!40000 ALTER TABLE `person_import_keys` DISABLE KEYS */;
/*!40000 ALTER TABLE `person_import_keys` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `person_province_relationships`
--

DROP TABLE IF EXISTS `person_province_relationships`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `person_province_relationships` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `relationship_type` varchar(80) NOT NULL,
  `status` enum('active','inactive','ended') NOT NULL DEFAULT 'active',
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `verified_by` bigint(20) unsigned NOT NULL,
  `verified_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_person_province_relationship` (`province_id`,`person_id`,`relationship_type`),
  KEY `idx_person_province` (`person_id`,`status`,`province_id`),
  KEY `verified_by` (`verified_by`),
  CONSTRAINT `person_province_relationships_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `person_province_relationships_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `person_province_relationships_ibfk_3` FOREIGN KEY (`verified_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `person_province_relationships`
--

LOCK TABLES `person_province_relationships` WRITE;
/*!40000 ALTER TABLE `person_province_relationships` DISABLE KEYS */;
/*!40000 ALTER TABLE `person_province_relationships` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `platform_email_templates`
--

DROP TABLE IF EXISTS `platform_email_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `platform_email_templates` (
  `template_key` varchar(80) NOT NULL,
  `display_name` varchar(150) NOT NULL,
  `subject_template` varchar(250) NOT NULL,
  `body_template` mediumtext NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 1,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`template_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `platform_email_templates`
--

LOCK TABLES `platform_email_templates` WRITE;
/*!40000 ALTER TABLE `platform_email_templates` DISABLE KEYS */;
INSERT INTO `platform_email_templates` VALUES ('attendee_meeting_invitation','Previous attendee meeting invitation','{{lodge_name}} invitation — {{meeting_title}}','Dear {{name}},\n\nYou previously booked with the Lodge and agreed that it could retain your contact details and tell you when future meeting summonses or invitations are published.\n\nThe summons or invitation for {{meeting_title}} on {{meeting_date}} at {{meeting_time}} is now available.\n\nView it here: {{summons_url}}\nBook for this meeting: {{booking_url}}\n\nIf you no longer wish to receive these invitations, please contact the Lodge using the website contact form.',1,'2026-09-27 21:01:01'),('booking_cancelled','Booking cancelled','Booking cancelled – {{booking_reference}}','<p>Your booking for {{meeting_date}} has been cancelled.</p>',1,'2026-09-27 21:01:01'),('booking_code','Booking code','Your booking code – {{booking_reference}}','<p>Dear {{name}},</p><p>Your new booking code is <strong>{{booking_code}}</strong>.</p>',1,'2026-09-27 21:01:01'),('booking_confirmation','Booking confirmation','{{lodge_name}} booking confirmation – {{meeting_date}}','Booking confirmation\n\nDear {{name}},\n\nYour attendance has been recorded for {{meeting_date}}.\n\nReference: {{booking_reference}}\nBooking & Cancellation code: {{booking_code}}\n\nTotal due: {{total_charge}}\n\n{{payment_details}}\nPayment reference: {{booking_reference}}\n\nPlease keep your booking & cancellation code safe.',1,'2026-09-27 21:01:01'),('guest_meeting_invitation','Previous guest meeting invitation','{{lodge_name}} invitation — {{meeting_title}}','Dear {{name}},\n\nYou previously attended as a guest and agreed that the Lodge could retain your details and contact you about future meetings.\n\nThe summons for {{meeting_title}} on {{meeting_date}} at {{meeting_time}} is now available.\n\nView the summons: {{summons_url}}\nBook for this meeting: {{booking_url}}\n\nIf you no longer wish to receive these invitations, please contact the Lodge using the website contact form.',1,'2026-09-27 21:01:01'),('meeting_changed','Meeting details changed','Important update – {{meeting_date}}','<p>The meeting details have changed. Please review the updated information.</p>',1,'2026-09-27 21:01:01'),('meeting_reminder','Meeting reminder','Reminder – {{meeting_title}} on {{meeting_date}}','<p>Dear {{name}},</p><p>This is a reminder that {{meeting_title}} is on {{meeting_date}} at {{meeting_time}} at {{venue_name}}.</p>',1,'2026-09-27 21:01:01'),('payment_reminder','Payment reminder','Payment reminder – {{booking_reference}}','<p>Dear {{name}},</p><p>Our records show a balance of <strong>{{balance}}</strong> for {{meeting_date}}.</p>{{payment_details}}',1,'2026-09-27 21:01:01'),('place_confirmed','Waiting-list place confirmed','Your place is confirmed – {{booking_reference}}','<p>Dear {{name}},</p><p>Your place for {{meeting_title}} on {{meeting_date}} is now confirmed.</p>',1,'2026-09-27 21:01:01'),('place_offered','Waiting-list place offered','A dining place is available','<p>A place is available until {{offer_expiry}}. Please use your booking code to accept it.</p>',1,'2026-09-27 21:01:01'),('summons_email','Summons or invitation email','{{meeting_title}} – {{document_name}}','{{meeting_title}}\n\n{{meeting_date}} at {{meeting_time}}\n{{venue_name}}\n\nYour {{document_name}} is available here:\n{{document_url}}',1,'2026-09-27 21:01:01'),('waiting_list','Waiting list confirmation','Waiting list – {{meeting_date}}','<p>You have been added to the waiting list. We will contact you if a place becomes available.</p>',1,'2026-09-27 21:01:01');
/*!40000 ALTER TABLE `platform_email_templates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `platform_order_rank_settings`
--

DROP TABLE IF EXISTS `platform_order_rank_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `platform_order_rank_settings` (
  `order_key` varchar(40) NOT NULL,
  `salutations` text DEFAULT NULL,
  `salutation_rank_links` longtext DEFAULT NULL,
  `masonic_ranks` text DEFAULT NULL,
  `active_provincial_ranks` text DEFAULT NULL,
  `past_provincial_ranks` text DEFAULT NULL,
  `active_grand_ranks` text DEFAULT NULL,
  `past_grand_ranks` text DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`order_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `platform_order_rank_settings`
--

LOCK TABLES `platform_order_rank_settings` WRITE;
/*!40000 ALTER TABLE `platform_order_rank_settings` DISABLE KEYS */;
INSERT INTO `platform_order_rank_settings` VALUES ('craft','Bro\nWBro\nVWBro\nRWBro\nMWBro','{\"Bro\":[{\"scope\":\"masonic\",\"rank\":\"Entered Apprentice\"},{\"scope\":\"masonic\",\"rank\":\"Fellow Craft\"},{\"scope\":\"masonic\",\"rank\":\"Master Mason\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Pursuivant\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Pursuivant\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Organist\"}],\"WBro\":[{\"scope\":\"provincial\",\"rank\":\"Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Assistant Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Senior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Junior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Treasurer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Inspector\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Charity Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Membership Officer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Communications Officer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Learning and Development Officer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Senior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Junior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Organise\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Pursuivant\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Steward\"},{\"scope\":\"grand\",\"rank\":\"Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Superintendent of Works\"},{\"scope\":\"grand\",\"rank\":\"Senior Grand Deacon\"},{\"scope\":\"grand\",\"rank\":\"Junior Grand Deacon\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Directors of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Sword Bearers\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Superintendents of Works\"},{\"scope\":\"grand\",\"rank\":\"Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Grand Pursuivant\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Pursiuvant\"},{\"scope\":\"grand\",\"rank\":\"Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Assistant Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Senior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Junior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Treasurer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Inspector\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Charity Steward\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Superintendent of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Senior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Membership Officer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Communications Officer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Learning and Development Officer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Senior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Junior Grand Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Junior Grand Deacon\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Directors of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Sword Bearers\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Superintendents of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Pursuivant\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Pursiuvant\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Superintendent of Works\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Organise\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Pursuivant\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Steward\"},{\"scope\":\"masonic\",\"rank\":\"Worshipful Master\"},{\"scope\":\"masonic\",\"rank\":\"Immediate Past Master\"},{\"scope\":\"masonic\",\"rank\":\"Past Master\"}],\"VWBro\":[{\"scope\":\"provincial\",\"rank\":\"Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Deputy Provincial Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Grand Chancellor\"},{\"scope\":\"grand\",\"rank\":\"President of the Masonic Charitable Foundation\"},{\"scope\":\"grand\",\"rank\":\"Deputy President of the Board of General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Deputy President of the Masonic Charitable Foundation\"},{\"scope\":\"grand\",\"rank\":\"Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Grand Superintendent of Works\"},{\"scope\":\"grand\",\"rank\":\"Grand Inspector\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Chancellor\"},{\"scope\":\"grand\",\"rank\":\"Past President of the Masonic Charitable Foundation\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy President of the Board of General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy President of the Masonic Charitable Foundation\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Superintendent of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Inspector\"}],\"RWBro\":[{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Senior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Junior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"President of the Board of General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Senior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Past Junior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Past President of the Board of General Purposes\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Master\"}],\"MWBro\":[{\"scope\":\"grand\",\"rank\":\"Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Pro Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Pro Grand Master\"}]}','Entered Apprentice\nFellow Craft\nMaster Mason\nWorshipful Master\nImmediate Past Master\nPast Master','Provincial Grand Master\nDeputy Provincial Grand Master\nAssistant Provincial Grand Master\nProvincial Senior Grand Warden\nProvincial Junior Grand Warden\nProvincial Grand Chaplain\nProvincial Grand Treasurer\nProvincial Grand Registrar\nProvincial Grand Secretary\nProvincial Grand Director of Ceremonies\nProvincial Grand Sword Bearer\nProvincial Grand Superintendent of Works\nProvincial Deputy Grand Chaplain\nProvincial Deputy Grand Registrar\nProvincial Deputy Grand Secretary\nProvincial Deputy Grand Director of Ceremonies\nProvincial Deputy Grand Sword Bearer\nProvincial Deputy Grand Superintendent of Works\nProvincial Assistant Grand Inspector\nProvincial Grand Almoner\nProvincial Grand Charity Steward\nProvincial Grand Membership Officer\nProvincial Grand Communications Officer\nProvincial Grand Learning and Development Officer\nProvincial Senior Grand Deacon\nProvincial Junior Grand Deacon\nProvincial Assistant Grand Chaplain\nProvincial Assistant Grand Registrar\nProvincial Assistant Grand Secretary\nProvincial Assistant Grand Director of Ceremonies\nProvincial Assistant Grand Sword Bearer\nProvincial Assistant Grand Superintendent of Works\nProvincial Grand Organise\nProvincial Standard Bearer\nProvincial Assistant Grand Standard Bearer\nProvincial Deputy Grand Organist\nProvincial Grand Pursuivant\nProvincial Grand Tyler\nProvincial Grand Steward','Past Provincial Grand Master\nPast Deputy Provincial Grand Master\nPast Assistant Provincial Grand Master\nPast Provincial Senior Grand Warden\nPast Provincial Junior Grand Warden\nPast Provincial Grand Chaplain\nPast Provincial Grand Treasurer\nPast Provincial Grand Registrar\nPast Provincial Grand Secretary\nPast Provincial Grand Director of Ceremonies\nPast Provincial Grand Sword Bearer\nPast Provincial Grand Superintendent of Works\nPast Provincial Deputy Grand Chaplain\nPast Provincial Deputy Grand Registrar\nPast Provincial Deputy Grand Secretary\nPast Provincial Deputy Grand Director of Ceremonies\nPast Provincial Deputy Grand Sword Bearer\nPast Provincial Deputy Grand Superintendent of Works\nPast Provincial Assistant Grand Inspector\nPast Provincial Grand Almoner\nPast Provincial Grand Charity Steward\nPast Provincial Grand Membership Officer\nPast Provincial Grand Communications Officer\nPast Provincial Grand Learning and Development Officer\nPast Provincial Senior Grand Deacon\nPast Provincial Junior Grand Deacon\nPast Provincial Assistant Grand Chaplain\nPast Provincial Assistant Grand Registrar\nPast Provincial Assistant Grand Secretary\nPast Provincial Assistant Grand Director of Ceremonies\nPast Provincial Assistant Grand Sword Bearer\nPast Provincial Assistant Grand Superintendent of Works\nPast Provincial Grand Organise\nPast Provincial Standard Bearer\nPast Provincial Assistant Grand Standard Bearer\nPast Provincial Deputy Grand Organist\nPast Provincial Grand Pursuivant\nPast Provincial Grand Tyler\nPast Provincial Grand Steward','Grand Master\nPro Grand Master\nDeputy Grand Master\nAssistant Grand Master\nSenior Grand Warden\nJunior Grand Warden\nPresident of the Board of General Purposes\nGrand Chaplain\nGrand Registrar\nGrand Secretary\nGrand Chancellor\nPresident of the Masonic Charitable Foundation\nDeputy President of the Board of General Purposes\nDeputy President of the Masonic Charitable Foundation\nGrand Director of Ceremonies\nGrand Sword Bearer\nGrand Superintendent of Works\nGrand Inspector\nGrand Treasurer\nDeputy Grand Chaplain\nDeputy Grand Registrar\nDeputy Grand Director of Ceremonies\nDeputy Grand Sword Bearer\nDeputy Grand Superintendent of Works\nSenior Grand Deacon\nJunior Grand Deacon\nAssistant Grand Chaplain\nAssistant Grand Registrar\nAssistant Grand Directors of Ceremonies\nAssistant Grand Sword Bearers\nAssistant Grand Superintendents of Works\nGrand Organist\nGrand Standard Bearer\nDeputy Grand Organist\nGrand Pursuivant\nAssistant Grand Pursiuvant\nGrand Steward','Past Grand Master\nPast Pro Grand Master\nPast Deputy Grand Master\nPast Assistant Grand Master\nPast Senior Grand Warden\nPast Junior Grand Warden\nPast President of the Board of General Purposes\nPast Grand Chaplain\nPast Grand Registrar\nPast Grand Secretary\nPast Grand Chancellor\nPast President of the Masonic Charitable Foundation\nPast Deputy President of the Board of General Purposes\nPast Deputy President of the Masonic Charitable Foundation\nPast Grand Director of Ceremonies\nPast Grand Sword Bearer\nPast Grand Superintendent of Works\nPast Grand Inspector\nPast Grand Treasurer\nPast Deputy Grand Chaplain\nPast Deputy Grand Registrar\nPast Deputy Grand Director of Ceremonies\nPast Deputy Grand Sword Bearer\nPast Deputy Grand Superintendent of Works\nPast Senior Grand Deacon\nPast Junior Grand Deacon\nPast Assistant Grand Chaplain\nPast Assistant Grand Registrar\nPast Assistant Grand Directors of Ceremonies\nPast Assistant Grand Sword Bearers\nPast Assistant Grand Superintendents of Works\nPast Grand Organist\nPast Grand Standard Bearer\nPast Deputy Grand Organist\nPast Grand Pursuivant\nPast Assistant Grand Pursiuvant\nPast Grand Steward','2026-09-27 21:01:01'),('mark','Bro\nWBro\nVWBro\nRWBro\nMWBro','{\"Bro\":[{\"scope\":\"masonic\",\"rank\":\"Mark Master Mason\"},{\"scope\":\"masonic\",\"rank\":\"Worshipful Master\"},{\"scope\":\"masonic\",\"rank\":\"Immediate Past Master\"},{\"scope\":\"masonic\",\"rank\":\"Past Master\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Tyler\"},{\"scope\":\"grand\",\"rank\":\"Grand Tyler\"},{\"scope\":\"grand\",\"rank\":\"Grand Steward\"},{\"scope\":\"grand\",\"rank\":\"Grand Inner Guard\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Inner Guard\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Inner Guard\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Steward\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Inner Guard\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Tyler\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Tyler\"}],\"WBro\":[{\"scope\":\"grand\",\"rank\":\"Grand Inspector of Works\"},{\"scope\":\"grand\",\"rank\":\"Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Deputy President of the General Board\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Deputy President of the Mark Benevolent Fund\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Inspectors of Works\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Grand Senior Deacon\"},{\"scope\":\"grand\",\"rank\":\"Grand Junior Deacon\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Directors of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Inspector of Works\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Sword Bearers\"},{\"scope\":\"grand\",\"rank\":\"Grand Librarian\"},{\"scope\":\"grand\",\"rank\":\"Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Grand Inner Guard\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Inner Guard\"},{\"scope\":\"grand\",\"rank\":\"Grand Steward\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Tyler\"},{\"scope\":\"grand\",\"rank\":\"Grand Tyler\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Tyler\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Tyler\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Steward\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Inner Guard\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Inner Guard\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Inspector of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy President of the General Board\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy President of the Mark Benevolent Fund\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Inspectors of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Senior Deacon\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Junior Deacon\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Directors of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Inspector of Works\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Sword Bearers\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Librarian\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Assistant Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Senior Warden\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Junior Warden\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Master Overseer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Senior Overseer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Junior Overseer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Treasurer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Senior Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Junior Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Charity Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Inner Guard\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Tyler\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Inner Guard\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Charity Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Junior Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Senior Deacon\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Secretary\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Treasurer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Junior Overseer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Senior Overseer\"},{\"scope\":\"provincial\",\"rank\":\"Past Assistant Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Senior Warden\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Junior Warden\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Master Overseer\"},{\"scope\":\"masonic\",\"rank\":\"Worshipful Master\"},{\"scope\":\"masonic\",\"rank\":\"Immediate Past Master\"},{\"scope\":\"masonic\",\"rank\":\"Past Master\"}],\"VWBro\":[{\"scope\":\"grand\",\"rank\":\"Grand Inspector\"},{\"scope\":\"grand\",\"rank\":\"Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"President of the Mark Benevolent Fund\"},{\"scope\":\"grand\",\"rank\":\"Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"President of the Board of General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Grand Junior Overseer\"},{\"scope\":\"grand\",\"rank\":\"Grand Senior Overseer\"},{\"scope\":\"grand\",\"rank\":\"Grand Master Overseer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Inspector\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Master Overseer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Senior Overseer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Junior Overseer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past President of the Board of General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past President of the Mark Benevolent Fund\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Secretary\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Deputy Provincial Grand Master\"}],\"RWBro\":[{\"scope\":\"grand\",\"rank\":\"Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Senior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Junior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Senior Grand Warden\"},{\"scope\":\"grand\",\"rank\":\"Past Junior Grand Warden\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Master\"}],\"MWBro\":[{\"scope\":\"grand\",\"rank\":\"Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Pro Grand Master\"}]}','Mark Master Mason\nWorshipful Master\nImmediate Past Master\nPast Master','Provincial Grand Master\nDeputy Provincial Grand Master\nAssistant Provincial Grand Master\nProvincial Grand Senior Warden\nProvincial Grand Junior Warden\nProvincial Grand Master Overseer\nProvincial Grand Senior Overseer\nProvincial Grand Junior Overseer\nProvincial Grand Chaplain\nProvincial Grand Treasurer\nProvincial Grand Registrar\nProvincial Grand Secretary\nProvincial Grand Director of Ceremonies\nProvincial Grand Senior Deacon\nProvincial Grand Junior Deacon\nProvincial Assistant Grand Chaplain\nProvincial Assistant Grand Charity Steward\nProvincial Assistant Grand Almoner\nProvincial Grand Organist\nProvincial Grand Standard Bearer\nProvincial Assistant Grand Standard Bearer\nProvincial Grand Inner Guard\nProvincial Grand Steward\nProvincial Grand Tyler','Past Provincial Grand Master\nPast Deputy Provincial Grand Master\nPast Assistant Provincial Grand Master\nPast Provincial Grand Senior Warden\nPast Provincial Grand Junior Warden\nPast Provincial Grand Master Overseer\nPast Provincial Grand Senior Overseer\nPast Provincial Grand Junior Overseer\nPast Provincial Grand Chaplain\nPast Provincial Grand Treasurer\nPast Provincial Grand Registrar\nPast Provincial Grand Secretary\nPast Provincial Grand Director of Ceremonies\nPast Provincial Grand Senior Deacon\nPast Provincial Grand Junior Deacon\nPast Provincial Assistant Grand Chaplain\nPast Provincial Assistant Grand Charity Steward\nPast Provincial Assistant Grand Almoner\nPast Provincial Grand Organist\nPast Provincial Grand Standard Bearer\nPast Provincial Assistant Grand Standard Bearer\nPast Provincial Grand Inner Guard\nPast Provincial Grand Steward\nPast Provincial Grand Tyler','Grand Master\nPro Grand Master\nDeputy Grand Master\nAssistant Grand Master\nSenior Grand Warden\nJunior Grand Warden\nGrand Inspector\nGrand Master Overseer\nGrand Senior Overseer\nGrand Junior Overseer\nGrand Chaplain\nPresident of the Board of General Purposes\nGrand Treasurer\nGrand Registrar\nPresident of the Mark Benevolent Fund\nGrand Secretary\nGrand Director of Ceremonies\nGrand Inspector of Works\nGrand Sword Bearer\nDeputy Grand Chaplain\nDeputy President of the General Board\nDeputy Grand Registrar\nDeputy President of the Mark Benevolent Fund\nDeputy Grand Secretary\nDeputy Grand Director of Ceremonies\nDeputy Grand Inspectors of Works\nDeputy Grand Sword Bearer\nGrand Senior Deacon\nGrand Junior Deacon\nAssistant Grand Chaplain\nAssistant Grand Registrar\nAssistant Grand Secretary\nAssistant Grand Directors of Ceremonies\nAssistant Grand Inspector of Works\nAssistant Grand Sword Bearers\nGrand Librarian\nGrand Organist\nGrand Standard Bearer\nAssistant Grand Standard Bearer\nDeputy Grand Organist\nGrand Inner Guard\nAssistant Grand Inner Guard\nGrand Steward\nGrand Tyler\nDeputy Grand Tyler','Past Grand Master\nPro Grand Master\nPast Deputy Grand Master\nPast Assistant Grand Master\nPast Senior Grand Warden\nPast Junior Grand Warden\nPast Grand Inspector\nPast Grand Master Overseer\nPast Grand Senior Overseer\nPast Grand Junior Overseer\nPast Grand Chaplain\nPast President of the Board of General Purposes\nPast Grand Treasurer\nPast Grand Registrar\nPast President of the Mark Benevolent Fund\nPast Grand Secretary\nPast Grand Director of Ceremonies\nPast Grand Inspector of Works\nPast Grand Sword Bearer\nPast Deputy Grand Chaplain\nPast Deputy President of the General Board\nPast Deputy Grand Registrar\nPast Deputy President of the Mark Benevolent Fund\nPast Deputy Grand Secretary\nPast Deputy Grand Director of Ceremonies\nPast Deputy Grand Inspectors of Works\nPast Deputy Grand Sword Bearer\nPast Grand Senior Deacon\nPast Grand Junior Deacon\nPast Assistant Grand Chaplain\nPast Assistant Grand Registrar\nPast Assistant Grand Secretary\nPast Assistant Grand Directors of Ceremonies\nPast Assistant Grand Inspector of Works\nPast Assistant Grand Sword Bearers\nPast Grand Librarian\nPast Grand Organist\nPast Grand Standard Bearer\nPast Assistant Grand Standard Bearer\nPast Deputy Grand Organist\nPast Grand Inner Guard\nPast Assistant Grand Inner Guard\nPast Grand Steward\nPast Grand Tyler\nPast Deputy Grand Tyler','2026-09-27 21:01:01'),('royal_arch','Comp\nEComp\nMEComp','{\"Comp\":[{\"scope\":\"masonic\",\"rank\":\"Companion\"}],\"EComp\":[{\"scope\":\"masonic\",\"rank\":\"MEZ\"},{\"scope\":\"masonic\",\"rank\":\"IPZ\"},{\"scope\":\"masonic\",\"rank\":\"PZ\"},{\"scope\":\"grand\",\"rank\":\"President of the Committee General Purposes\"},{\"scope\":\"grand\",\"rank\":\"Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Grand Scribe Ezra\"},{\"scope\":\"grand\",\"rank\":\"Grand Scribe Nehemiah\"},{\"scope\":\"grand\",\"rank\":\"Grand Director of Cermonies\"},{\"scope\":\"grand\",\"rank\":\"Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Grand Inspector\"},{\"scope\":\"grand\",\"rank\":\"Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Scribe Ezra\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Principal Grand Sojourner\"},{\"scope\":\"grand\",\"rank\":\"First Assistant Grand Sojourner\"},{\"scope\":\"grand\",\"rank\":\"Second Assistant Grand Sojourner\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Scribe Ezra\"},{\"scope\":\"grand\",\"rank\":\"Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Grand Janitor\"},{\"scope\":\"provincial\",\"rank\":\"Deputy Grand Superintendent\"},{\"scope\":\"provincial\",\"rank\":\"Second Provincial Grand Principal\"},{\"scope\":\"provincial\",\"rank\":\"Third Provincial Grand Principal\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Scribe Ezra\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Scribe Nehemiah\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Treasurer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Scribe Ezra\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Deputy Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Inspectors\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Charity Steward\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Membership Officer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Communications Officer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Sojourner\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Mentor\"},{\"scope\":\"provincial\",\"rank\":\"Provincial First Assistant Grand Sojourner\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Second Assistant Grand Sojourner\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Scribe Ezra\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Assistant Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Janitor\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Janitor\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Scribe Ezra\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Second Assistant Grand Sojourner\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial First Assistant Grand Sojourner\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Sojourner\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Mentor\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Communications Officer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Membership Officer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Charity Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Assistant Grand Inspectors\"},{\"scope\":\"provincial\",\"rank\":\"Past Deputy Grand Superintendent\"},{\"scope\":\"provincial\",\"rank\":\"Past Second Provincial Grand Principal\"},{\"scope\":\"provincial\",\"rank\":\"Past Third Provincial Grand Principal\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Scribe Ezra\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Scribe Nehemiah\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Treasurer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Registrar\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Scribe Ezra\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Janitor\"},{\"scope\":\"grand\",\"rank\":\"Past Past Assistant Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Standard Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Scribe Ezra\"},{\"scope\":\"grand\",\"rank\":\"Past Second Assistant Grand Sojourner\"},{\"scope\":\"grand\",\"rank\":\"Past First Assistant Grand Sojourner\"},{\"scope\":\"grand\",\"rank\":\"Past Principal Grand Sojourner\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Scribe Ezra\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Inspector\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Director of Cermonies\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Scribe Nehemiah\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Scribe Ezra\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Registrar\"},{\"scope\":\"grand\",\"rank\":\"Past President of the Committee General Purposes\"}],\"MEComp\":[{\"scope\":\"grand\",\"rank\":\"First Grand Principal\"},{\"scope\":\"grand\",\"rank\":\"Pro First Grand Principal\"},{\"scope\":\"grand\",\"rank\":\"Second Grand Principal\"},{\"scope\":\"grand\",\"rank\":\"Third Grand Principal\"},{\"scope\":\"grand\",\"rank\":\"Past First Grand Principal\"},{\"scope\":\"grand\",\"rank\":\"Past Pro First Grand Principal\"},{\"scope\":\"grand\",\"rank\":\"Past Second Grand Principal\"},{\"scope\":\"grand\",\"rank\":\"Past Third Grand Principal\"},{\"scope\":\"provincial\",\"rank\":\"Most Excellent Grand Superintendent\"},{\"scope\":\"provincial\",\"rank\":\"Past Most Excellent Grand Superintendent\"}]}','Companion\nMEZ\nIPZ\nPZ','Most Excellent Grand Superintendent\nDeputy Grand Superintendent\nSecond Provincial Grand Principal\nThird Provincial Grand Principal\nProvincial Grand Scribe Ezra\nProvincial Grand Scribe Nehemiah\nProvincial Grand Treasurer\nProvincial Grand Registrar\nProvincial Grand Director of Ceremonies\nProvincial Grand Sword Bearer\nProvincial Deputy Grand Registrar\nProvincial Deputy Grand Scribe Ezra\nProvincial Deputy Grand Director of Ceremonies\nProvincial Assistant Grand Inspectors\nProvincial Grand Almoner\nProvincial Grand Charity Steward\nProvincial Grand Membership Officer\nProvincial Grand Communications Officer\nProvincial Grand Mentor\nProvincial Grand Sojourner\nProvincial First Assistant Grand Sojourner\nProvincial Second Assistant Grand Sojourner\nProvincial Assistant Grand Scribe Ezra\nProvincial Grand Standard Bearer\nProvincial Grand Organist\nProvincial Assistant Grand Director of Ceremonies\nProvincial Grand Janitor\nProvincial Grand Steward','Past Most Excellent Grand Superintendent\nPast Deputy Grand Superintendent\nPast Second Provincial Grand Principal\nPast Third Provincial Grand Principal\nPast Provincial Grand Scribe Ezra\nPast Provincial Grand Scribe Nehemiah\nPast Provincial Grand Treasurer\nPast Provincial Grand Registrar\nPast Provincial Grand Director of Ceremonies\nPast Provincial Grand Sword Bearer\nPast Provincial Deputy Grand Registrar\nPast Provincial Deputy Grand Scribe Ezra\nPast Provincial Deputy Grand Director of Ceremonies\nPast Provincial Assistant Grand Inspectors\nPast Provincial Grand Almoner\nPast Provincial Grand Charity Steward\nPast Provincial Grand Membership Officer\nPast Provincial Grand Communications Officer\nPast Provincial Grand Mentor\nPast Provincial Grand Sojourner\nPast Provincial First Assistant Grand Sojourner\nPast Provincial Second Assistant Grand Sojourner\nPast Provincial Assistant Grand Scribe Ezra\nPast Provincial Grand Standard Bearer\nPast Provincial Grand Organist\nPast Provincial Assistant Grand Director of Ceremonies\nPast Provincial Grand Janitor\nPast Provincial Grand Steward','First Grand Principal\nPro First Grand Principal\nSecond Grand Principal\nThird Grand Principal\nPresident of the Committee General Purposes\nGrand Registrar\nGrand Scribe Ezra\nGrand Scribe Nehemiah\nGrand Director of Cermonies\nGrand Sword Bearer\nGrand Inspector\nGrand Treasurer\nDeputy Grand Registrar\nDeputy Grand Scribe Ezra\nDeputy Grand Director of Ceremonies\nDeputy Grand Sword Bearer\nPrincipal Grand Sojourner\nFirst Assistant Grand Sojourner\nSecond Assistant Grand Sojourner\nAssistant Grand Scribe Ezra\nGrand Standard Bearer\nGrand Organist\nPast Assistant Grand Director of Ceremonies\nGrand Janitor','Past First Grand Principal\nPast Pro First Grand Principal\nPast Second Grand Principal\nPast Third Grand Principal\nPast President of the Committee General Purposes\nPast Grand Registrar\nPast Grand Scribe Ezra\nPast Grand Scribe Nehemiah\nPast Grand Director of Cermonies\nPast Grand Sword Bearer\nPast Grand Inspector\nPast Grand Treasurer\nPast Deputy Grand Registrar\nPast Deputy Grand Scribe Ezra\nPast Deputy Grand Director of Ceremonies\nPast Deputy Grand Sword Bearer\nPast Principal Grand Sojourner\nPast First Assistant Grand Sojourner\nPast Second Assistant Grand Sojourner\nPast Assistant Grand Scribe Ezra\nPast Grand Standard Bearer\nPast Grand Organist\nPast Past Assistant Grand Director of Ceremonies\nPast Grand Janitor','2026-09-27 21:01:01'),('royal_ark_mariners','Bro\nWBro\nRWBro\nMWBro','{\"Bro\":[{\"scope\":\"masonic\",\"rank\":\"Royal Ark Mariner\"},{\"scope\":\"provincial\",\"rank\":\"Royal Ark Mariner Provincial Grand Rank\"},{\"scope\":\"provincial\",\"rank\":\"Past Royal Ark Mariner Provincial Grand Rank\"}],\"WBro\":[{\"scope\":\"grand\",\"rank\":\"Royal Ark Mariner Grand Rank\"},{\"scope\":\"grand\",\"rank\":\"Grand Master\'s Royal Ark Council Honoris Causa\"},{\"scope\":\"grand\",\"rank\":\"Member of the Grand Master\'s Royal Ark Council\"},{\"scope\":\"grand\",\"rank\":\"Past Royal Ark Mariner Grand Rank\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Master\'s Royal Ark Council Honoris Causa\"},{\"scope\":\"provincial\",\"rank\":\"Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Assistant Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Royal Ark Mariner Provincial Grand Rank\"},{\"scope\":\"provincial\",\"rank\":\"Past Deputy Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Assistant Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Royal Ark Mariner Provincial Grand Rank\"},{\"scope\":\"grand\",\"rank\":\"Past Member of the Grand Master\'s Royal Ark Council\"}],\"RWBro\":[{\"scope\":\"grand\",\"rank\":\"Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Member of the Grand Master\'s Royal Ark Council\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Member of the Grand Master\'s Royal Ark Council\"},{\"scope\":\"provincial\",\"rank\":\"Provincial Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past Provincial Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Grand Master\'s Royal Ark Council Honoris Causa\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Master\'s Royal Ark Council Honoris Causa\"}],\"MWBro\":[{\"scope\":\"grand\",\"rank\":\"Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Pro Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Pro Grand Master\"}]}','Royal Ark Mariner\nWorshipful Commander\nImmediate Past Commander\nPast Commander','Provincial Grand Master\nDeputy Provincial Grand Master\nAssistant Provincial Grand Master\nRoyal Ark Mariner Provincial Grand Rank','Past Provincial Grand Master\nPast Deputy Provincial Grand Master\nPast Assistant Provincial Grand Master\nPast Royal Ark Mariner Provincial Grand Rank','Grand Master\nPro Grand Master\nDeputy Grand Master\nAssistant Grand Master\nMember of the Grand Master\'s Royal Ark Council\nGrand Master\'s Royal Ark Council Honoris Causa\nRoyal Ark Mariner Grand Rank','Past Grand Master\nPast Pro Grand Master\nPast Deputy Grand Master\nPast Assistant Grand Master\nPast Member of the Grand Master\'s Royal Ark Council\nPast Grand Master\'s Royal Ark Council Honoris Causa\nPast Royal Ark Mariner Grand Rank','2026-09-27 21:01:01'),('royal_select','Comp\nIll.\nV.Ill\nR.Ill.\nM.Ill.','{\"Comp\":[{\"scope\":\"masonic\",\"rank\":\"Select Master\"},{\"scope\":\"masonic\",\"rank\":\"Royal Master\"},{\"scope\":\"masonic\",\"rank\":\"Most Excellent Master\"},{\"scope\":\"masonic\",\"rank\":\"Super-Excellent Master\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Sentinel\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Manciple\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Manciple\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Sentinel\"}],\"Ill.\":[{\"scope\":\"grand\",\"rank\":\"Deputy Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Grand Sentinel\"},{\"scope\":\"grand\",\"rank\":\"Grand Manciple\"},{\"scope\":\"grand\",\"rank\":\"Grand Steward\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Recorder\"},{\"scope\":\"grand\",\"rank\":\"Grand Conductor of the Council\"},{\"scope\":\"grand\",\"rank\":\"Assistant Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Grand Captain of the Guard\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Recorder\"},{\"scope\":\"grand\",\"rank\":\"Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Recorder\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Captain of the Guard\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Conductor of the Council\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Recorder\"},{\"scope\":\"grand\",\"rank\":\"Past Assistant Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Sword Bearer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Organist\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Steward\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Manciple\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Sentinel\"},{\"scope\":\"provincial\",\"rank\":\"Deputy District Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"District Principal Conductor of the Work\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Recorder\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Lecturer\"},{\"scope\":\"provincial\",\"rank\":\"District Deputy Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Captain of the Guard\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"District Assistant Grand Recorder\"},{\"scope\":\"provincial\",\"rank\":\"District Assistant Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Manciple\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Sentinel\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Sentinel\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Manciple\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Steward\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Organist\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Standard Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Sword Bearer\"},{\"scope\":\"provincial\",\"rank\":\"Past District Assistant Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past District Assistant Grand Recorder\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Almoner\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Captain of the Guard\"},{\"scope\":\"provincial\",\"rank\":\"Past District Deputy Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Lecturer\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Director of Ceremonies\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Recorder\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Chaplain\"},{\"scope\":\"provincial\",\"rank\":\"Past District Principal Conductor of the Work\"},{\"scope\":\"provincial\",\"rank\":\"Past Deputy District Grand Master\"}],\"V.Ill\":[{\"scope\":\"grand\",\"rank\":\"Grand Inspector\"},{\"scope\":\"grand\",\"rank\":\"Grand Historiographer\"},{\"scope\":\"grand\",\"rank\":\"Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"President of the Executive Committee\"},{\"scope\":\"grand\",\"rank\":\"Grand Recorder\"},{\"scope\":\"grand\",\"rank\":\"Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Grand Lecturer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Inspector\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Chaplain\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Treasurer\"},{\"scope\":\"grand\",\"rank\":\"Past President of the Executive Committee\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Recorder\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Director of Ceremonies\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Lecturer\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Historiographer\"}],\"R.Ill.\":[{\"scope\":\"grand\",\"rank\":\"Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Grand Councillor\"},{\"scope\":\"grand\",\"rank\":\"Grand Principal Conductor of the Work\"},{\"scope\":\"grand\",\"rank\":\"Order of Service to Cryptic Masonry\"},{\"scope\":\"grand\",\"rank\":\"Custodian of the Ninth Arch\"},{\"scope\":\"grand\",\"rank\":\"Grand Chancellor\"},{\"scope\":\"grand\",\"rank\":\"Past Deputy Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Principal Conductor of the Work\"},{\"scope\":\"grand\",\"rank\":\"Past Order of Service to Cryptic Masonry\"},{\"scope\":\"grand\",\"rank\":\"Past Custodian of the Ninth Arch\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Chancellor\"},{\"scope\":\"provincial\",\"rank\":\"District Grand Master\"},{\"scope\":\"provincial\",\"rank\":\"Past District Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Councillor\"}],\"M.Ill.\":[{\"scope\":\"grand\",\"rank\":\"Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Pro Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Grand Master\"},{\"scope\":\"grand\",\"rank\":\"Past Pro Grand Master\"}]}','Select Master\nRoyal Master\nMost Excellent Master\nSuper-Excellent Master\nThrice Illustrious Master\nExcellent Master','District Grand Master\nDeputy District Grand Master\nDistrict Principal Conductor of the Work\nDistrict Grand Chaplain\nDistrict Grand Recorder\nDistrict Grand Director of Ceremonies\nDistrict Grand Lecturer\nDistrict Deputy Grand Director of Ceremonies\nDistrict Grand Captain of the Guard\nDistrict Grand Almoner\nDistrict Assistant Grand Recorder\nDistrict Assistant Grand Director of Ceremonies\nDistrict Grand Sword Bearer\nDistrict Grand Standard Bearer\nDistrict Grand Organist\nDistrict Grand Steward\nDistrict Grand Manciple\nDistrict Grand Sentinel','Past District Grand Master\nPast Deputy District Grand Master\nPast District Principal Conductor of the Work\nPast District Grand Chaplain\nPast District Grand Recorder\nPast District Grand Director of Ceremonies\nPast District Grand Lecturer\nPast District Deputy Grand Director of Ceremonies\nPast District Grand Captain of the Guard\nPast District Grand Almoner\nPast District Assistant Grand Recorder\nPast District Assistant Grand Director of Ceremonies\nPast District Grand Sword Bearer\nPast District Grand Standard Bearer\nPast District Grand Organist\nPast District Grand Steward\nPast District Grand Manciple\nPast District Grand Sentinel','Grand Master\nPro Grand Master\nDeputy Grand Master\nGrand Principal Conductor of the Work\nOrder of Service to Cryptic Masonry\nCustodian of the Ninth Arch\nGrand Chancellor\nGrand Councillor\nGrand Inspector\nGrand Chaplain\nGrand Treasurer\nPresident of the Executive Committee\nGrand Recorder\nGrand Director of Ceremonies\nGrand Lecturer\nGrand Historiographer\nDeputy Grand Chaplain\nDeputy Grand Recorder\nDeputy Grand Director of Ceremonies\nGrand Captain of the Guard\nGrand Conductor of the Council\nAssistant Grand Chaplain\nAssistant Grand Recorder\nAssistant Grand Director of Ceremonies\nGrand Sword Bearer\nGrand Organist\nDeputy Grand Organist\nGrand Steward\nGrand Manciple\nGrand Sentinel','Past Grand Master\nPast Pro Grand Master\nPast Deputy Grand Master\nPast Grand Principal Conductor of the Work\nPast Order of Service to Cryptic Masonry\nPast Custodian of the Ninth Arch\nPast Grand Chancellor\nPast Grand Councillor\nPast Grand Inspector\nPast Grand Chaplain\nPast Grand Treasurer\nPast President of the Executive Committee\nPast Grand Recorder\nPast Grand Director of Ceremonies\nPast Grand Lecturer\nPast Grand Historiographer\nPast Deputy Grand Chaplain\nPast Deputy Grand Recorder\nPast Deputy Grand Director of Ceremonies\nPast Grand Captain of the Guard\nPast Grand Conductor of the Council\nPast Assistant Grand Chaplain\nPast Assistant Grand Recorder\nPast Assistant Grand Director of Ceremonies\nPast Grand Sword Bearer\nPast Grand Organist\nPast Deputy Grand Organist\nPast Grand Steward\nPast Grand Manciple\nPast Grand Sentinel','2026-09-27 21:01:01');
/*!40000 ALTER TABLE `platform_order_rank_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `postal_address_exports`
--

DROP TABLE IF EXISTS `postal_address_exports`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `postal_address_exports` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `snapshot_id` bigint(20) unsigned NOT NULL,
  `token_hash` char(64) NOT NULL,
  `export_kind` enum('labels','letters') NOT NULL,
  `payload_cipher` longtext NOT NULL,
  `expires_at` datetime NOT NULL,
  `downloaded_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_postal_export_token` (`token_hash`),
  KEY `idx_postal_export` (`unit_id`,`snapshot_id`,`expires_at`),
  KEY `snapshot_id` (`snapshot_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `postal_address_exports_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `postal_address_exports_ibfk_2` FOREIGN KEY (`snapshot_id`) REFERENCES `meeting_publication_snapshots` (`id`) ON DELETE CASCADE,
  CONSTRAINT `postal_address_exports_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `postal_address_exports`
--

LOCK TABLES `postal_address_exports` WRITE;
/*!40000 ALTER TABLE `postal_address_exports` DISABLE KEYS */;
/*!40000 ALTER TABLE `postal_address_exports` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `postal_dispatch_history`
--

DROP TABLE IF EXISTS `postal_dispatch_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `postal_dispatch_history` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `dispatch_id` bigint(20) unsigned NOT NULL,
  `from_status` varchar(30) DEFAULT NULL,
  `to_status` varchar(30) NOT NULL,
  `note` varchar(500) DEFAULT NULL,
  `actor_user_id` bigint(20) unsigned NOT NULL,
  `occurred_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_postal_history` (`dispatch_id`,`occurred_at`,`id`),
  KEY `actor_user_id` (`actor_user_id`),
  CONSTRAINT `postal_dispatch_history_ibfk_1` FOREIGN KEY (`dispatch_id`) REFERENCES `postal_dispatches` (`id`) ON DELETE CASCADE,
  CONSTRAINT `postal_dispatch_history_ibfk_2` FOREIGN KEY (`actor_user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `postal_dispatch_history`
--

LOCK TABLES `postal_dispatch_history` WRITE;
/*!40000 ALTER TABLE `postal_dispatch_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `postal_dispatch_history` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER postal_dispatch_history_no_update BEFORE UPDATE ON postal_dispatch_history FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Postal history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER postal_dispatch_history_no_delete BEFORE DELETE ON postal_dispatch_history FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Postal history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `postal_dispatches`
--

DROP TABLE IF EXISTS `postal_dispatches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `postal_dispatches` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `recipient_id` bigint(20) unsigned NOT NULL,
  `snapshot_id` bigint(20) unsigned NOT NULL,
  `status` enum('ready','exported','posted','returned','undeliverable','cancelled') NOT NULL DEFAULT 'ready',
  `exported_at` datetime DEFAULT NULL,
  `posted_at` datetime DEFAULT NULL,
  `returned_at` datetime DEFAULT NULL,
  `status_note` varchar(500) DEFAULT NULL,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_postal_dispatch_recipient` (`recipient_id`),
  KEY `idx_postal_queue` (`snapshot_id`,`status`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `postal_dispatches_ibfk_1` FOREIGN KEY (`recipient_id`) REFERENCES `meeting_publication_recipients` (`id`) ON DELETE CASCADE,
  CONSTRAINT `postal_dispatches_ibfk_2` FOREIGN KEY (`snapshot_id`) REFERENCES `meeting_publication_snapshots` (`id`) ON DELETE CASCADE,
  CONSTRAINT `postal_dispatches_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `postal_dispatches`
--

LOCK TABLES `postal_dispatches` WRITE;
/*!40000 ALTER TABLE `postal_dispatches` DISABLE KEYS */;
/*!40000 ALTER TABLE `postal_dispatches` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_diners`
--

DROP TABLE IF EXISTS `programme_diners`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_diners` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `programme_id` bigint(20) unsigned NOT NULL,
  `person_key` char(64) NOT NULL,
  `booking_id` bigint(20) unsigned NOT NULL,
  `guest_id` bigint(20) unsigned DEFAULT NULL,
  `diner_kind` enum('main','guest') NOT NULL,
  `display_name` varchar(240) NOT NULL,
  `dietary_requirements` text DEFAULT NULL,
  `allergy_details` text DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_programme_diner` (`programme_id`,`person_key`),
  UNIQUE KEY `uq_booking_guest_diner` (`booking_id`,`guest_id`),
  KEY `idx_programme_diner_booking` (`booking_id`,`active`),
  KEY `guest_id` (`guest_id`),
  CONSTRAINT `programme_diners_ibfk_1` FOREIGN KEY (`programme_id`) REFERENCES `event_programmes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_diners_ibfk_2` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_diners_ibfk_3` FOREIGN KEY (`guest_id`) REFERENCES `guests` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=108 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_diners`
--

LOCK TABLES `programme_diners` WRITE;
/*!40000 ALTER TABLE `programme_diners` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_diners` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_menu_courses`
--

DROP TABLE IF EXISTS `programme_menu_courses`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_menu_courses` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `menu_version_id` bigint(20) unsigned NOT NULL,
  `stable_key` char(36) NOT NULL,
  `name` varchar(120) NOT NULL,
  `description` varchar(1000) DEFAULT NULL,
  `display_order` int(10) unsigned NOT NULL,
  `selection_required` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_menu_course_key` (`menu_version_id`,`stable_key`),
  KEY `idx_menu_course_order` (`menu_version_id`,`display_order`),
  CONSTRAINT `programme_menu_courses_ibfk_1` FOREIGN KEY (`menu_version_id`) REFERENCES `programme_menu_versions` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_menu_courses`
--

LOCK TABLES `programme_menu_courses` WRITE;
/*!40000 ALTER TABLE `programme_menu_courses` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_menu_courses` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_menu_dishes`
--

DROP TABLE IF EXISTS `programme_menu_dishes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_menu_dishes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `course_id` bigint(20) unsigned NOT NULL,
  `stable_key` char(36) NOT NULL,
  `name` varchar(180) NOT NULL,
  `description` varchar(1500) DEFAULT NULL,
  `available` tinyint(1) NOT NULL DEFAULT 1,
  `supplement` decimal(10,2) NOT NULL DEFAULT 0.00,
  `allergen_summary` varchar(2000) DEFAULT NULL,
  `allergen_verified_at` datetime DEFAULT NULL,
  `allergen_verified_by` bigint(20) unsigned DEFAULT NULL,
  `display_order` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_menu_dish_key` (`course_id`,`stable_key`),
  KEY `idx_menu_dish_available` (`course_id`,`available`,`display_order`),
  KEY `allergen_verified_by` (`allergen_verified_by`),
  CONSTRAINT `programme_menu_dishes_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `programme_menu_courses` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_menu_dishes_ibfk_2` FOREIGN KEY (`allergen_verified_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `chk_dish_supplement` CHECK (`supplement` >= 0)
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_menu_dishes`
--

LOCK TABLES `programme_menu_dishes` WRITE;
/*!40000 ALTER TABLE `programme_menu_dishes` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_menu_dishes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_menu_versions`
--

DROP TABLE IF EXISTS `programme_menu_versions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_menu_versions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `programme_id` bigint(20) unsigned NOT NULL,
  `version_no` int(10) unsigned NOT NULL,
  `status` enum('draft','published','retired') NOT NULL DEFAULT 'draft',
  `title` varchar(180) NOT NULL DEFAULT 'Dining menu',
  `change_note` varchar(1000) DEFAULT NULL,
  `published_by` bigint(20) unsigned DEFAULT NULL,
  `published_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_programme_menu_version` (`programme_id`,`version_no`),
  KEY `idx_programme_menu_status` (`programme_id`,`status`),
  KEY `published_by` (`published_by`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `programme_menu_versions_ibfk_1` FOREIGN KEY (`programme_id`) REFERENCES `event_programmes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_menu_versions_ibfk_2` FOREIGN KEY (`published_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `programme_menu_versions_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_menu_versions`
--

LOCK TABLES `programme_menu_versions` WRITE;
/*!40000 ALTER TABLE `programme_menu_versions` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_menu_versions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_plan_seats`
--

DROP TABLE IF EXISTS `programme_plan_seats`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_plan_seats` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `table_id` bigint(20) unsigned NOT NULL,
  `seat_number` smallint(5) unsigned NOT NULL,
  `x_pos` decimal(8,2) DEFAULT NULL,
  `y_pos` decimal(8,2) DEFAULT NULL,
  `locked` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_plan_seat` (`table_id`,`seat_number`),
  CONSTRAINT `programme_plan_seats_ibfk_1` FOREIGN KEY (`table_id`) REFERENCES `programme_plan_tables` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_plan_seats`
--

LOCK TABLES `programme_plan_seats` WRITE;
/*!40000 ALTER TABLE `programme_plan_seats` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_plan_seats` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_plan_tables`
--

DROP TABLE IF EXISTS `programme_plan_tables`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_plan_tables` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `plan_id` bigint(20) unsigned NOT NULL,
  `stable_key` char(36) NOT NULL,
  `table_number` varchar(30) NOT NULL,
  `table_name` varchar(100) DEFAULT NULL,
  `shape` enum('round','rectangular') NOT NULL DEFAULT 'round',
  `is_top_table` tinyint(1) NOT NULL DEFAULT 0,
  `x_pos` decimal(8,2) NOT NULL,
  `y_pos` decimal(8,2) NOT NULL,
  `width` decimal(8,2) NOT NULL,
  `height` decimal(8,2) NOT NULL,
  `capacity` smallint(5) unsigned NOT NULL,
  `display_order` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_plan_table_key` (`plan_id`,`stable_key`),
  UNIQUE KEY `uq_plan_table_number` (`plan_id`,`table_number`),
  CONSTRAINT `programme_plan_tables_ibfk_1` FOREIGN KEY (`plan_id`) REFERENCES `programme_table_plans` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_plan_table_size` CHECK (`width` > 0 and `height` > 0 and `capacity` > 0)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_plan_tables`
--

LOCK TABLES `programme_plan_tables` WRITE;
/*!40000 ALTER TABLE `programme_plan_tables` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_plan_tables` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_seat_assignments`
--

DROP TABLE IF EXISTS `programme_seat_assignments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_seat_assignments` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `plan_id` bigint(20) unsigned NOT NULL,
  `seat_id` bigint(20) unsigned NOT NULL,
  `diner_id` bigint(20) unsigned NOT NULL,
  `assigned_by` bigint(20) unsigned NOT NULL,
  `assigned_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_plan_assigned_seat` (`seat_id`),
  UNIQUE KEY `uq_plan_assigned_diner` (`plan_id`,`diner_id`),
  KEY `diner_id` (`diner_id`),
  KEY `assigned_by` (`assigned_by`),
  CONSTRAINT `programme_seat_assignments_ibfk_1` FOREIGN KEY (`plan_id`) REFERENCES `programme_table_plans` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_seat_assignments_ibfk_2` FOREIGN KEY (`seat_id`) REFERENCES `programme_plan_seats` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_seat_assignments_ibfk_3` FOREIGN KEY (`diner_id`) REFERENCES `programme_diners` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_seat_assignments_ibfk_4` FOREIGN KEY (`assigned_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_seat_assignments`
--

LOCK TABLES `programme_seat_assignments` WRITE;
/*!40000 ALTER TABLE `programme_seat_assignments` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_seat_assignments` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_seating_preferences`
--

DROP TABLE IF EXISTS `programme_seating_preferences`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_seating_preferences` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `programme_id` bigint(20) unsigned NOT NULL,
  `diner_id` bigint(20) unsigned NOT NULL,
  `preference_type` enum('sit_together','keep_apart','honoured_visitor','accessibility','host_pairing') NOT NULL,
  `related_diner_id` bigint(20) unsigned DEFAULT NULL,
  `hard_constraint` tinyint(1) NOT NULL DEFAULT 0,
  `public_label` varchar(160) DEFAULT NULL,
  `private_reason_cipher` text DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_seating_preference` (`programme_id`,`diner_id`,`active`),
  KEY `diner_id` (`diner_id`),
  KEY `related_diner_id` (`related_diner_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `programme_seating_preferences_ibfk_1` FOREIGN KEY (`programme_id`) REFERENCES `event_programmes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_seating_preferences_ibfk_2` FOREIGN KEY (`diner_id`) REFERENCES `programme_diners` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_seating_preferences_ibfk_3` FOREIGN KEY (`related_diner_id`) REFERENCES `programme_diners` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_seating_preferences_ibfk_4` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_seating_preferences`
--

LOCK TABLES `programme_seating_preferences` WRITE;
/*!40000 ALTER TABLE `programme_seating_preferences` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_seating_preferences` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `programme_table_plan_revisions`
--

DROP TABLE IF EXISTS `programme_table_plan_revisions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_table_plan_revisions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `plan_id` bigint(20) unsigned NOT NULL,
  `revision_no` int(10) unsigned NOT NULL,
  `action` varchar(60) NOT NULL,
  `change_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`change_json`)),
  `actor_user_id` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_plan_revision` (`plan_id`,`revision_no`),
  KEY `actor_user_id` (`actor_user_id`),
  CONSTRAINT `programme_table_plan_revisions_ibfk_1` FOREIGN KEY (`plan_id`) REFERENCES `programme_table_plans` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_table_plan_revisions_ibfk_2` FOREIGN KEY (`actor_user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_table_plan_revisions`
--

LOCK TABLES `programme_table_plan_revisions` WRITE;
/*!40000 ALTER TABLE `programme_table_plan_revisions` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_table_plan_revisions` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER plan_revision_no_update BEFORE UPDATE ON programme_table_plan_revisions FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Table plan history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER plan_revision_no_delete BEFORE DELETE ON programme_table_plan_revisions FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Table plan history is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `programme_table_plan_snapshots`
--

DROP TABLE IF EXISTS `programme_table_plan_snapshots`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_table_plan_snapshots` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `plan_id` bigint(20) unsigned NOT NULL,
  `snapshot_no` int(10) unsigned NOT NULL,
  `payload_json` longtext NOT NULL,
  `source_fingerprint` char(64) NOT NULL,
  `published_by` bigint(20) unsigned NOT NULL,
  `published_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_plan_snapshot` (`plan_id`,`snapshot_no`),
  KEY `published_by` (`published_by`),
  CONSTRAINT `programme_table_plan_snapshots_ibfk_1` FOREIGN KEY (`plan_id`) REFERENCES `programme_table_plans` (`id`),
  CONSTRAINT `programme_table_plan_snapshots_ibfk_2` FOREIGN KEY (`published_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_table_plan_snapshots`
--

LOCK TABLES `programme_table_plan_snapshots` WRITE;
/*!40000 ALTER TABLE `programme_table_plan_snapshots` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_table_plan_snapshots` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER plan_snapshot_no_update BEFORE UPDATE ON programme_table_plan_snapshots FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Published table plans are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER plan_snapshot_no_delete BEFORE DELETE ON programme_table_plan_snapshots FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Published table plans are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `programme_table_plans`
--

DROP TABLE IF EXISTS `programme_table_plans`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `programme_table_plans` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `programme_id` bigint(20) unsigned NOT NULL,
  `room_template_id` bigint(20) unsigned DEFAULT NULL,
  `title` varchar(180) NOT NULL,
  `revision_no` int(10) unsigned NOT NULL DEFAULT 1,
  `status` enum('draft','review','published') NOT NULL DEFAULT 'draft',
  `created_by` bigint(20) unsigned NOT NULL,
  `published_snapshot_id` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_programme_plan` (`programme_id`),
  KEY `room_template_id` (`room_template_id`),
  KEY `created_by` (`created_by`),
  KEY `fk_plan_published_snapshot` (`published_snapshot_id`),
  CONSTRAINT `fk_plan_published_snapshot` FOREIGN KEY (`published_snapshot_id`) REFERENCES `programme_table_plan_snapshots` (`id`) ON DELETE SET NULL,
  CONSTRAINT `programme_table_plans_ibfk_1` FOREIGN KEY (`programme_id`) REFERENCES `event_programmes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `programme_table_plans_ibfk_2` FOREIGN KEY (`room_template_id`) REFERENCES `dining_room_templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `programme_table_plans_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `programme_table_plans`
--

LOCK TABLES `programme_table_plans` WRITE;
/*!40000 ALTER TABLE `programme_table_plans` DISABLE KEYS */;
/*!40000 ALTER TABLE `programme_table_plans` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_admin_invites`
--

DROP TABLE IF EXISTS `province_admin_invites`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_admin_invites` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `role_key` varchar(40) NOT NULL DEFAULT 'province_admin',
  `email` varchar(254) NOT NULL,
  `token_hash` char(64) NOT NULL,
  `invited_by` bigint(20) unsigned DEFAULT NULL,
  `expires_at` datetime NOT NULL,
  `accepted_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_province_admin_invite_token` (`token_hash`),
  KEY `idx_province_admin_invites` (`province_id`,`created_at`),
  KEY `invited_by` (`invited_by`),
  CONSTRAINT `province_admin_invites_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_admin_invites_ibfk_2` FOREIGN KEY (`invited_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_admin_invites`
--

LOCK TABLES `province_admin_invites` WRITE;
/*!40000 ALTER TABLE `province_admin_invites` DISABLE KEYS */;
/*!40000 ALTER TABLE `province_admin_invites` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_audit_log`
--

DROP TABLE IF EXISTS `province_audit_log`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_audit_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `actor_id` bigint(20) unsigned DEFAULT NULL,
  `action` varchar(80) NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_province_audit` (`province_id`,`created_at`,`id`),
  KEY `actor_id` (`actor_id`),
  KEY `unit_id` (`unit_id`),
  CONSTRAINT `province_audit_log_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_audit_log_ibfk_2` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `province_audit_log_ibfk_3` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_audit_log`
--

LOCK TABLES `province_audit_log` WRITE;
/*!40000 ALTER TABLE `province_audit_log` DISABLE KEYS */;
INSERT INTO `province_audit_log` VALUES (1,103,1,'province_created',NULL,'2026-09-28 16:50:08'),(2,103,1,'unit_created',134,'2026-09-28 16:50:44');
/*!40000 ALTER TABLE `province_audit_log` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER trg_activity_from_province AFTER INSERT ON province_audit_log FOR EACH ROW
INSERT INTO activity_log(source_kind,source_id,actor_id,province_id,unit_id,action,target_type,target_id,change_summary,occurred_at)
VALUES('province',NEW.id,NEW.actor_id,NEW.province_id,NEW.unit_id,NEW.action,
IF(NEW.unit_id IS NULL,'province','unit'),IFNULL(NEW.unit_id,NEW.province_id),
REPLACE(NEW.action,'_',' '),NEW.created_at) */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `province_document_versions`
--

DROP TABLE IF EXISTS `province_document_versions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_document_versions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `document_id` bigint(20) unsigned NOT NULL,
  `version_number` int(10) unsigned NOT NULL,
  `storage_key` char(64) NOT NULL,
  `original_filename` varchar(200) NOT NULL,
  `mime_type` varchar(100) NOT NULL,
  `byte_size` int(10) unsigned NOT NULL,
  `sha256` char(64) NOT NULL,
  `uploaded_by` bigint(20) unsigned DEFAULT NULL,
  `uploaded_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_province_document_version` (`document_id`,`version_number`),
  UNIQUE KEY `uq_province_document_storage` (`storage_key`),
  KEY `province_id` (`province_id`,`document_id`),
  KEY `uploaded_by` (`uploaded_by`),
  CONSTRAINT `province_document_versions_ibfk_1` FOREIGN KEY (`province_id`, `document_id`) REFERENCES `province_documents` (`province_id`, `id`) ON DELETE CASCADE,
  CONSTRAINT `province_document_versions_ibfk_2` FOREIGN KEY (`uploaded_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_document_versions`
--

LOCK TABLES `province_document_versions` WRITE;
/*!40000 ALTER TABLE `province_document_versions` DISABLE KEYS */;
/*!40000 ALTER TABLE `province_document_versions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_documents`
--

DROP TABLE IF EXISTS `province_documents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_documents` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `folder_id` bigint(20) unsigned NOT NULL,
  `title` varchar(200) NOT NULL,
  `description` varchar(500) DEFAULT NULL,
  `publication_state` enum('private_officer','member','public_event') NOT NULL DEFAULT 'private_officer',
  `redacted_from_document_id` bigint(20) unsigned DEFAULT NULL,
  `published_at` datetime DEFAULT NULL,
  `retention_review_at` date DEFAULT NULL,
  `archived_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_province_document_id` (`province_id`,`id`),
  KEY `idx_province_document_scope` (`province_id`,`folder_id`,`event_id`,`publication_state`,`archived_at`,`revoked_at`),
  KEY `event_id` (`event_id`),
  KEY `folder_id` (`folder_id`),
  KEY `redacted_from_document_id` (`redacted_from_document_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `province_documents_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_documents_ibfk_2` FOREIGN KEY (`event_id`) REFERENCES `meetings` (`id`) ON DELETE SET NULL,
  CONSTRAINT `province_documents_ibfk_3` FOREIGN KEY (`folder_id`) REFERENCES `document_folders` (`id`),
  CONSTRAINT `province_documents_ibfk_4` FOREIGN KEY (`redacted_from_document_id`) REFERENCES `province_documents` (`id`) ON DELETE SET NULL,
  CONSTRAINT `province_documents_ibfk_5` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_documents`
--

LOCK TABLES `province_documents` WRITE;
/*!40000 ALTER TABLE `province_documents` DISABLE KEYS */;
/*!40000 ALTER TABLE `province_documents` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_email_templates`
--

DROP TABLE IF EXISTS `province_email_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_email_templates` (
  `province_id` bigint(20) unsigned NOT NULL,
  `template_key` varchar(80) NOT NULL,
  `display_name` varchar(150) NOT NULL,
  `subject_template` varchar(250) NOT NULL,
  `body_template` mediumtext NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 1,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`province_id`,`template_key`),
  KEY `fk_province_email_template_user` (`updated_by`),
  CONSTRAINT `fk_province_email_template_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_province_email_template_user` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_email_templates`
--

LOCK TABLES `province_email_templates` WRITE;
/*!40000 ALTER TABLE `province_email_templates` DISABLE KEYS */;
/*!40000 ALTER TABLE `province_email_templates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_event_hosts`
--

DROP TABLE IF EXISTS `province_event_hosts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_event_hosts` (
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  PRIMARY KEY (`province_id`),
  UNIQUE KEY `unit_id` (`unit_id`),
  CONSTRAINT `province_event_hosts_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_event_hosts_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_event_hosts`
--

LOCK TABLES `province_event_hosts` WRITE;
/*!40000 ALTER TABLE `province_event_hosts` DISABLE KEYS */;
/*!40000 ALTER TABLE `province_event_hosts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_events`
--

DROP TABLE IF EXISTS `province_events`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `meeting_id` bigint(20) unsigned NOT NULL,
  `event_kind` enum('grand_lodge','convocation') NOT NULL,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_province_event_meeting` (`meeting_id`),
  KEY `idx_province_events` (`province_id`,`unit_id`),
  KEY `unit_id` (`unit_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `province_events_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_events_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_events_ibfk_3` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_events_ibfk_4` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_events`
--

LOCK TABLES `province_events` WRITE;
/*!40000 ALTER TABLE `province_events` DISABLE KEYS */;
/*!40000 ALTER TABLE `province_events` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_order_rank_settings`
--

DROP TABLE IF EXISTS `province_order_rank_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_order_rank_settings` (
  `province_id` bigint(20) unsigned NOT NULL,
  `order_key` varchar(40) NOT NULL,
  `salutations` text DEFAULT NULL,
  `salutation_rank_links` longtext DEFAULT NULL,
  `masonic_ranks` text DEFAULT NULL,
  `active_provincial_ranks` text DEFAULT NULL,
  `past_provincial_ranks` text DEFAULT NULL,
  `active_grand_ranks` text DEFAULT NULL,
  `past_grand_ranks` text DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`province_id`,`order_key`),
  CONSTRAINT `fk_province_rank_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_order_rank_settings`
--

LOCK TABLES `province_order_rank_settings` WRITE;
/*!40000 ALTER TABLE `province_order_rank_settings` DISABLE KEYS */;
/*!40000 ALTER TABLE `province_order_rank_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_settings`
--

DROP TABLE IF EXISTS `province_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_settings` (
  `province_id` bigint(20) unsigned NOT NULL,
  `logo_url` varchar(500) DEFAULT NULL,
  `order_logo_url` varchar(500) DEFAULT NULL,
  `charity_logo_url` varchar(500) DEFAULT NULL,
  `primary_colour` char(7) NOT NULL DEFAULT '#990033',
  `secondary_colour` char(7) NOT NULL DEFAULT '#122849',
  `accent_colour` char(7) NOT NULL DEFAULT '#c7a646',
  `contact_name` varchar(150) DEFAULT NULL,
  `contact_email` varchar(254) DEFAULT NULL,
  `contact_phone` varchar(50) DEFAULT NULL,
  `website_url` varchar(500) DEFAULT NULL,
  `postal_address` varchar(500) DEFAULT NULL,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`province_id`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `province_settings_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_settings_ibfk_2` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_settings`
--

LOCK TABLES `province_settings` WRITE;
/*!40000 ALTER TABLE `province_settings` DISABLE KEYS */;
INSERT INTO `province_settings` VALUES (103,NULL,NULL,NULL,'#990033','#122849','#C7A646',NULL,NULL,NULL,NULL,NULL,1,'2026-09-28 16:50:08');
/*!40000 ALTER TABLE `province_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `province_unit_invites`
--

DROP TABLE IF EXISTS `province_unit_invites`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `province_unit_invites` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `email` varchar(254) NOT NULL,
  `token_hash` char(64) NOT NULL,
  `invited_by` bigint(20) unsigned DEFAULT NULL,
  `expires_at` datetime NOT NULL,
  `accepted_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_province_invite_token` (`token_hash`),
  KEY `idx_province_invites` (`province_id`,`unit_id`,`created_at`),
  KEY `unit_id` (`unit_id`),
  KEY `invited_by` (`invited_by`),
  CONSTRAINT `province_unit_invites_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_unit_invites_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `province_unit_invites_ibfk_3` FOREIGN KEY (`invited_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `province_unit_invites`
--

LOCK TABLES `province_unit_invites` WRITE;
/*!40000 ALTER TABLE `province_unit_invites` DISABLE KEYS */;
/*!40000 ALTER TABLE `province_unit_invites` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `provinces`
--

DROP TABLE IF EXISTS `provinces`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `provinces` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `slug` varchar(100) NOT NULL,
  `order_key` varchar(40) DEFAULT NULL,
  `custom_order_name` varchar(150) DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `normalized_name` varchar(200) GENERATED ALWAYS AS (lcase(trim(`name`))) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_province_slug` (`slug`),
  UNIQUE KEY `uq_provinces_normalized_name` (`normalized_name`)
) ENGINE=InnoDB AUTO_INCREMENT=196 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `provinces`
--

LOCK TABLES `provinces` WRITE;
/*!40000 ALTER TABLE `provinces` DISABLE KEYS */;
INSERT INTO `provinces` VALUES (103,'test','test','craft',NULL,1,'2026-09-28 16:50:08','2026-09-28 16:50:08','test');
/*!40000 ALTER TABLE `provinces` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `public_event_slug_redirects`
--

DROP TABLE IF EXISTS `public_event_slug_redirects`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `public_event_slug_redirects` (
  `unit_id` bigint(20) unsigned NOT NULL,
  `old_slug` varchar(100) NOT NULL,
  `event_id` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`unit_id`,`old_slug`),
  KEY `idx_event_slug_redirect_event` (`event_id`),
  CONSTRAINT `fk_public_event_slug_event` FOREIGN KEY (`event_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_public_event_slug_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `public_event_slug_redirects`
--

LOCK TABLES `public_event_slug_redirects` WRITE;
/*!40000 ALTER TABLE `public_event_slug_redirects` DISABLE KEYS */;
/*!40000 ALTER TABLE `public_event_slug_redirects` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `reminders`
--

DROP TABLE IF EXISTS `reminders`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `reminders` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `booking_id` bigint(20) unsigned NOT NULL,
  `reminder_type` enum('payment','booking_deadline','meeting','waiting_list') NOT NULL,
  `status` enum('pending','sent','failed','cancelled') NOT NULL DEFAULT 'pending',
  `scheduled_for` datetime NOT NULL,
  `sent_at` datetime DEFAULT NULL,
  `failure_message` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `reminder_day` date DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_reminder_booking_type_day` (`booking_id`,`reminder_type`,`reminder_day`),
  KEY `idx_reminder_schedule` (`status`,`scheduled_for`),
  CONSTRAINT `fk_reminder_booking` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `reminders`
--

LOCK TABLES `reminders` WRITE;
/*!40000 ALTER TABLE `reminders` DISABLE KEYS */;
/*!40000 ALTER TABLE `reminders` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `return_export_audit`
--

DROP TABLE IF EXISTS `return_export_audit`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `return_export_audit` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `snapshot_id` bigint(20) unsigned NOT NULL,
  `format` enum('pdf','csv','xlsx') NOT NULL,
  `exported_by` bigint(20) unsigned NOT NULL,
  `exported_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_return_export_snapshot` (`snapshot_id`,`exported_at`),
  KEY `fk_return_export_actor` (`exported_by`),
  CONSTRAINT `fk_return_export_actor` FOREIGN KEY (`exported_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_return_export_snapshot` FOREIGN KEY (`snapshot_id`) REFERENCES `return_final_snapshots` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `return_export_audit`
--

LOCK TABLES `return_export_audit` WRITE;
/*!40000 ALTER TABLE `return_export_audit` DISABLE KEYS */;
/*!40000 ALTER TABLE `return_export_audit` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER return_export_audit_no_update BEFORE UPDATE ON return_export_audit FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Return export audit is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER return_export_audit_no_delete BEFORE DELETE ON return_export_audit FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Return export audit is append-only' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `return_final_snapshots`
--

DROP TABLE IF EXISTS `return_final_snapshots`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `return_final_snapshots` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `return_id` bigint(20) unsigned NOT NULL,
  `snapshot_no` int(10) unsigned NOT NULL,
  `payload_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`payload_json`)),
  `source_fingerprint` char(64) NOT NULL,
  `template_version_id` bigint(20) unsigned NOT NULL,
  `signed_by` bigint(20) unsigned NOT NULL,
  `signed_at` datetime NOT NULL,
  `locked_at` datetime NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_return_snapshot` (`return_id`,`snapshot_no`),
  KEY `fk_return_snapshot_template` (`template_version_id`),
  KEY `fk_return_snapshot_signer` (`signed_by`),
  CONSTRAINT `fk_return_snapshot_return` FOREIGN KEY (`return_id`) REFERENCES `unit_returns` (`id`),
  CONSTRAINT `fk_return_snapshot_signer` FOREIGN KEY (`signed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_return_snapshot_template` FOREIGN KEY (`template_version_id`) REFERENCES `return_template_versions` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `return_final_snapshots`
--

LOCK TABLES `return_final_snapshots` WRITE;
/*!40000 ALTER TABLE `return_final_snapshots` DISABLE KEYS */;
/*!40000 ALTER TABLE `return_final_snapshots` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER return_final_snapshot_no_update BEFORE UPDATE ON return_final_snapshots FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Final return snapshots are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = cp850 */ ;
/*!50003 SET character_set_results = cp850 */ ;
/*!50003 SET collation_connection  = cp850_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER return_final_snapshot_no_delete BEFORE DELETE ON return_final_snapshots FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Final return snapshots are immutable' */;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;

--
-- Table structure for table `return_submissions`
--

DROP TABLE IF EXISTS `return_submissions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `return_submissions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `snapshot_id` bigint(20) unsigned NOT NULL,
  `status` enum('not_submitted','submitted','acknowledged','rejected','withdrawn') NOT NULL DEFAULT 'not_submitted',
  `submitted_at` datetime DEFAULT NULL,
  `acknowledged_at` datetime DEFAULT NULL,
  `acknowledgement_reference` varchar(190) DEFAULT NULL,
  `note` varchar(1000) DEFAULT NULL,
  `updated_by` bigint(20) unsigned NOT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_return_submission` (`snapshot_id`),
  KEY `fk_return_submission_actor` (`updated_by`),
  CONSTRAINT `fk_return_submission_actor` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_return_submission_snapshot` FOREIGN KEY (`snapshot_id`) REFERENCES `return_final_snapshots` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `return_submissions`
--

LOCK TABLES `return_submissions` WRITE;
/*!40000 ALTER TABLE `return_submissions` DISABLE KEYS */;
/*!40000 ALTER TABLE `return_submissions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `return_template_versions`
--

DROP TABLE IF EXISTS `return_template_versions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `return_template_versions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `order_key` varchar(40) NOT NULL,
  `return_type` enum('annual','installation') NOT NULL,
  `version_no` int(10) unsigned NOT NULL,
  `name` varchar(180) NOT NULL,
  `terminology_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`terminology_json`)),
  `field_config_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`field_config_json`)),
  `supports_pdf` tinyint(1) NOT NULL DEFAULT 0,
  `supports_csv` tinyint(1) NOT NULL DEFAULT 1,
  `supports_xlsx` tinyint(1) NOT NULL DEFAULT 0,
  `requirements_verified_at` datetime DEFAULT NULL,
  `requirements_source` varchar(500) DEFAULT NULL,
  `effective_from` date DEFAULT NULL,
  `effective_to` date DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_return_template_version` (`province_id`,`order_key`,`return_type`,`version_no`),
  KEY `idx_return_template_lookup` (`province_id`,`order_key`,`return_type`,`active`,`effective_from`),
  KEY `fk_return_template_actor` (`created_by`),
  CONSTRAINT `fk_return_template_actor` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_return_template_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `return_template_versions`
--

LOCK TABLES `return_template_versions` WRITE;
/*!40000 ALTER TABLE `return_template_versions` DISABLE KEYS */;
/*!40000 ALTER TABLE `return_template_versions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `scheduled_job_runs`
--

DROP TABLE IF EXISTS `scheduled_job_runs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `scheduled_job_runs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_unit_id` bigint(20) unsigned NOT NULL DEFAULT 0,
  `job_key` varchar(60) NOT NULL,
  `started_at` datetime NOT NULL DEFAULT current_timestamp(),
  `finished_at` datetime DEFAULT NULL,
  `status` enum('running','success','failed') NOT NULL DEFAULT 'running',
  `affected_count` int(10) unsigned NOT NULL DEFAULT 0,
  `summary` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_job_history` (`scope_unit_id`,`job_key`,`started_at`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `scheduled_job_runs`
--

LOCK TABLES `scheduled_job_runs` WRITE;
/*!40000 ALTER TABLE `scheduled_job_runs` DISABLE KEYS */;
INSERT INTO `scheduled_job_runs` VALUES (1,0,'guest_retention','2026-09-28 06:49:43','2026-09-28 06:49:43','success',0,NULL);
/*!40000 ALTER TABLE `scheduled_job_runs` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `scheduled_job_state`
--

DROP TABLE IF EXISTS `scheduled_job_state`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `scheduled_job_state` (
  `scope_unit_id` bigint(20) unsigned NOT NULL DEFAULT 0,
  `job_key` varchar(60) NOT NULL,
  `last_started_at` datetime DEFAULT NULL,
  `last_completed_at` datetime DEFAULT NULL,
  `last_success_at` datetime DEFAULT NULL,
  `last_status` enum('never','running','success','failed') NOT NULL DEFAULT 'never',
  `last_summary` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`scope_unit_id`,`job_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `scheduled_job_state`
--

LOCK TABLES `scheduled_job_state` WRITE;
/*!40000 ALTER TABLE `scheduled_job_state` DISABLE KEYS */;
INSERT INTO `scheduled_job_state` VALUES (0,'guest_retention','2026-09-28 06:49:43','2026-09-28 06:49:43','2026-09-28 06:49:43','success','0 item(s) processed');
/*!40000 ALTER TABLE `scheduled_job_state` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `scheduled_payment_reminder_settings`
--

DROP TABLE IF EXISTS `scheduled_payment_reminder_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `scheduled_payment_reminder_settings` (
  `unit_id` bigint(20) unsigned NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 0,
  `authorised_by` bigint(20) unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`unit_id`),
  KEY `authorised_by` (`authorised_by`),
  CONSTRAINT `scheduled_payment_reminder_settings_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `scheduled_payment_reminder_settings_ibfk_2` FOREIGN KEY (`authorised_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `scheduled_payment_reminder_settings`
--

LOCK TABLES `scheduled_payment_reminder_settings` WRITE;
/*!40000 ALTER TABLE `scheduled_payment_reminder_settings` DISABLE KEYS */;
/*!40000 ALTER TABLE `scheduled_payment_reminder_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `schema_versions`
--

DROP TABLE IF EXISTS `schema_versions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `schema_versions` (
  `version_number` int(10) unsigned NOT NULL,
  `version_name` varchar(150) NOT NULL,
  `installed_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`version_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `schema_versions`
--

LOCK TABLES `schema_versions` WRITE;
/*!40000 ALTER TABLE `schema_versions` DISABLE KEYS */;
INSERT INTO `schema_versions` VALUES (22,'Operations and resilience centre','2026-09-27 21:01:00'),(26,'Consented guest directory and meeting invitations','2026-09-27 21:01:00'),(27,'Consented attendee directory and meeting invitations','2026-09-27 21:01:00'),(28,'Paying official visit classifications','2026-09-27 21:01:00');
/*!40000 ALTER TABLE `schema_versions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `scoped_permission_grants`
--

DROP TABLE IF EXISTS `scoped_permission_grants`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `scoped_permission_grants` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL,
  `permission_set_id` bigint(20) unsigned NOT NULL,
  `scope_type` enum('platform','province','unit','event') NOT NULL,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `expires_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `last_used_at` datetime DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  `review_due_at` datetime DEFAULT NULL,
  `granted_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `scope_key` varchar(100) GENERATED ALWAYS AS (case `scope_type` when 'platform' then 'platform' when 'province' then concat('province:',`province_id`) when 'unit' then concat('unit:',`unit_id`) else concat('event:',`event_id`) end) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_scoped_permission_grant` (`user_id`,`permission_set_id`,`scope_key`),
  KEY `idx_permission_grant_scope` (`scope_type`,`province_id`,`unit_id`,`event_id`,`active`,`expires_at`),
  KEY `fk_permission_grant_set` (`permission_set_id`),
  KEY `fk_permission_grant_province` (`province_id`),
  KEY `fk_permission_grant_unit` (`unit_id`),
  KEY `fk_permission_grant_event` (`event_id`),
  KEY `fk_permission_grant_actor` (`granted_by`),
  CONSTRAINT `fk_permission_grant_actor` FOREIGN KEY (`granted_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_permission_grant_event` FOREIGN KEY (`event_id`) REFERENCES `meetings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_permission_grant_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_permission_grant_set` FOREIGN KEY (`permission_set_id`) REFERENCES `permission_sets` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_permission_grant_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_permission_grant_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_permission_grant_scope` CHECK (`scope_type` = 'platform' and `province_id` is null and `unit_id` is null and `event_id` is null or `scope_type` = 'province' and `province_id` is not null and `unit_id` is null and `event_id` is null or `scope_type` = 'unit' and `province_id` is null and `unit_id` is not null and `event_id` is null or `scope_type` = 'event' and `province_id` is null and `unit_id` is null and `event_id` is not null)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `scoped_permission_grants`
--

LOCK TABLES `scoped_permission_grants` WRITE;
/*!40000 ALTER TABLE `scoped_permission_grants` DISABLE KEYS */;
/*!40000 ALTER TABLE `scoped_permission_grants` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `seat_assignments`
--

DROP TABLE IF EXISTS `seat_assignments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `seat_assignments` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `dining_table_id` bigint(20) unsigned NOT NULL,
  `booking_id` bigint(20) unsigned NOT NULL,
  `guest_id` bigint(20) unsigned DEFAULT NULL,
  `seat_number` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_booking_guest_seat` (`booking_id`,`guest_id`),
  KEY `fk_seat_table` (`dining_table_id`),
  KEY `fk_seat_guest` (`guest_id`),
  CONSTRAINT `fk_seat_booking` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_seat_guest` FOREIGN KEY (`guest_id`) REFERENCES `guests` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_seat_table` FOREIGN KEY (`dining_table_id`) REFERENCES `dining_tables` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `seat_assignments`
--

LOCK TABLES `seat_assignments` WRITE;
/*!40000 ALTER TABLE `seat_assignments` DISABLE KEYS */;
/*!40000 ALTER TABLE `seat_assignments` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `security_events`
--

DROP TABLE IF EXISTS `security_events`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `security_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `actor_id` bigint(20) unsigned DEFAULT NULL,
  `event_key` varchar(60) NOT NULL,
  `occurred_at` datetime NOT NULL DEFAULT current_timestamp(),
  `notification_status` enum('none','queued','failed') NOT NULL DEFAULT 'none',
  PRIMARY KEY (`id`),
  KEY `idx_security_user` (`user_id`,`occurred_at`,`id`),
  KEY `actor_id` (`actor_id`),
  CONSTRAINT `security_events_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `security_events_ibfk_2` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `security_events`
--

LOCK TABLES `security_events` WRITE;
/*!40000 ALTER TABLE `security_events` DISABLE KEYS */;
INSERT INTO `security_events` VALUES (1,1,1,'login_succeeded','2026-09-27 22:07:51','queued'),(2,1,1,'login_succeeded','2026-09-28 08:32:26','queued'),(3,1,1,'login_succeeded','2026-09-28 12:03:06','queued'),(4,1,1,'password_changed','2026-09-28 12:48:33','none'),(5,1,1,'login_failed','2026-09-28 16:49:43','none'),(6,1,1,'login_succeeded','2026-09-28 16:49:49','queued'),(7,1,1,'reauthenticated','2026-09-28 16:50:44','none'),(8,1,1,'login_failed','2026-09-28 18:39:39','none'),(9,1,1,'login_succeeded','2026-09-28 18:39:43','queued');
/*!40000 ALTER TABLE `security_events` ENABLE KEYS */;
UNLOCK TABLES;

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

DROP TABLE IF EXISTS `settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `settings` (
  `unit_id` bigint(20) unsigned NOT NULL,
  `setting_key` varchar(100) NOT NULL,
  `setting_value` text DEFAULT NULL,
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`unit_id`,`setting_key`),
  KEY `fk_setting_user` (`updated_by`),
  CONSTRAINT `fk_setting_user` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_settings_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `settings`
--

LOCK TABLES `settings` WRITE;
/*!40000 ALTER TABLE `settings` DISABLE KEYS */;
INSERT INTO `settings` VALUES (134,'enabled_features','[\"waiting_list\",\"raffle\",\"check_in\",\"email_notifications\",\"documents\"]',1,'2026-09-28 16:50:44'),(134,'enabled_masonic_orders','[\"craft\"]',1,'2026-09-28 16:50:44');
/*!40000 ALTER TABLE `settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `source_installations`
--

DROP TABLE IF EXISTS `source_installations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `source_installations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `source_key` varchar(100) NOT NULL,
  `display_name` varchar(200) NOT NULL,
  `target_province_id` bigint(20) unsigned NOT NULL,
  `target_unit_id` bigint(20) unsigned NOT NULL,
  `status` enum('registered','importing','complete','failed') NOT NULL DEFAULT 'registered',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_source_installation_key` (`source_key`),
  KEY `fk_source_province` (`target_province_id`),
  KEY `fk_source_unit` (`target_unit_id`),
  CONSTRAINT `fk_source_province` FOREIGN KEY (`target_province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `fk_source_unit` FOREIGN KEY (`target_unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `source_installations`
--

LOCK TABLES `source_installations` WRITE;
/*!40000 ALTER TABLE `source_installations` DISABLE KEYS */;
/*!40000 ALTER TABLE `source_installations` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `subscription_charges`
--

DROP TABLE IF EXISTS `subscription_charges`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `subscription_charges` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `period_id` bigint(20) unsigned NOT NULL,
  `rate_id` bigint(20) unsigned NOT NULL,
  `member_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `membership_type_snapshot` varchar(80) NOT NULL,
  `membership_start_snapshot` date NOT NULL,
  `base_amount` decimal(12,2) NOT NULL,
  `charged_amount` decimal(12,2) NOT NULL,
  `proration_note` varchar(250) DEFAULT NULL,
  `status` enum('charged','exempt','reversed') NOT NULL DEFAULT 'charged',
  `invoice_id` bigint(20) unsigned DEFAULT NULL,
  `ledger_entry_id` bigint(20) unsigned NOT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_subscription_charge` (`period_id`,`person_id`),
  KEY `idx_subscription_person` (`unit_id`,`person_id`,`period_id`),
  KEY `province_id` (`province_id`),
  KEY `rate_id` (`rate_id`),
  KEY `member_id` (`member_id`),
  KEY `person_id` (`person_id`),
  KEY `invoice_id` (`invoice_id`),
  KEY `ledger_entry_id` (`ledger_entry_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `subscription_charges_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `subscription_charges_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `subscription_charges_ibfk_3` FOREIGN KEY (`period_id`) REFERENCES `subscription_periods` (`id`),
  CONSTRAINT `subscription_charges_ibfk_4` FOREIGN KEY (`rate_id`) REFERENCES `subscription_rates` (`id`),
  CONSTRAINT `subscription_charges_ibfk_5` FOREIGN KEY (`member_id`) REFERENCES `unit_members` (`id`),
  CONSTRAINT `subscription_charges_ibfk_6` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `subscription_charges_ibfk_7` FOREIGN KEY (`invoice_id`) REFERENCES `finance_invoices` (`id`),
  CONSTRAINT `subscription_charges_ibfk_8` FOREIGN KEY (`ledger_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `subscription_charges_ibfk_9` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `subscription_charges`
--

LOCK TABLES `subscription_charges` WRITE;
/*!40000 ALTER TABLE `subscription_charges` DISABLE KEYS */;
/*!40000 ALTER TABLE `subscription_charges` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `subscription_exemptions`
--

DROP TABLE IF EXISTS `subscription_exemptions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `subscription_exemptions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `charge_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `reason` varchar(500) NOT NULL,
  `ledger_entry_id` bigint(20) unsigned NOT NULL,
  `approved_by` bigint(20) unsigned NOT NULL,
  `approved_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_subscription_exemption` (`charge_id`,`id`),
  KEY `unit_id` (`unit_id`),
  KEY `ledger_entry_id` (`ledger_entry_id`),
  KEY `approved_by` (`approved_by`),
  CONSTRAINT `subscription_exemptions_ibfk_1` FOREIGN KEY (`charge_id`) REFERENCES `subscription_charges` (`id`),
  CONSTRAINT `subscription_exemptions_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `subscription_exemptions_ibfk_3` FOREIGN KEY (`ledger_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `subscription_exemptions_ibfk_4` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` > 0)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `subscription_exemptions`
--

LOCK TABLES `subscription_exemptions` WRITE;
/*!40000 ALTER TABLE `subscription_exemptions` DISABLE KEYS */;
/*!40000 ALTER TABLE `subscription_exemptions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `subscription_periods`
--

DROP TABLE IF EXISTS `subscription_periods`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `subscription_periods` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned NOT NULL,
  `label` varchar(120) NOT NULL,
  `starts_on` date NOT NULL,
  `ends_on` date NOT NULL,
  `due_on` date NOT NULL,
  `proration_method` enum('none','daily','monthly') NOT NULL DEFAULT 'none',
  `status` enum('draft','approved','closed') NOT NULL DEFAULT 'draft',
  `reminder_policy_id` bigint(20) unsigned DEFAULT NULL,
  `approved_by` bigint(20) unsigned DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_subscription_period` (`unit_id`,`starts_on`,`ends_on`),
  KEY `idx_subscription_period` (`unit_id`,`status`,`due_on`),
  KEY `province_id` (`province_id`),
  KEY `reminder_policy_id` (`reminder_policy_id`),
  KEY `approved_by` (`approved_by`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `subscription_periods_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `subscription_periods_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `subscription_periods_ibfk_3` FOREIGN KEY (`reminder_policy_id`) REFERENCES `subscription_reminder_policies` (`id`),
  CONSTRAINT `subscription_periods_ibfk_4` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `subscription_periods_ibfk_5` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`starts_on` <= `ends_on`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `subscription_periods`
--

LOCK TABLES `subscription_periods` WRITE;
/*!40000 ALTER TABLE `subscription_periods` DISABLE KEYS */;
/*!40000 ALTER TABLE `subscription_periods` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `subscription_rates`
--

DROP TABLE IF EXISTS `subscription_rates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `subscription_rates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `period_id` bigint(20) unsigned NOT NULL,
  `membership_type` varchar(80) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `allow_proration` tinyint(1) NOT NULL DEFAULT 0,
  `approved_by` bigint(20) unsigned DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_subscription_rate` (`period_id`,`membership_type`),
  KEY `approved_by` (`approved_by`),
  CONSTRAINT `subscription_rates_ibfk_1` FOREIGN KEY (`period_id`) REFERENCES `subscription_periods` (`id`),
  CONSTRAINT `subscription_rates_ibfk_2` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `CONSTRAINT_1` CHECK (`amount` >= 0)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `subscription_rates`
--

LOCK TABLES `subscription_rates` WRITE;
/*!40000 ALTER TABLE `subscription_rates` DISABLE KEYS */;
/*!40000 ALTER TABLE `subscription_rates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `subscription_reminder_log`
--

DROP TABLE IF EXISTS `subscription_reminder_log`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `subscription_reminder_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `charge_id` bigint(20) unsigned NOT NULL,
  `policy_id` bigint(20) unsigned NOT NULL,
  `sequence_number` tinyint(3) unsigned NOT NULL,
  `queued_by` bigint(20) unsigned NOT NULL,
  `queued_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_subscription_reminder` (`charge_id`,`sequence_number`),
  KEY `policy_id` (`policy_id`),
  KEY `queued_by` (`queued_by`),
  CONSTRAINT `subscription_reminder_log_ibfk_1` FOREIGN KEY (`charge_id`) REFERENCES `subscription_charges` (`id`),
  CONSTRAINT `subscription_reminder_log_ibfk_2` FOREIGN KEY (`policy_id`) REFERENCES `subscription_reminder_policies` (`id`),
  CONSTRAINT `subscription_reminder_log_ibfk_3` FOREIGN KEY (`queued_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `subscription_reminder_log`
--

LOCK TABLES `subscription_reminder_log` WRITE;
/*!40000 ALTER TABLE `subscription_reminder_log` DISABLE KEYS */;
/*!40000 ALTER TABLE `subscription_reminder_log` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `subscription_reminder_policies`
--

DROP TABLE IF EXISTS `subscription_reminder_policies`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `subscription_reminder_policies` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `name` varchar(120) NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 0,
  `first_after_days` smallint(5) unsigned NOT NULL DEFAULT 14,
  `repeat_days` smallint(5) unsigned NOT NULL DEFAULT 30,
  `maximum_reminders` tinyint(3) unsigned NOT NULL DEFAULT 3,
  `subject` varchar(180) NOT NULL,
  `message_text` varchar(2000) NOT NULL,
  `authorised_by` bigint(20) unsigned DEFAULT NULL,
  `authorised_at` datetime DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_reminder_policy` (`unit_id`,`name`),
  KEY `authorised_by` (`authorised_by`),
  CONSTRAINT `subscription_reminder_policies_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `subscription_reminder_policies_ibfk_2` FOREIGN KEY (`authorised_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `subscription_reminder_policies`
--

LOCK TABLES `subscription_reminder_policies` WRITE;
/*!40000 ALTER TABLE `subscription_reminder_policies` DISABLE KEYS */;
/*!40000 ALTER TABLE `subscription_reminder_policies` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_jobs`
--

DROP TABLE IF EXISTS `system_jobs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_jobs` (
  `unit_id` bigint(20) unsigned NOT NULL,
  `job_key` varchar(80) NOT NULL,
  `last_started_at` datetime DEFAULT NULL,
  `last_completed_at` datetime DEFAULT NULL,
  `last_status` enum('never','running','success','failed') NOT NULL DEFAULT 'never',
  `last_message` text DEFAULT NULL,
  PRIMARY KEY (`unit_id`,`job_key`),
  CONSTRAINT `fk_system_jobs_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_jobs`
--

LOCK TABLES `system_jobs` WRITE;
/*!40000 ALTER TABLE `system_jobs` DISABLE KEYS */;
/*!40000 ALTER TABLE `system_jobs` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tenant_document_categories`
--

DROP TABLE IF EXISTS `tenant_document_categories`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tenant_document_categories` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `label` varchar(100) NOT NULL,
  `name_key` varchar(100) GENERATED ALWAYS AS (lcase(trim(`label`))) STORED,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_doc_category_unit_id` (`unit_id`,`id`),
  UNIQUE KEY `uq_doc_category_unit_name` (`unit_id`,`name_key`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `tenant_document_categories_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `tenant_document_categories_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tenant_document_categories`
--

LOCK TABLES `tenant_document_categories` WRITE;
/*!40000 ALTER TABLE `tenant_document_categories` DISABLE KEYS */;
/*!40000 ALTER TABLE `tenant_document_categories` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tenant_document_versions`
--

DROP TABLE IF EXISTS `tenant_document_versions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tenant_document_versions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `document_id` bigint(20) unsigned NOT NULL,
  `version_number` int(10) unsigned NOT NULL,
  `storage_key` char(64) NOT NULL,
  `original_filename` varchar(200) NOT NULL,
  `mime_type` varchar(100) NOT NULL,
  `byte_size` int(10) unsigned NOT NULL,
  `sha256` char(64) NOT NULL,
  `uploaded_by` bigint(20) unsigned DEFAULT NULL,
  `uploaded_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_document_version` (`document_id`,`version_number`),
  UNIQUE KEY `uq_document_file` (`storage_key`),
  KEY `idx_document_versions` (`unit_id`,`document_id`),
  KEY `uploaded_by` (`uploaded_by`),
  CONSTRAINT `tenant_document_versions_ibfk_1` FOREIGN KEY (`unit_id`, `document_id`) REFERENCES `tenant_documents` (`unit_id`, `id`) ON DELETE CASCADE,
  CONSTRAINT `tenant_document_versions_ibfk_2` FOREIGN KEY (`uploaded_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tenant_document_versions`
--

LOCK TABLES `tenant_document_versions` WRITE;
/*!40000 ALTER TABLE `tenant_document_versions` DISABLE KEYS */;
/*!40000 ALTER TABLE `tenant_document_versions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tenant_documents`
--

DROP TABLE IF EXISTS `tenant_documents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tenant_documents` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `event_id` bigint(20) unsigned DEFAULT NULL,
  `category_key` varchar(32) NOT NULL,
  `custom_category_id` bigint(20) unsigned DEFAULT NULL,
  `folder_id` bigint(20) unsigned DEFAULT NULL,
  `title` varchar(200) NOT NULL,
  `description` varchar(500) DEFAULT NULL,
  `audience` enum('members','officers','administrators') NOT NULL DEFAULT 'members',
  `publication_state` enum('private_officer','member','public_event') NOT NULL DEFAULT 'member',
  `redacted_from_document_id` bigint(20) unsigned DEFAULT NULL,
  `published_at` datetime DEFAULT NULL,
  `retention_review_at` date DEFAULT NULL,
  `archived_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_tenant_documents_unit_id` (`unit_id`,`id`),
  KEY `idx_tenant_documents` (`unit_id`,`event_id`,`deleted_at`,`archived_at`),
  KEY `fk_tenant_document_event` (`event_id`),
  KEY `fk_tenant_document_custom` (`unit_id`,`custom_category_id`),
  KEY `created_by` (`created_by`),
  KEY `idx_tenant_document_public` (`unit_id`,`event_id`,`publication_state`,`published_at`,`revoked_at`),
  KEY `fk_tenant_document_folder` (`folder_id`),
  KEY `fk_tenant_document_redacted` (`redacted_from_document_id`),
  CONSTRAINT `fk_tenant_document_custom` FOREIGN KEY (`unit_id`, `custom_category_id`) REFERENCES `tenant_document_categories` (`unit_id`, `id`),
  CONSTRAINT `fk_tenant_document_event` FOREIGN KEY (`event_id`) REFERENCES `meetings` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_tenant_document_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `tenant_documents_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `tenant_documents_ibfk_2` FOREIGN KEY (`folder_id`) REFERENCES `document_folders` (`id`) ON DELETE SET NULL,
  CONSTRAINT `tenant_documents_ibfk_3` FOREIGN KEY (`redacted_from_document_id`) REFERENCES `tenant_documents` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tenant_documents`
--

LOCK TABLES `tenant_documents` WRITE;
/*!40000 ALTER TABLE `tenant_documents` DISABLE KEYS */;
/*!40000 ALTER TABLE `tenant_documents` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tenant_retention_queue`
--

DROP TABLE IF EXISTS `tenant_retention_queue`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tenant_retention_queue` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `schedule_id` bigint(20) unsigned NOT NULL,
  `data_class` varchar(40) NOT NULL,
  `source_id` bigint(20) unsigned NOT NULL,
  `due_at` datetime NOT NULL,
  `status` enum('pending','retain','approved','completed','skipped','failed') NOT NULL DEFAULT 'pending',
  `proposed_action` enum('review','anonymise','delete') NOT NULL,
  `decision_reason` varchar(500) DEFAULT NULL,
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_retention_queue` (`schedule_id`,`data_class`,`source_id`),
  KEY `idx_retention_queue` (`unit_id`,`status`,`due_at`),
  KEY `fk_retention_queue_reviewer` (`reviewed_by`),
  CONSTRAINT `fk_retention_queue_reviewer` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_retention_queue_schedule` FOREIGN KEY (`schedule_id`) REFERENCES `tenant_retention_schedules` (`id`),
  CONSTRAINT `fk_retention_queue_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tenant_retention_queue`
--

LOCK TABLES `tenant_retention_queue` WRITE;
/*!40000 ALTER TABLE `tenant_retention_queue` DISABLE KEYS */;
/*!40000 ALTER TABLE `tenant_retention_queue` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tenant_retention_schedules`
--

DROP TABLE IF EXISTS `tenant_retention_schedules`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tenant_retention_schedules` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `data_class` enum('memberships','candidates','guest_directory','bookings','guests','messages','documents','welfare','finance','dc_private_notes') NOT NULL,
  `retention_months` smallint(5) unsigned NOT NULL,
  `due_action` enum('review','anonymise','delete') NOT NULL DEFAULT 'review',
  `obligation_type` enum('consent','operational','legal','accounting','safeguarding') NOT NULL DEFAULT 'operational',
  `legal_basis` varchar(255) DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `updated_by` bigint(20) unsigned NOT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_retention_schedule` (`unit_id`,`data_class`),
  KEY `fk_retention_schedule_actor` (`updated_by`),
  CONSTRAINT `fk_retention_schedule_actor` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_retention_schedule_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tenant_retention_schedules`
--

LOCK TABLES `tenant_retention_schedules` WRITE;
/*!40000 ALTER TABLE `tenant_retention_schedules` DISABLE KEYS */;
/*!40000 ALTER TABLE `tenant_retention_schedules` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tenant_role_scopes`
--

DROP TABLE IF EXISTS `tenant_role_scopes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tenant_role_scopes` (
  `role_key` varchar(50) NOT NULL,
  `scope_type` enum('platform','province','unit') NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`role_key`,`scope_type`),
  CONSTRAINT `fk_tenant_role_scope_role` FOREIGN KEY (`role_key`) REFERENCES `tenant_roles` (`role_key`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tenant_role_scopes`
--

LOCK TABLES `tenant_role_scopes` WRITE;
/*!40000 ALTER TABLE `tenant_role_scopes` DISABLE KEYS */;
INSERT INTO `tenant_role_scopes` VALUES ('admin','unit','2026-09-27 21:01:01'),('almoner','unit','2026-09-28 18:28:32'),('checkin_operator','unit','2026-09-27 21:01:01'),('dining','unit','2026-09-27 21:01:01'),('director_of_ceremonies','province','2026-09-28 06:45:44'),('director_of_ceremonies','unit','2026-09-28 06:45:44'),('document_viewer','unit','2026-09-27 21:01:01'),('member','unit','2026-09-27 21:01:01'),('platform_admin','platform','2026-09-27 21:01:01'),('province_admin','province','2026-09-27 21:01:01'),('province_almoner','province','2026-09-28 18:28:32'),('province_secretary','province','2026-09-27 21:01:02'),('readonly','unit','2026-09-27 21:01:01'),('secretary','unit','2026-09-27 21:01:01'),('treasurer','unit','2026-09-27 21:01:01'),('worshipful_master','unit','2026-09-27 21:01:01');
/*!40000 ALTER TABLE `tenant_role_scopes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tenant_roles`
--

DROP TABLE IF EXISTS `tenant_roles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tenant_roles` (
  `role_key` varchar(50) NOT NULL,
  `display_name` varchar(100) NOT NULL,
  `built_in` tinyint(1) NOT NULL DEFAULT 0,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`role_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tenant_roles`
--

LOCK TABLES `tenant_roles` WRITE;
/*!40000 ALTER TABLE `tenant_roles` DISABLE KEYS */;
INSERT INTO `tenant_roles` VALUES ('admin','Unit Administrator',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('almoner','Almoner',1,1,'2026-09-28 18:28:32','2026-09-28 18:28:32'),('checkin_operator','Check-in Operator',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('dining','Dining Steward',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('director_of_ceremonies','Director of Ceremonies',1,1,'2026-09-28 06:45:44','2026-09-28 06:45:44'),('document_viewer','Document Viewer',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('member','Member',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('platform_admin','Platform Administrator',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('province_admin','Province Administrator',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('province_almoner','Province Almoner',1,1,'2026-09-28 18:28:32','2026-09-28 18:28:32'),('province_secretary','Provincial Secretary',1,1,'2026-09-27 21:01:02','2026-09-27 21:01:02'),('readonly','Read-only Officer',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('secretary','Secretary',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('treasurer','Treasurer',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),('worshipful_master','Worshipful Master',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01');
/*!40000 ALTER TABLE `tenant_roles` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_candidates`
--

DROP TABLE IF EXISTS `unit_candidates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_candidates` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `order_key` varchar(40) NOT NULL DEFAULT 'craft',
  `sponsor_person_id` bigint(20) unsigned DEFAULT NULL,
  `sponsor_name` varchar(200) DEFAULT NULL,
  `stage` enum('enquiry','meeting','application','ballot','approved','on_hold','closed','admitted') NOT NULL DEFAULT 'enquiry',
  `next_action` varchar(250) DEFAULT NULL,
  `agreed_contact_method` enum('email','phone','post','none') NOT NULL DEFAULT 'none',
  `review_date` date DEFAULT NULL,
  `closed_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_candidate` (`unit_id`,`person_id`,`order_key`),
  KEY `idx_candidate_stage` (`unit_id`,`stage`,`review_date`),
  KEY `fk_candidate_person` (`person_id`),
  KEY `fk_candidate_sponsor` (`sponsor_person_id`),
  KEY `fk_candidate_actor` (`created_by`),
  CONSTRAINT `fk_candidate_actor` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_candidate_person` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_candidate_sponsor` FOREIGN KEY (`sponsor_person_id`) REFERENCES `people` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_candidate_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_candidates`
--

LOCK TABLES `unit_candidates` WRITE;
/*!40000 ALTER TABLE `unit_candidates` DISABLE KEYS */;
/*!40000 ALTER TABLE `unit_candidates` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_contacts`
--

DROP TABLE IF EXISTS `unit_contacts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_contacts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `source_guest_contact_id` bigint(20) unsigned DEFAULT NULL,
  `source_booking_id` bigint(20) unsigned DEFAULT NULL,
  `consent_text` text NOT NULL,
  `consent_version` varchar(40) NOT NULL,
  `consented_at` datetime NOT NULL,
  `permitted_unit_id` bigint(20) unsigned NOT NULL,
  `permitted_reuse` tinyint(1) NOT NULL DEFAULT 1,
  `permit_event_invitations` tinyint(1) NOT NULL DEFAULT 0,
  `permit_general_messages` tinyint(1) NOT NULL DEFAULT 0,
  `agreed_contact_method` enum('email','phone','post','none') NOT NULL DEFAULT 'none',
  `withdrawn_at` datetime DEFAULT NULL,
  `corrected_at` datetime DEFAULT NULL,
  `retention_expires_at` datetime NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_contact` (`unit_id`,`person_id`),
  UNIQUE KEY `uq_contact_guest_source` (`source_guest_contact_id`),
  KEY `idx_unit_contact_consent` (`unit_id`,`withdrawn_at`,`retention_expires_at`),
  KEY `fk_unit_contact_scope` (`permitted_unit_id`),
  KEY `fk_unit_contact_person` (`person_id`),
  KEY `fk_unit_contact_booking` (`source_booking_id`),
  CONSTRAINT `fk_unit_contact_booking` FOREIGN KEY (`source_booking_id`) REFERENCES `bookings` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_unit_contact_guest` FOREIGN KEY (`source_guest_contact_id`) REFERENCES `guest_contacts` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_unit_contact_person` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_unit_contact_scope` FOREIGN KEY (`permitted_unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_unit_contact_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_contact_unit_scope` CHECK (`unit_id` = `permitted_unit_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_contacts`
--

LOCK TABLES `unit_contacts` WRITE;
/*!40000 ALTER TABLE `unit_contacts` DISABLE KEYS */;
/*!40000 ALTER TABLE `unit_contacts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_display_links`
--

DROP TABLE IF EXISTS `unit_display_links`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_display_links` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `source_unit_id` bigint(20) unsigned NOT NULL,
  `target_unit_id` bigint(20) unsigned NOT NULL,
  `priority` int(10) unsigned NOT NULL DEFAULT 100,
  `active_from` date NOT NULL,
  `active_until` date DEFAULT NULL,
  `requested_by` bigint(20) unsigned DEFAULT NULL,
  `requested_at` datetime NOT NULL DEFAULT current_timestamp(),
  `accepted_by` bigint(20) unsigned DEFAULT NULL,
  `accepted_at` datetime DEFAULT NULL,
  `revoked_by` bigint(20) unsigned DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_display_direction` (`source_unit_id`,`target_unit_id`),
  KEY `idx_unit_display_source` (`source_unit_id`,`accepted_at`,`revoked_at`,`priority`),
  KEY `idx_unit_display_target` (`target_unit_id`,`accepted_at`,`revoked_at`),
  KEY `fk_unit_display_requester` (`requested_by`),
  KEY `fk_unit_display_accepter` (`accepted_by`),
  KEY `fk_unit_display_revoker` (`revoked_by`),
  CONSTRAINT `fk_unit_display_accepter` FOREIGN KEY (`accepted_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_unit_display_requester` FOREIGN KEY (`requested_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_unit_display_revoker` FOREIGN KEY (`revoked_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_unit_display_source` FOREIGN KEY (`source_unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_unit_display_target` FOREIGN KEY (`target_unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_unit_display_distinct` CHECK (`source_unit_id` <> `target_unit_id`),
  CONSTRAINT `chk_unit_display_dates` CHECK (`active_until` is null or `active_until` >= `active_from`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_display_links`
--

LOCK TABLES `unit_display_links` WRITE;
/*!40000 ALTER TABLE `unit_display_links` DISABLE KEYS */;
/*!40000 ALTER TABLE `unit_display_links` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_domains_or_slugs`
--

DROP TABLE IF EXISTS `unit_domains_or_slugs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_domains_or_slugs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `identifier_type` enum('slug','domain') NOT NULL,
  `identifier_value` varchar(253) NOT NULL,
  `normalized_value` varchar(253) GENERATED ALWAYS AS (lcase(trim(`identifier_value`))) STORED,
  `is_primary` tinyint(1) NOT NULL DEFAULT 0,
  `redirect_to_primary` tinyint(1) NOT NULL DEFAULT 1,
  `verified_at` datetime DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `primary_slot` varchar(80) GENERATED ALWAYS AS (case when `is_primary` = 1 and `active` = 1 then concat(`identifier_type`,':',`unit_id`) else NULL end) STORED,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_identifier` (`identifier_type`,`normalized_value`),
  UNIQUE KEY `uq_unit_primary_identifier` (`primary_slot`),
  KEY `idx_unit_identifier_unit` (`unit_id`,`identifier_type`,`active`),
  CONSTRAINT `fk_unit_identifier_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_domains_or_slugs`
--

LOCK TABLES `unit_domains_or_slugs` WRITE;
/*!40000 ALTER TABLE `unit_domains_or_slugs` DISABLE KEYS */;
INSERT INTO `unit_domains_or_slugs` VALUES (1,134,'slug','test-test','test-test',1,0,NULL,1,'slug:134','2026-09-28 16:50:44','2026-09-28 16:50:44');
/*!40000 ALTER TABLE `unit_domains_or_slugs` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_member_delivery_preferences`
--

DROP TABLE IF EXISTS `unit_member_delivery_preferences`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_member_delivery_preferences` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `essential_delivery` enum('email','post','both','none') NOT NULL DEFAULT 'email',
  `optional_delivery` enum('email','post','both','none') NOT NULL DEFAULT 'none',
  `postal_address_cipher` mediumtext DEFAULT NULL,
  `postal_address_source` enum('member_provided','officer_verified','imported','historic_record') DEFAULT NULL,
  `postal_verified_at` datetime DEFAULT NULL,
  `postal_verified_by` bigint(20) unsigned DEFAULT NULL,
  `updated_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_member_delivery` (`unit_id`,`person_id`),
  KEY `idx_delivery_person` (`person_id`,`unit_id`),
  KEY `postal_verified_by` (`postal_verified_by`),
  KEY `updated_by` (`updated_by`),
  CONSTRAINT `unit_member_delivery_preferences_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `unit_member_delivery_preferences_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE,
  CONSTRAINT `unit_member_delivery_preferences_ibfk_3` FOREIGN KEY (`postal_verified_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `unit_member_delivery_preferences_ibfk_4` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
  CONSTRAINT `chk_postal_verification` CHECK (`postal_address_cipher` is null and `postal_address_source` is null and `postal_verified_at` is null or `postal_address_cipher` is not null and `postal_address_source` is not null and `postal_verified_at` is not null)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_member_delivery_preferences`
--

LOCK TABLES `unit_member_delivery_preferences` WRITE;
/*!40000 ALTER TABLE `unit_member_delivery_preferences` DISABLE KEYS */;
/*!40000 ALTER TABLE `unit_member_delivery_preferences` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_members`
--

DROP TABLE IF EXISTS `unit_members`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_members` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `order_key` varchar(40) NOT NULL DEFAULT 'craft',
  `membership_type` varchar(80) NOT NULL,
  `admission_route` enum('admitted','joining') NOT NULL,
  `state` enum('active','inactive','resigned','deceased') NOT NULL DEFAULT 'active',
  `start_date` date NOT NULL,
  `end_date` date DEFAULT NULL,
  `participation_status` varchar(80) DEFAULT NULL,
  `contact_email` tinyint(1) NOT NULL DEFAULT 0,
  `contact_post` tinyint(1) NOT NULL DEFAULT 0,
  `contact_phone` tinyint(1) NOT NULL DEFAULT 0,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_member` (`unit_id`,`person_id`,`order_key`),
  KEY `idx_unit_member_state` (`unit_id`,`state`,`start_date`),
  KEY `fk_unit_member_person` (`person_id`),
  KEY `fk_unit_member_actor` (`created_by`),
  CONSTRAINT `fk_unit_member_actor` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_unit_member_person` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `fk_unit_member_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_member_dates` CHECK (`end_date` is null or `end_date` >= `start_date`)
) ENGINE=InnoDB AUTO_INCREMENT=151 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_members`
--

LOCK TABLES `unit_members` WRITE;
/*!40000 ALTER TABLE `unit_members` DISABLE KEYS */;
/*!40000 ALTER TABLE `unit_members` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_returns`
--

DROP TABLE IF EXISTS `unit_returns`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_returns` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `template_version_id` bigint(20) unsigned NOT NULL,
  `parent_return_id` bigint(20) unsigned DEFAULT NULL,
  `amendment_no` int(10) unsigned NOT NULL DEFAULT 0,
  `return_type` enum('annual','installation') NOT NULL,
  `order_key` varchar(40) NOT NULL,
  `period_start` date NOT NULL,
  `period_end` date NOT NULL,
  `installation_date` date DEFAULT NULL,
  `status` enum('draft','review','signed','locked','superseded') NOT NULL DEFAULT 'draft',
  `revision_no` int(10) unsigned NOT NULL DEFAULT 1,
  `working_payload_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`working_payload_json`)),
  `source_fingerprint` char(64) NOT NULL,
  `missing_flags_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`missing_flags_json`)),
  `validation_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`validation_json`)),
  `created_by` bigint(20) unsigned NOT NULL,
  `reviewed_by` bigint(20) unsigned DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  `signed_by` bigint(20) unsigned DEFAULT NULL,
  `signed_at` datetime DEFAULT NULL,
  `locked_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_return_amendment` (`unit_id`,`return_type`,`order_key`,`period_start`,`period_end`,`amendment_no`),
  KEY `idx_unit_return_province` (`province_id`,`status`,`period_end`),
  KEY `fk_unit_return_template` (`template_version_id`),
  KEY `fk_unit_return_parent` (`parent_return_id`),
  KEY `fk_unit_return_creator` (`created_by`),
  KEY `fk_unit_return_reviewer` (`reviewed_by`),
  KEY `fk_unit_return_signer` (`signed_by`),
  CONSTRAINT `fk_unit_return_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_unit_return_parent` FOREIGN KEY (`parent_return_id`) REFERENCES `unit_returns` (`id`),
  CONSTRAINT `fk_unit_return_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `fk_unit_return_reviewer` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_unit_return_signer` FOREIGN KEY (`signed_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_unit_return_template` FOREIGN KEY (`template_version_id`) REFERENCES `return_template_versions` (`id`),
  CONSTRAINT `fk_unit_return_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `chk_unit_return_period` CHECK (`period_end` >= `period_start`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_returns`
--

LOCK TABLES `unit_returns` WRITE;
/*!40000 ALTER TABLE `unit_returns` DISABLE KEYS */;
/*!40000 ALTER TABLE `unit_returns` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_role_invitations`
--

DROP TABLE IF EXISTS `unit_role_invitations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_role_invitations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `unit_id` bigint(20) unsigned NOT NULL,
  `email` varchar(254) NOT NULL,
  `role_key` varchar(50) NOT NULL,
  `token_hash` char(64) NOT NULL,
  `invited_by` bigint(20) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `expires_at` datetime NOT NULL,
  `accepted_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_role_token` (`token_hash`),
  KEY `idx_unit_role_pending` (`unit_id`,`email`,`expires_at`),
  KEY `invited_by` (`invited_by`),
  CONSTRAINT `unit_role_invitations_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `unit_role_invitations_ibfk_2` FOREIGN KEY (`invited_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_role_invitations`
--

LOCK TABLES `unit_role_invitations` WRITE;
/*!40000 ALTER TABLE `unit_role_invitations` DISABLE KEYS */;
/*!40000 ALTER TABLE `unit_role_invitations` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `unit_types`
--

DROP TABLE IF EXISTS `unit_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unit_types` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `type_key` varchar(40) NOT NULL,
  `display_name` varchar(100) NOT NULL,
  `body_noun` varchar(50) NOT NULL,
  `member_noun` varchar(50) NOT NULL,
  `built_in` tinyint(1) NOT NULL DEFAULT 0,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_type_key` (`type_key`),
  KEY `idx_unit_type_active` (`active`,`display_name`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `unit_types`
--

LOCK TABLES `unit_types` WRITE;
/*!40000 ALTER TABLE `unit_types` DISABLE KEYS */;
INSERT INTO `unit_types` VALUES (1,'lodge','Lodge','Lodge','Brother',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),(2,'chapter','Chapter','Chapter','Companion',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),(3,'council','Council','Council','Companion',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01'),(4,'other','Other Masonic Body','Unit','Member',1,1,'2026-09-27 21:01:01','2026-09-27 21:01:01');
/*!40000 ALTER TABLE `unit_types` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `units`
--

DROP TABLE IF EXISTS `units`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `units` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `unit_type_id` smallint(5) unsigned NOT NULL,
  `name` varchar(200) NOT NULL,
  `number` varchar(30) NOT NULL DEFAULT '',
  `slug` varchar(100) NOT NULL,
  `unit_type` varchar(50) NOT NULL DEFAULT 'lodge',
  `order_key` varchar(40) DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` bigint(20) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_unit_slug` (`slug`),
  UNIQUE KEY `uq_unit_province_name_number` (`province_id`,`name`,`number`),
  KEY `idx_unit_province_active` (`province_id`,`active`),
  KEY `idx_units_type_active` (`unit_type_id`,`active`),
  KEY `idx_units_province_visible` (`province_id`,`deleted_at`,`active`),
  KEY `fk_units_deleted_by` (`deleted_by`),
  CONSTRAINT `fk_unit_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `fk_units_deleted_by` FOREIGN KEY (`deleted_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_units_unit_type` FOREIGN KEY (`unit_type_id`) REFERENCES `unit_types` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=247 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `units`
--

LOCK TABLES `units` WRITE;
/*!40000 ALTER TABLE `units` DISABLE KEYS */;
INSERT INTO `units` VALUES (134,103,1,'test','0000','test-test','lodge','craft',1,'2026-09-28 16:50:44','2026-09-28 16:50:44',NULL,NULL);
/*!40000 ALTER TABLE `units` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `user_memberships`
--

DROP TABLE IF EXISTS `user_memberships`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user_memberships` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL,
  `scope_type` enum('platform','province','unit') NOT NULL,
  `province_id` bigint(20) unsigned DEFAULT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `role` varchar(50) NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `scope_key` varchar(80) GENERATED ALWAYS AS (case `scope_type` when 'platform' then 'platform' when 'province' then concat('province:',`province_id`) else concat('unit:',`unit_id`) end) STORED,
  `expires_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `last_used_at` datetime DEFAULT NULL,
  `reviewed_at` datetime DEFAULT NULL,
  `review_due_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_user_membership` (`user_id`,`scope_type`,`scope_key`),
  KEY `idx_membership_province` (`province_id`,`user_id`,`active`),
  KEY `idx_membership_unit` (`unit_id`,`user_id`,`active`),
  KEY `idx_membership_role_scope` (`role`,`scope_type`),
  KEY `idx_membership_expiry` (`user_id`,`active`,`expires_at`),
  KEY `idx_membership_review` (`scope_type`,`province_id`,`unit_id`,`review_due_at`),
  CONSTRAINT `fk_membership_province` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_membership_role_scope` FOREIGN KEY (`role`, `scope_type`) REFERENCES `tenant_role_scopes` (`role_key`, `scope_type`),
  CONSTRAINT `fk_membership_unit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_membership_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `chk_membership_scope` CHECK (`scope_type` = 'platform' and `province_id` is null and `unit_id` is null or `scope_type` = 'province' and `province_id` is not null and `unit_id` is null or `scope_type` = 'unit' and `province_id` is null and `unit_id` is not null)
) ENGINE=InnoDB AUTO_INCREMENT=54 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user_memberships`
--

LOCK TABLES `user_memberships` WRITE;
/*!40000 ALTER TABLE `user_memberships` DISABLE KEYS */;
INSERT INTO `user_memberships` VALUES (1,1,'platform',NULL,NULL,'platform_admin',1,'2026-09-27 22:07:43','2026-09-28 18:39:52','platform',NULL,NULL,'2026-09-28 18:39:52',NULL,NULL);
/*!40000 ALTER TABLE `user_memberships` ENABLE KEYS */;
UNLOCK TABLES;

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

DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `email` varchar(254) NOT NULL,
  `display_name` varchar(150) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `role` enum('admin','secretary','dining','treasurer','worshipful_master','readonly','member') NOT NULL DEFAULT 'member',
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `two_factor_enabled` tinyint(1) NOT NULL DEFAULT 0,
  `failed_logins` int(10) unsigned NOT NULL DEFAULT 0,
  `locked_until` datetime DEFAULT NULL,
  `last_login_at` datetime DEFAULT NULL,
  `password_changed_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_user_email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=129 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `users`
--

LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,'cajtaylor@gmail.com','Carl - Global Admin','$2y$10$mjHpfn7a/XU7.cUpqz5ka.G4JAKlPFFu5i1OQNVJiOdqJptLgl2wm','admin',1,0,0,NULL,'2026-09-28 18:39:43','2026-09-28 12:43:42','2026-09-27 22:07:43','2026-09-28 18:39:43');
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_case_assignments`
--

DROP TABLE IF EXISTS `welfare_case_assignments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_case_assignments` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint(20) unsigned NOT NULL,
  `assigned_user_id` bigint(20) unsigned NOT NULL,
  `assigned_by` bigint(20) unsigned NOT NULL,
  `assigned_at` datetime NOT NULL DEFAULT current_timestamp(),
  `ended_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_welfare_assignment` (`case_id`,`ended_at`),
  KEY `assigned_user_id` (`assigned_user_id`),
  KEY `assigned_by` (`assigned_by`),
  CONSTRAINT `welfare_case_assignments_ibfk_1` FOREIGN KEY (`case_id`) REFERENCES `welfare_cases` (`id`),
  CONSTRAINT `welfare_case_assignments_ibfk_2` FOREIGN KEY (`assigned_user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `welfare_case_assignments_ibfk_3` FOREIGN KEY (`assigned_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_case_assignments`
--

LOCK TABLES `welfare_case_assignments` WRITE;
/*!40000 ALTER TABLE `welfare_case_assignments` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_case_assignments` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_case_events`
--

DROP TABLE IF EXISTS `welfare_case_events`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_case_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint(20) unsigned DEFAULT NULL,
  `scope_key` varchar(80) NOT NULL,
  `actor_id` bigint(20) unsigned NOT NULL,
  `event_key` varchar(80) NOT NULL,
  `occurred_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_welfare_event` (`scope_key`,`occurred_at`),
  KEY `case_id` (`case_id`),
  KEY `actor_id` (`actor_id`),
  CONSTRAINT `welfare_case_events_ibfk_1` FOREIGN KEY (`case_id`) REFERENCES `welfare_cases` (`id`) ON DELETE SET NULL,
  CONSTRAINT `welfare_case_events_ibfk_2` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_case_events`
--

LOCK TABLES `welfare_case_events` WRITE;
/*!40000 ALTER TABLE `welfare_case_events` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_case_events` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_cases`
--

DROP TABLE IF EXISTS `welfare_cases`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_cases` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_key` varchar(80) NOT NULL,
  `scope_type` enum('unit','province') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `person_id` bigint(20) unsigned NOT NULL,
  `assigned_user_id` bigint(20) unsigned NOT NULL,
  `status` enum('open','review','closed','withdrawn','retired') NOT NULL DEFAULT 'open',
  `personal_summary_cipher` longtext DEFAULT NULL,
  `working_notes_cipher` longtext DEFAULT NULL,
  `contains_health_information` tinyint(1) NOT NULL DEFAULT 0,
  `legal_basis_snapshot` varchar(255) NOT NULL,
  `special_condition_snapshot` varchar(255) DEFAULT NULL,
  `opened_on` date NOT NULL,
  `next_review_on` date DEFAULT NULL,
  `retention_review_due` date NOT NULL,
  `withdrawn_at` datetime DEFAULT NULL,
  `retired_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_welfare_case_queue` (`scope_key`,`assigned_user_id`,`status`,`next_review_on`),
  KEY `idx_welfare_case_person` (`person_id`,`scope_key`),
  KEY `province_id` (`province_id`),
  KEY `unit_id` (`unit_id`),
  KEY `assigned_user_id` (`assigned_user_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `welfare_cases_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `welfare_cases_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `welfare_cases_ibfk_3` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `welfare_cases_ibfk_4` FOREIGN KEY (`assigned_user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `welfare_cases_ibfk_5` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_cases`
--

LOCK TABLES `welfare_cases` WRITE;
/*!40000 ALTER TABLE `welfare_cases` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_cases` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_contacts`
--

DROP TABLE IF EXISTS `welfare_contacts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_contacts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint(20) unsigned NOT NULL,
  `contact_type` enum('phone','email','letter','visit','message','other') NOT NULL,
  `occurred_at` datetime NOT NULL,
  `private_note_cipher` longtext DEFAULT NULL,
  `agreed_follow_up_cipher` longtext DEFAULT NULL,
  `follow_up_due` datetime DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_welfare_followup` (`case_id`,`follow_up_due`,`completed_at`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `welfare_contacts_ibfk_1` FOREIGN KEY (`case_id`) REFERENCES `welfare_cases` (`id`),
  CONSTRAINT `welfare_contacts_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_contacts`
--

LOCK TABLES `welfare_contacts` WRITE;
/*!40000 ALTER TABLE `welfare_contacts` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_contacts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_exceptional_access`
--

DROP TABLE IF EXISTS `welfare_exceptional_access`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_exceptional_access` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_key` varchar(80) NOT NULL,
  `user_id` bigint(20) unsigned NOT NULL,
  `granted_by` bigint(20) unsigned NOT NULL,
  `reason_cipher` longtext NOT NULL,
  `granted_at` datetime NOT NULL DEFAULT current_timestamp(),
  `expires_at` datetime NOT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `last_used_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_welfare_exception` (`scope_key`,`user_id`,`expires_at`,`revoked_at`),
  KEY `user_id` (`user_id`),
  KEY `granted_by` (`granted_by`),
  CONSTRAINT `welfare_exceptional_access_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `welfare_exceptional_access_ibfk_2` FOREIGN KEY (`granted_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_exceptional_access`
--

LOCK TABLES `welfare_exceptional_access` WRITE;
/*!40000 ALTER TABLE `welfare_exceptional_access` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_exceptional_access` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_gestures`
--

DROP TABLE IF EXISTS `welfare_gestures`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_gestures` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint(20) unsigned NOT NULL,
  `gesture_type` enum('card','flowers','visit','cheque','support','reimbursement') NOT NULL,
  `planned_for` date NOT NULL,
  `status` enum('planned','approved','sent','completed','cancelled','rejected','paid') NOT NULL DEFAULT 'planned',
  `amount` decimal(12,2) DEFAULT NULL,
  `accounting_category` varchar(80) DEFAULT NULL,
  `private_reason_cipher` longtext DEFAULT NULL,
  `finance_entry_id` bigint(20) unsigned DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_welfare_gesture` (`case_id`,`status`,`planned_for`),
  KEY `idx_welfare_finance` (`status`,`accounting_category`,`planned_for`),
  KEY `finance_entry_id` (`finance_entry_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `welfare_gestures_ibfk_1` FOREIGN KEY (`case_id`) REFERENCES `welfare_cases` (`id`),
  CONSTRAINT `welfare_gestures_ibfk_2` FOREIGN KEY (`finance_entry_id`) REFERENCES `finance_ledger_entries` (`id`),
  CONSTRAINT `welfare_gestures_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`gesture_type` in ('cheque','support','reimbursement') and `amount` is not null and `amount` > 0 and `accounting_category` is not null or `gesture_type` not in ('cheque','support','reimbursement') and `amount` is null)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_gestures`
--

LOCK TABLES `welfare_gestures` WRITE;
/*!40000 ALTER TABLE `welfare_gestures` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_gestures` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_life_events`
--

DROP TABLE IF EXISTS `welfare_life_events`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_life_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint(20) unsigned NOT NULL,
  `event_type` enum('bereavement','illness','hospital','recovery','death','care','other') NOT NULL,
  `event_date` date NOT NULL,
  `private_detail_cipher` longtext DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_welfare_life_event` (`case_id`,`event_date`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `welfare_life_events_ibfk_1` FOREIGN KEY (`case_id`) REFERENCES `welfare_cases` (`id`),
  CONSTRAINT `welfare_life_events_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_life_events`
--

LOCK TABLES `welfare_life_events` WRITE;
/*!40000 ALTER TABLE `welfare_life_events` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_life_events` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_related_contacts`
--

DROP TABLE IF EXISTS `welfare_related_contacts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_related_contacts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_key` varchar(80) NOT NULL,
  `member_person_id` bigint(20) unsigned NOT NULL,
  `related_person_id` bigint(20) unsigned DEFAULT NULL,
  `relationship_type` enum('spouse','partner','surviving_spouse','surviving_partner','other') NOT NULL,
  `display_name_cipher` longtext NOT NULL,
  `email_cipher` longtext DEFAULT NULL,
  `phone_cipher` longtext DEFAULT NULL,
  `address_cipher` longtext DEFAULT NULL,
  `preferred_channel` enum('email','phone','post','none') NOT NULL DEFAULT 'none',
  `contact_allowed` tinyint(1) NOT NULL DEFAULT 0,
  `preference_source` varchar(255) NOT NULL,
  `preference_recorded_at` datetime NOT NULL,
  `withdrawn_at` datetime DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_welfare_relation` (`scope_key`,`member_person_id`,`withdrawn_at`),
  KEY `member_person_id` (`member_person_id`),
  KEY `related_person_id` (`related_person_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `welfare_related_contacts_ibfk_1` FOREIGN KEY (`member_person_id`) REFERENCES `people` (`id`),
  CONSTRAINT `welfare_related_contacts_ibfk_2` FOREIGN KEY (`related_person_id`) REFERENCES `people` (`id`) ON DELETE SET NULL,
  CONSTRAINT `welfare_related_contacts_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_related_contacts`
--

LOCK TABLES `welfare_related_contacts` WRITE;
/*!40000 ALTER TABLE `welfare_related_contacts` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_related_contacts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `welfare_scope_settings`
--

DROP TABLE IF EXISTS `welfare_scope_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `welfare_scope_settings` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `scope_key` varchar(80) NOT NULL,
  `scope_type` enum('unit','province') NOT NULL,
  `province_id` bigint(20) unsigned NOT NULL,
  `unit_id` bigint(20) unsigned DEFAULT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 0,
  `legal_basis` varchar(255) NOT NULL,
  `special_category_condition` varchar(255) DEFAULT NULL,
  `health_information_enabled` tinyint(1) NOT NULL DEFAULT 0,
  `retention_months` smallint(5) unsigned NOT NULL DEFAULT 24,
  `approved_by` bigint(20) unsigned NOT NULL,
  `approved_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_welfare_scope` (`scope_key`),
  KEY `idx_welfare_mandate` (`province_id`,`scope_type`,`enabled`),
  KEY `unit_id` (`unit_id`),
  KEY `approved_by` (`approved_by`),
  CONSTRAINT `welfare_scope_settings_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
  CONSTRAINT `welfare_scope_settings_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`),
  CONSTRAINT `welfare_scope_settings_ibfk_3` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`),
  CONSTRAINT `CONSTRAINT_1` CHECK (`retention_months` between 1 and 120)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `welfare_scope_settings`
--

LOCK TABLES `welfare_scope_settings` WRITE;
/*!40000 ALTER TABLE `welfare_scope_settings` DISABLE KEYS */;
/*!40000 ALTER TABLE `welfare_scope_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping events for database 'masonic_office'
--

--
-- Dumping routines for database 'masonic_office'
--

--
-- Final view structure for view `active_user_memberships`
--

/*!50001 DROP VIEW IF EXISTS `active_user_memberships`*/;
/*!50001 SET @saved_cs_client          = @@character_set_client */;
/*!50001 SET @saved_cs_results         = @@character_set_results */;
/*!50001 SET @saved_col_connection     = @@collation_connection */;
/*!50001 SET character_set_client      = utf8mb4 */;
/*!50001 SET character_set_results     = utf8mb4 */;
/*!50001 SET collation_connection      = utf8mb4_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `active_user_memberships` AS select `m`.`id` AS `id`,`m`.`user_id` AS `user_id`,`m`.`scope_type` AS `scope_type`,`m`.`province_id` AS `province_id`,`m`.`unit_id` AS `unit_id`,`m`.`role` AS `role`,`m`.`active` AS `active`,`m`.`created_at` AS `created_at`,`m`.`updated_at` AS `updated_at`,`m`.`scope_key` AS `scope_key`,`m`.`expires_at` AS `expires_at`,`m`.`revoked_at` AS `revoked_at`,`m`.`last_used_at` AS `last_used_at`,`m`.`reviewed_at` AS `reviewed_at`,`m`.`review_due_at` AS `review_due_at` from `user_memberships` `m` where `m`.`active` = 1 and `m`.`revoked_at` is null and (`m`.`expires_at` is null or `m`.`expires_at` > current_timestamp()) and exists(select 1 from `users` `u` where `u`.`id` = `m`.`user_id` and `u`.`active` = 1 limit 1) */;
/*!50001 SET character_set_client      = @saved_cs_client */;
/*!50001 SET character_set_results     = @saved_cs_results */;
/*!50001 SET collation_connection      = @saved_col_connection */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

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

-- Dump completed on 2026-09-28 18:40:52
