{
  "tables": {
    "attendance_events": {
      "ddl": "CREATE TABLE `attendance_events` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `session_id` bigint(20) unsigned NOT NULL,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `type` varchar(24) NOT NULL,\n  `recorded_at` datetime(3) NOT NULL,\n  `sequence` smallint(5) unsigned NOT NULL,\n  `idempotency_key` varchar(80) NOT NULL,\n  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),\n  `created_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `attendance_events_session_id_sequence_unique` (`session_id`,`sequence`),\n  UNIQUE KEY `attendance_events_user_id_idempotency_key_unique` (`user_id`,`idempotency_key`),\n  UNIQUE KEY `attendance_events_legacy_id_unique` (`legacy_id`),\n  KEY `attendance_events_user_id_recorded_at_index` (`user_id`,`recorded_at`),\n  CONSTRAINT `attendance_events_session_id_foreign` FOREIGN KEY (`session_id`) REFERENCES `attendance_sessions` (`id`),\n  CONSTRAINT `attendance_events_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `attendance_events_sequence_check` CHECK (`sequence` >= 1),\n  CONSTRAINT `attendance_events_type_check` CHECK (`type` in ('travel_check_in','start_work','start_break','end_break','start_private_leave','end_private_leave','final_check_out','worksite_arrival','return_departure'))\n) ENGINE=InnoDB AUTO_INCREMENT=154 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "attendance_locations": {
      "ddl": "CREATE TABLE `attendance_locations` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `event_id` bigint(20) unsigned NOT NULL,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `latitude` double NOT NULL,\n  `longitude` double NOT NULL,\n  `accuracy_meters` double NOT NULL,\n  `device_timestamp` datetime(3) DEFAULT NULL,\n  `retain_until` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `attendance_locations_event_id_unique` (`event_id`),\n  KEY `attendance_locations_user_id_created_at_index` (`user_id`,`created_at`),\n  CONSTRAINT `attendance_locations_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `attendance_events` (`id`),\n  CONSTRAINT `attendance_locations_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `attendance_locations_range_check` CHECK (`latitude` between -90 and 90 and `longitude` between -180 and 180 and `accuracy_meters` >= 0)\n) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "attendance_sessions": {
      "ddl": "CREATE TABLE `attendance_sessions` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `work_date` date NOT NULL,\n  `timezone` varchar(64) NOT NULL,\n  `status` varchar(16) NOT NULL DEFAULT 'not_started',\n  `started_at` datetime(3) NOT NULL,\n  `finished_at` datetime(3) DEFAULT NULL,\n  `abandoned_at` datetime(3) DEFAULT NULL,\n  `scheduled_start_at` datetime(3) DEFAULT NULL,\n  `scheduled_end_at` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `attendance_sessions_user_id_work_date_unique` (`user_id`,`work_date`),\n  UNIQUE KEY `attendance_sessions_legacy_id_unique` (`legacy_id`),\n  KEY `attendance_sessions_work_date_index` (`work_date`),\n  KEY `attendance_sessions_user_id_status_index` (`user_id`,`status`),\n  CONSTRAINT `attendance_sessions_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `attendance_sessions_status_check` CHECK (`status` in ('not_started','traveling','working','on_break','private_leave','finished','on_site','return_travel'))\n) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "audit_logs": {
      "ddl": "CREATE TABLE `audit_logs` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `actor_id` bigint(20) unsigned DEFAULT NULL,\n  `subject_id` bigint(20) unsigned DEFAULT NULL,\n  `action` varchar(64) NOT NULL,\n  `entity` varchar(64) NOT NULL,\n  `entity_id` varchar(64) DEFAULT NULL,\n  `metadata` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata`)),\n  `created_at` datetime(3) NOT NULL,\n  PRIMARY KEY (`id`),\n  KEY `audit_logs_actor_id_foreign` (`actor_id`),\n  KEY `audit_logs_entity_entity_id_index` (`entity`,`entity_id`),\n  KEY `audit_logs_subject_id_created_at_index` (`subject_id`,`created_at`),\n  KEY `audit_logs_action_created_at_index` (`action`,`created_at`),\n  CONSTRAINT `audit_logs_actor_id_foreign` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `audit_logs_subject_id_foreign` FOREIGN KEY (`subject_id`) REFERENCES `users` (`id`) ON DELETE SET NULL\n) ENGINE=InnoDB AUTO_INCREMENT=612 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "cache": {
      "ddl": "CREATE TABLE `cache` (\n  `key` varchar(255) NOT NULL,\n  `value` mediumtext NOT NULL,\n  `expiration` bigint(20) NOT NULL,\n  PRIMARY KEY (`key`),\n  KEY `cache_expiration_index` (`expiration`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "cache_locks": {
      "ddl": "CREATE TABLE `cache_locks` (\n  `key` varchar(255) NOT NULL,\n  `owner` varchar(255) NOT NULL,\n  `expiration` bigint(20) NOT NULL,\n  PRIMARY KEY (`key`),\n  KEY `cache_locks_expiration_index` (`expiration`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "company_settings": {
      "ddl": "CREATE TABLE `company_settings` (\n  `id` tinyint(3) unsigned NOT NULL,\n  `timezone` varchar(64) NOT NULL DEFAULT 'Europe/Zurich',\n  `late_threshold_minutes` smallint(5) unsigned NOT NULL DEFAULT 15,\n  `location_retention_days` smallint(5) unsigned DEFAULT NULL,\n  `report_recipient_email` varchar(255) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  `worksite_permissions` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`worksite_permissions`)),\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "daily_work_report_items": {
      "ddl": "CREATE TABLE `daily_work_report_items` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `report_id` bigint(20) unsigned NOT NULL,\n  `kind` varchar(12) NOT NULL,\n  `position` smallint(5) unsigned NOT NULL,\n  `title` varchar(140) NOT NULL,\n  `description` text DEFAULT NULL,\n  `note` text DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `daily_work_report_items_report_id_kind_position_index` (`report_id`,`kind`,`position`),\n  CONSTRAINT `daily_work_report_items_report_id_foreign` FOREIGN KEY (`report_id`) REFERENCES `daily_work_reports` (`id`),\n  CONSTRAINT `daily_report_items_kind_check` CHECK (`kind` in ('completed','incomplete'))\n) ENGINE=InnoDB AUTO_INCREMENT=140 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "daily_work_reports": {
      "ddl": "CREATE TABLE `daily_work_reports` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `work_date` date NOT NULL,\n  `status` varchar(12) NOT NULL DEFAULT 'draft',\n  `notes` text DEFAULT NULL,\n  `submitted_at` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `daily_work_reports_user_id_work_date_unique` (`user_id`,`work_date`),\n  UNIQUE KEY `daily_work_reports_legacy_id_unique` (`legacy_id`),\n  KEY `daily_work_reports_work_date_status_index` (`work_date`,`status`),\n  CONSTRAINT `daily_work_reports_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `daily_reports_status_check` CHECK (`status` in ('draft','submitted')),\n  CONSTRAINT `daily_reports_submitted_check` CHECK (`status` = 'submitted' = (`submitted_at` is not null))\n) ENGINE=InnoDB AUTO_INCREMENT=118 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "delivery_policies": {
      "ddl": "CREATE TABLE `delivery_policies` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `version` smallint(5) unsigned NOT NULL,\n  `cutoff_minutes` smallint(5) unsigned NOT NULL,\n  `days_before_cutoff` tinyint(3) unsigned NOT NULL,\n  `days_after_cutoff` tinyint(3) unsigned NOT NULL,\n  `skip_weekends` tinyint(1) NOT NULL DEFAULT 0,\n  `holidays` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`holidays`)),\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `delivery_policies_version_unique` (`version`),\n  KEY `delivery_policies_created_by_id_foreign` (`created_by_id`),\n  CONSTRAINT `delivery_policies_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `policies_check` CHECK (`version` >= 1 and `cutoff_minutes` between 0 and 1439 and `days_before_cutoff` between 0 and 30 and `days_after_cutoff` between 0 and 30)\n) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "failed_jobs": {
      "ddl": "CREATE TABLE `failed_jobs` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `uuid` varchar(255) NOT NULL,\n  `connection` varchar(255) NOT NULL,\n  `queue` varchar(255) NOT NULL,\n  `payload` longtext NOT NULL,\n  `exception` longtext NOT NULL,\n  `failed_at` timestamp NOT NULL DEFAULT current_timestamp(),\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`),\n  KEY `failed_jobs_connection_queue_failed_at_index` (`connection`,`queue`,`failed_at`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "job_batches": {
      "ddl": "CREATE TABLE `job_batches` (\n  `id` varchar(255) NOT NULL,\n  `name` varchar(255) NOT NULL,\n  `total_jobs` int(11) NOT NULL,\n  `pending_jobs` int(11) NOT NULL,\n  `failed_jobs` int(11) NOT NULL,\n  `failed_job_ids` longtext NOT NULL,\n  `options` mediumtext DEFAULT NULL,\n  `cancelled_at` int(11) DEFAULT NULL,\n  `created_at` int(11) NOT NULL,\n  `finished_at` int(11) DEFAULT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "jobs": {
      "ddl": "CREATE TABLE `jobs` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `queue` varchar(255) NOT NULL,\n  `payload` longtext NOT NULL,\n  `attempts` smallint(5) unsigned NOT NULL,\n  `reserved_at` int(10) unsigned DEFAULT NULL,\n  `available_at` int(10) unsigned NOT NULL,\n  `created_at` int(10) unsigned NOT NULL,\n  PRIMARY KEY (`id`),\n  KEY `jobs_queue_index` (`queue`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "late_arrival_explanations": {
      "ddl": "CREATE TABLE `late_arrival_explanations` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `session_id` bigint(20) unsigned NOT NULL,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `event_id` bigint(20) unsigned NOT NULL,\n  `scheduled_start_at` datetime(3) NOT NULL,\n  `actual_start_at` datetime(3) NOT NULL,\n  `minutes_late` smallint(5) unsigned NOT NULL,\n  `status` varchar(12) NOT NULL DEFAULT 'pending',\n  `reason` text DEFAULT NULL,\n  `submitted_at` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `late_arrival_explanations_session_id_unique` (`session_id`),\n  UNIQUE KEY `late_arrival_explanations_event_id_unique` (`event_id`),\n  KEY `late_arrival_explanations_user_id_status_index` (`user_id`,`status`),\n  CONSTRAINT `late_arrival_explanations_event_id_foreign` FOREIGN KEY (`event_id`) REFERENCES `attendance_events` (`id`),\n  CONSTRAINT `late_arrival_explanations_session_id_foreign` FOREIGN KEY (`session_id`) REFERENCES `attendance_sessions` (`id`),\n  CONSTRAINT `late_arrival_explanations_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `late_explanations_status_check` CHECK (`status` in ('pending','submitted'))\n) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "leave_requests": {
      "ddl": "CREATE TABLE `leave_requests` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `worker_id` bigint(20) unsigned NOT NULL,\n  `start_date` date NOT NULL,\n  `end_date` date NOT NULL,\n  `comment` text NOT NULL,\n  `status` varchar(10) NOT NULL DEFAULT 'pending',\n  `approved_by_id` bigint(20) unsigned DEFAULT NULL,\n  `approved_at` datetime(3) DEFAULT NULL,\n  `idempotency_key` varchar(64) NOT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  `decided_by_id` bigint(20) unsigned DEFAULT NULL,\n  `decided_at` datetime(3) DEFAULT NULL,\n  `rejection_reason` text DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `leave_requests_worker_id_idempotency_key_unique` (`worker_id`,`idempotency_key`),\n  UNIQUE KEY `leave_requests_legacy_id_unique` (`legacy_id`),\n  KEY `leave_requests_approved_by_id_foreign` (`approved_by_id`),\n  KEY `leave_requests_worker_id_created_at_index` (`worker_id`,`created_at`),\n  KEY `leave_requests_status_created_at_index` (`status`,`created_at`),\n  KEY `leave_requests_decided_by_id_foreign` (`decided_by_id`),\n  CONSTRAINT `leave_requests_approved_by_id_foreign` FOREIGN KEY (`approved_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `leave_requests_decided_by_id_foreign` FOREIGN KEY (`decided_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `leave_requests_worker_id_foreign` FOREIGN KEY (`worker_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `leave_dates_check` CHECK (`end_date` >= `start_date`),\n  CONSTRAINT `leave_comment_check` CHECK (char_length(trim(`comment`)) between 3 and 500),\n  CONSTRAINT `leave_status_check` CHECK (`status` in ('pending','approved','rejected')),\n  CONSTRAINT `leave_approval_check` CHECK (`status` = 'pending' and `approved_by_id` is null and `approved_at` is null and `decided_by_id` is null and `decided_at` is null and `rejection_reason` is null or `status` = 'approved' and `approved_by_id` is not null and `approved_at` is not null and `decided_by_id` is not null and `decided_at` is not null and `decided_by_id` = `approved_by_id` and `decided_at` = `approved_at` and `decided_by_id` <> `worker_id` and `rejection_reason` is null or `status` = 'rejected' and `approved_by_id` is null and `approved_at` is null and `decided_by_id` is not null and `decided_at` is not null and `decided_by_id` <> `worker_id` and `rejection_reason` is not null and char_length(trim(`rejection_reason`)) between 3 and 500)\n) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "material_order_items": {
      "ddl": "CREATE TABLE `material_order_items` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `order_id` bigint(20) unsigned NOT NULL,\n  `name` varchar(120) NOT NULL,\n  `quantity` decimal(10,2) NOT NULL,\n  `unit` varchar(5) NOT NULL,\n  `position` smallint(5) unsigned NOT NULL DEFAULT 0,\n  PRIMARY KEY (`id`),\n  KEY `material_order_items_order_id_index` (`order_id`),\n  CONSTRAINT `material_order_items_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `material_orders` (`id`),\n  CONSTRAINT `order_items_name_check` CHECK (char_length(trim(`name`)) > 0),\n  CONSTRAINT `order_items_unit_check` CHECK (`unit` in ('pack','piece','meter')),\n  CONSTRAINT `order_items_qty_check` CHECK (`quantity` > 0 and (`unit` = 'meter' or `quantity` = floor(`quantity`)))\n) ENGINE=InnoDB AUTO_INCREMENT=109 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "material_order_status_history": {
      "ddl": "CREATE TABLE `material_order_status_history` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `order_id` bigint(20) unsigned NOT NULL,\n  `previous_status` varchar(12) DEFAULT NULL,\n  `new_status` varchar(12) NOT NULL,\n  `changed_by_id` bigint(20) unsigned DEFAULT NULL,\n  `changed_at` datetime(3) NOT NULL,\n  `note` text DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `material_order_status_history_changed_by_id_foreign` (`changed_by_id`),\n  KEY `material_order_status_history_order_id_changed_at_index` (`order_id`,`changed_at`),\n  CONSTRAINT `material_order_status_history_changed_by_id_foreign` FOREIGN KEY (`changed_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `material_order_status_history_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `material_orders` (`id`),\n  CONSTRAINT `order_history_status_check` CHECK (`new_status` in ('submitted','accepted','cancelled') and (`previous_status` is null or `previous_status` in ('submitted','accepted','cancelled')))\n) ENGINE=InnoDB AUTO_INCREMENT=122 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "material_orders": {
      "ddl": "CREATE TABLE `material_orders` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `reference` char(14) NOT NULL,\n  `requested_by` bigint(20) unsigned NOT NULL,\n  `status` varchar(12) NOT NULL DEFAULT 'submitted',\n  `submitted_at` datetime(3) NOT NULL,\n  `expected_delivery_date` date DEFAULT NULL,\n  `delivery_policy_version` smallint(5) unsigned DEFAULT NULL,\n  `notes` text DEFAULT NULL,\n  `worksite_name` varchar(120) DEFAULT NULL,\n  `idempotency_key` varchar(64) NOT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `material_orders_requested_by_idempotency_key_unique` (`requested_by`,`idempotency_key`),\n  UNIQUE KEY `material_orders_reference_unique` (`reference`),\n  UNIQUE KEY `material_orders_legacy_id_unique` (`legacy_id`),\n  KEY `material_orders_status_index` (`status`),\n  KEY `material_orders_submitted_at_index` (`submitted_at`),\n  CONSTRAINT `material_orders_requested_by_foreign` FOREIGN KEY (`requested_by`) REFERENCES `users` (`id`),\n  CONSTRAINT `orders_reference_check` CHECK (`reference` regexp '^QW-[0-9]{4}-[0-9]{6}$'),\n  CONSTRAINT `orders_status_check` CHECK (`status` in ('submitted','accepted','cancelled')),\n  CONSTRAINT `orders_worksite_check` CHECK (`worksite_name` is null or char_length(trim(`worksite_name`)) between 2 and 120)\n) ENGINE=InnoDB AUTO_INCREMENT=104 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "migrations": {
      "ddl": "CREATE TABLE `migrations` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `migration` varchar(255) NOT NULL,\n  `batch` int(11) NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "notification_outbox": {
      "ddl": "CREATE TABLE `notification_outbox` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `dedupe_key` varchar(255) NOT NULL,\n  `type` varchar(64) NOT NULL,\n  `actor_id` bigint(20) unsigned DEFAULT NULL,\n  `employee_id` bigint(20) unsigned DEFAULT NULL,\n  `entity_type` varchar(64) NOT NULL,\n  `entity_id` bigint(20) unsigned NOT NULL,\n  `params` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`params`)),\n  `status` varchar(16) NOT NULL DEFAULT 'pending',\n  `attempts` int(10) unsigned NOT NULL DEFAULT 0,\n  `last_error` varchar(64) DEFAULT NULL,\n  `last_attempt_at` datetime(3) DEFAULT NULL,\n  `created_at` timestamp(3) NULL DEFAULT NULL,\n  `updated_at` timestamp(3) NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `notification_outbox_dedupe_key_unique` (`dedupe_key`),\n  KEY `notification_outbox_actor_id_foreign` (`actor_id`),\n  KEY `notification_outbox_employee_id_foreign` (`employee_id`),\n  KEY `notification_outbox_status_index` (`status`),\n  CONSTRAINT `notification_outbox_actor_id_foreign` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `notification_outbox_employee_id_foreign` FOREIGN KEY (`employee_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=292 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "notification_preferences": {
      "ddl": "CREATE TABLE `notification_preferences` (\n  `user_id` bigint(20) unsigned NOT NULL,\n  `in_app` tinyint(1) NOT NULL DEFAULT 1,\n  `browser` tinyint(1) NOT NULL DEFAULT 0,\n  `attendance` tinyint(1) NOT NULL DEFAULT 1,\n  `reports` tinyint(1) NOT NULL DEFAULT 1,\n  `orders` tinyint(1) NOT NULL DEFAULT 1,\n  `weekly` tinyint(1) NOT NULL DEFAULT 1,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`user_id`),\n  CONSTRAINT `notification_preferences_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "notifications": {
      "ddl": "CREATE TABLE `notifications` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `recipient_id` bigint(20) unsigned NOT NULL,\n  `type` varchar(32) NOT NULL,\n  `category` varchar(12) NOT NULL,\n  `actor_id` bigint(20) unsigned DEFAULT NULL,\n  `entity_type` varchar(32) NOT NULL,\n  `entity_id` bigint(20) unsigned NOT NULL,\n  `params` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`params`)),\n  `dedupe_key` varchar(120) NOT NULL,\n  `created_at` datetime(3) NOT NULL,\n  `read_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `notifications_recipient_id_dedupe_key_unique` (`recipient_id`,`dedupe_key`),\n  UNIQUE KEY `notifications_legacy_id_unique` (`legacy_id`),\n  KEY `notifications_actor_id_foreign` (`actor_id`),\n  KEY `notifications_recipient_id_read_at_created_at_index` (`recipient_id`,`read_at`,`created_at`),\n  KEY `notifications_recipient_id_category_created_at_index` (`recipient_id`,`category`,`created_at`),\n  CONSTRAINT `notifications_actor_id_foreign` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `notifications_recipient_id_foreign` FOREIGN KEY (`recipient_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,\n  CONSTRAINT `notifications_category_check` CHECK (`category` in ('ATTENDANCE','REPORTS','ORDERS','SYSTEM')),\n  CONSTRAINT `notifications_type_check` CHECK (`type` in ('LEAVE_REQUESTED','LEAVE_APPROVED','LEAVE_REJECTED','DAILY_REPORT_SUBMITTED','ORDER_CREATED','ORDER_ACCEPTED','ORDER_CANCELLED','ORDER_STATUS_CHANGED','LATE_ARRIVAL','WEEKLY_REPORT_CLOSED','WEEKLY_EMAIL_FAILED'))\n) ENGINE=InnoDB AUTO_INCREMENT=691 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "order_capability_grants": {
      "ddl": "CREATE TABLE `order_capability_grants` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `capability` varchar(16) NOT NULL,\n  `role` varchar(8) DEFAULT NULL,\n  `user_id` bigint(20) unsigned DEFAULT NULL,\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `grant_key` varchar(60) GENERATED ALWAYS AS (concat(`capability`,':',coalesce(`role`,''),':',coalesce(`user_id`,''))) VIRTUAL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `order_capability_grants_grant_key_unique` (`grant_key`),\n  KEY `order_capability_grants_user_id_foreign` (`user_id`),\n  KEY `order_capability_grants_created_by_id_foreign` (`created_by_id`),\n  KEY `order_capability_grants_capability_index` (`capability`),\n  CONSTRAINT `order_capability_grants_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `order_capability_grants_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,\n  CONSTRAINT `grants_capability_check` CHECK (`capability` in ('accept_order','cancel_order')),\n  CONSTRAINT `grants_target_check` CHECK (`role` is not null and `role` = 'admin' and `user_id` is null or `role` is null and `user_id` is not null)\n) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "order_counters": {
      "ddl": "CREATE TABLE `order_counters` (\n  `year` smallint(5) unsigned NOT NULL,\n  `last_value` int(10) unsigned NOT NULL DEFAULT 0,\n  PRIMARY KEY (`year`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "phase02_migration_archives": {
      "ddl": "CREATE TABLE `phase02_migration_archives` (\n  `name` varchar(255) NOT NULL,\n  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`payload`)),\n  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),\n  PRIMARY KEY (`name`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "report_attachments": {
      "ddl": "CREATE TABLE `report_attachments` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `report_id` bigint(20) unsigned NOT NULL,\n  `storage_key` varchar(120) NOT NULL,\n  `original_name` varchar(120) NOT NULL,\n  `mime_type` varchar(60) NOT NULL,\n  `size_bytes` int(10) unsigned NOT NULL,\n  `sha256` char(64) NOT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `report_attachments_storage_key_unique` (`storage_key`),\n  KEY `report_attachments_report_id_index` (`report_id`),\n  CONSTRAINT `report_attachments_report_id_foreign` FOREIGN KEY (`report_id`) REFERENCES `daily_work_reports` (`id`),\n  CONSTRAINT `report_attachments_mime_check` CHECK (`mime_type` in ('image/jpeg','image/png','image/webp','application/pdf'))\n) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "report_email_deliveries": {
      "ddl": "CREATE TABLE `report_email_deliveries` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `weekly_report_id` bigint(20) unsigned NOT NULL,\n  `snapshot_id` bigint(20) unsigned NOT NULL,\n  `recipient_email` varchar(255) DEFAULT NULL,\n  `status` varchar(16) NOT NULL,\n  `attempts` smallint(5) unsigned NOT NULL DEFAULT 0,\n  `last_error` text DEFAULT NULL,\n  `message_id` varchar(255) DEFAULT NULL,\n  `last_attempt_at` datetime(3) DEFAULT NULL,\n  `sent_at` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `report_email_deliveries_weekly_report_id_unique` (`weekly_report_id`),\n  KEY `report_email_deliveries_snapshot_id_foreign` (`snapshot_id`),\n  KEY `report_email_deliveries_status_index` (`status`),\n  CONSTRAINT `report_email_deliveries_snapshot_id_foreign` FOREIGN KEY (`snapshot_id`) REFERENCES `weekly_report_snapshots` (`id`),\n  CONSTRAINT `report_email_deliveries_weekly_report_id_foreign` FOREIGN KEY (`weekly_report_id`) REFERENCES `weekly_team_reports` (`id`),\n  CONSTRAINT `deliveries_status_check` CHECK (`status` in ('not_configured','pending','sending','sent','failed'))\n) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "sessions": {
      "ddl": "CREATE TABLE `sessions` (\n  `id` varchar(255) NOT NULL,\n  `user_id` bigint(20) unsigned DEFAULT NULL,\n  `ip_address` varchar(45) DEFAULT NULL,\n  `user_agent` text DEFAULT NULL,\n  `payload` longtext NOT NULL,\n  `last_activity` int(11) NOT NULL,\n  PRIMARY KEY (`id`),\n  KEY `sessions_user_id_index` (`user_id`),\n  KEY `sessions_last_activity_index` (`last_activity`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_absence_types": {
      "ddl": "CREATE TABLE `smgv_absence_types` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `code` varchar(8) NOT NULL,\n  `label_de` varchar(120) NOT NULL,\n  `label_sq` varchar(120) NOT NULL,\n  `gav_article` varchar(40) DEFAULT NULL,\n  `kind` varchar(16) NOT NULL,\n  `counts_towards_total` tinyint(1) NOT NULL DEFAULT 1,\n  `sort` smallint(5) unsigned NOT NULL,\n  `active` tinyint(1) NOT NULL DEFAULT 1,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_absence_types_code_unique` (`code`),\n  CONSTRAINT `smgv_absence_types_kind_check` CHECK (`kind` in ('vacation','compensation','absence','unpaid'))\n) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_absences": {
      "ddl": "CREATE TABLE `smgv_absences` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `date` date NOT NULL,\n  `absence_type_id` bigint(20) unsigned NOT NULL,\n  `minutes` smallint(5) unsigned NOT NULL,\n  `note` varchar(300) DEFAULT NULL,\n  `source` varchar(16) NOT NULL DEFAULT 'manual',\n  `leave_request_id` bigint(20) unsigned DEFAULT NULL,\n  `import_batch_id` bigint(20) unsigned DEFAULT NULL,\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_absences_user_id_date_absence_type_id_unique` (`user_id`,`date`,`absence_type_id`),\n  KEY `smgv_absences_absence_type_id_foreign` (`absence_type_id`),\n  KEY `smgv_absences_leave_request_id_foreign` (`leave_request_id`),\n  KEY `smgv_absences_created_by_id_foreign` (`created_by_id`),\n  KEY `smgv_absences_user_id_date_index` (`user_id`,`date`),\n  CONSTRAINT `smgv_absences_absence_type_id_foreign` FOREIGN KEY (`absence_type_id`) REFERENCES `smgv_absence_types` (`id`),\n  CONSTRAINT `smgv_absences_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_absences_leave_request_id_foreign` FOREIGN KEY (`leave_request_id`) REFERENCES `leave_requests` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_absences_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_absences_minutes_check` CHECK (`minutes` between 1 and 1440),\n  CONSTRAINT `smgv_absences_source_check` CHECK (`source` in ('manual','leave','import'))\n) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_contracts": {
      "ddl": "CREATE TABLE `smgv_contracts` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `entry_date` date NOT NULL,\n  `exit_date` date DEFAULT NULL,\n  `daily_target_minutes` smallint(5) unsigned NOT NULL DEFAULT 480,\n  `vacation_auto` tinyint(1) NOT NULL DEFAULT 1,\n  `note` varchar(500) DEFAULT NULL,\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_contracts_user_id_entry_date_unique` (`user_id`,`entry_date`),\n  KEY `smgv_contracts_created_by_id_foreign` (`created_by_id`),\n  KEY `smgv_contracts_user_id_exit_date_index` (`user_id`,`exit_date`),\n  CONSTRAINT `smgv_contracts_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_contracts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_contracts_dates_check` CHECK (`exit_date` is null or `exit_date` >= `entry_date`),\n  CONSTRAINT `smgv_contracts_target_check` CHECK (`daily_target_minutes` between 1 and 1440)\n) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_corrections": {
      "ddl": "CREATE TABLE `smgv_corrections` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `date` date NOT NULL,\n  `category` varchar(32) NOT NULL,\n  `original_minutes` int(11) DEFAULT NULL,\n  `corrected_minutes` int(11) NOT NULL,\n  `reason` varchar(500) NOT NULL,\n  `created_by_id` bigint(20) unsigned NOT NULL,\n  `created_at` datetime(3) NOT NULL,\n  PRIMARY KEY (`id`),\n  KEY `smgv_corrections_created_by_id_foreign` (`created_by_id`),\n  KEY `smgv_corrections_user_id_date_index` (`user_id`,`date`),\n  CONSTRAINT `smgv_corrections_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_corrections_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_corrections_category_check` CHECK (`category` in ('day_total','travel','karenz','exclude_day','paid_prev_saldo','paid_overtime','vacation_adjust')),\n  CONSTRAINT `smgv_corrections_reason_check` CHECK (char_length(`reason`) >= 3)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_employee_profiles": {
      "ddl": "CREATE TABLE `smgv_employee_profiles` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `street` varchar(160) DEFAULT NULL,\n  `postal_code` varchar(16) DEFAULT NULL,\n  `city` varchar(120) DEFAULT NULL,\n  `ahv_number_encrypted` text DEFAULT NULL,\n  `birth_date` date DEFAULT NULL,\n  `updated_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_employee_profiles_user_id_unique` (`user_id`),\n  KEY `smgv_employee_profiles_updated_by_id_foreign` (`updated_by_id`),\n  CONSTRAINT `smgv_employee_profiles_updated_by_id_foreign` FOREIGN KEY (`updated_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_employee_profiles_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_employment_periods": {
      "ddl": "CREATE TABLE `smgv_employment_periods` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `valid_from` date NOT NULL,\n  `valid_to` date DEFAULT NULL,\n  `mo_bp` smallint(5) unsigned NOT NULL DEFAULT 10000,\n  `di_bp` smallint(5) unsigned NOT NULL DEFAULT 10000,\n  `mi_bp` smallint(5) unsigned NOT NULL DEFAULT 10000,\n  `do_bp` smallint(5) unsigned NOT NULL DEFAULT 10000,\n  `fr_bp` smallint(5) unsigned NOT NULL DEFAULT 10000,\n  `sa_bp` smallint(5) unsigned NOT NULL DEFAULT 0,\n  `so_bp` smallint(5) unsigned NOT NULL DEFAULT 0,\n  `reason` varchar(300) DEFAULT NULL,\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_employment_periods_user_id_valid_from_unique` (`user_id`,`valid_from`),\n  KEY `smgv_employment_periods_created_by_id_foreign` (`created_by_id`),\n  CONSTRAINT `smgv_employment_periods_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_employment_periods_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_employment_periods_dates_check` CHECK (`valid_to` is null or `valid_to` >= `valid_from`),\n  CONSTRAINT `smgv_employment_periods_bp_check` CHECK (`mo_bp` <= 10000 and `di_bp` <= 10000 and `mi_bp` <= 10000 and `do_bp` <= 10000 and `fr_bp` <= 10000 and `sa_bp` <= 10000 and `so_bp` <= 10000)\n) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_exports": {
      "ddl": "CREATE TABLE `smgv_exports` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `requested_by_id` bigint(20) unsigned NOT NULL,\n  `kind` varchar(32) NOT NULL,\n  `year` smallint(5) unsigned NOT NULL,\n  `options` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`options`)),\n  `status` varchar(16) NOT NULL DEFAULT 'running',\n  `file_path` varchar(255) DEFAULT NULL,\n  `file_sha256` char(64) DEFAULT NULL,\n  `pages` int(10) unsigned DEFAULT NULL,\n  `bytes` int(10) unsigned DEFAULT NULL,\n  `error` varchar(64) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `completed_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `smgv_exports_requested_by_id_created_at_index` (`requested_by_id`,`created_at`),\n  CONSTRAINT `smgv_exports_requested_by_id_foreign` FOREIGN KEY (`requested_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_exports_status_check` CHECK (`status` in ('running','done','failed'))\n) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_historical_values": {
      "ddl": "CREATE TABLE `smgv_historical_values` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `import_batch_id` bigint(20) unsigned NOT NULL,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `scope` varchar(8) NOT NULL,\n  `period` varchar(16) NOT NULL,\n  `date` date DEFAULT NULL,\n  `year` smallint(5) unsigned NOT NULL,\n  `month` tinyint(3) unsigned DEFAULT NULL,\n  `metric` varchar(32) NOT NULL,\n  `value_e4` bigint(20) DEFAULT NULL,\n  `original` varchar(120) NOT NULL,\n  `source_page` smallint(5) unsigned NOT NULL,\n  `validation_status` varchar(16) NOT NULL DEFAULT 'valid',\n  `imported_at` datetime(3) NOT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_hist_values_unique` (`import_batch_id`,`user_id`,`scope`,`period`,`metric`),\n  KEY `smgv_hist_values_user_date` (`user_id`,`scope`,`date`),\n  KEY `smgv_hist_values_user_month` (`user_id`,`year`,`month`),\n  CONSTRAINT `smgv_historical_values_import_batch_id_foreign` FOREIGN KEY (`import_batch_id`) REFERENCES `smgv_import_batches` (`id`),\n  CONSTRAINT `smgv_historical_values_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_hist_values_scope_check` CHECK (`scope` in ('basis','day','week','month','year')),\n  CONSTRAINT `smgv_hist_values_status_check` CHECK (`validation_status` in ('valid','discrepancy','info'))\n) ENGINE=InnoDB AUTO_INCREMENT=577 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_holiday_calendars": {
      "ddl": "CREATE TABLE `smgv_holiday_calendars` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `name` varchar(120) NOT NULL,\n  `region` varchar(60) DEFAULT NULL,\n  `is_default` tinyint(1) NOT NULL DEFAULT 0,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_holiday_calendars_name_unique` (`name`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_holidays": {
      "ddl": "CREATE TABLE `smgv_holidays` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `calendar_id` bigint(20) unsigned NOT NULL,\n  `date` date NOT NULL,\n  `name` varchar(120) DEFAULT NULL,\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_holidays_calendar_id_date_unique` (`calendar_id`,`date`),\n  KEY `smgv_holidays_created_by_id_foreign` (`created_by_id`),\n  CONSTRAINT `smgv_holidays_calendar_id_foreign` FOREIGN KEY (`calendar_id`) REFERENCES `smgv_holiday_calendars` (`id`),\n  CONSTRAINT `smgv_holidays_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL\n) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_import_batches": {
      "ddl": "CREATE TABLE `smgv_import_batches` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `uploaded_by_id` bigint(20) unsigned NOT NULL,\n  `original_name` varchar(200) NOT NULL,\n  `stored_path` varchar(255) NOT NULL,\n  `sha256` char(64) NOT NULL,\n  `pages` int(10) unsigned NOT NULL DEFAULT 0,\n  `status` varchar(16) NOT NULL DEFAULT 'uploaded',\n  `kind` varchar(24) NOT NULL DEFAULT 'opening_values',\n  `source_type` varchar(40) DEFAULT NULL,\n  `year` smallint(5) unsigned DEFAULT NULL,\n  `employees` smallint(5) unsigned DEFAULT NULL,\n  `extracted` longtext DEFAULT NULL,\n  `mapping` longtext DEFAULT NULL,\n  `stats` longtext DEFAULT NULL,\n  `reconciliation` longtext DEFAULT NULL,\n  `confirmed_by_id` bigint(20) unsigned DEFAULT NULL,\n  `confirmed_at` datetime(3) DEFAULT NULL,\n  `committed_by_id` bigint(20) unsigned DEFAULT NULL,\n  `committed_at` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_import_batches_sha256_unique` (`sha256`),\n  KEY `smgv_import_batches_uploaded_by_id_foreign` (`uploaded_by_id`),\n  KEY `smgv_import_batches_confirmed_by_id_foreign` (`confirmed_by_id`),\n  KEY `smgv_import_batches_committed_by_id_foreign` (`committed_by_id`),\n  CONSTRAINT `smgv_import_batches_committed_by_id_foreign` FOREIGN KEY (`committed_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_import_batches_confirmed_by_id_foreign` FOREIGN KEY (`confirmed_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_import_batches_uploaded_by_id_foreign` FOREIGN KEY (`uploaded_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_import_batches_status_check` CHECK (`status` in ('uploaded','parsed','confirmed','rejected'))\n) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_month_closings": {
      "ddl": "CREATE TABLE `smgv_month_closings` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `year` smallint(5) unsigned NOT NULL,\n  `month` tinyint(3) unsigned NOT NULL,\n  `revision` smallint(5) unsigned NOT NULL,\n  `rule_set_id` bigint(20) unsigned NOT NULL,\n  `rules_verified` tinyint(1) NOT NULL,\n  `payload` longtext NOT NULL,\n  `checksum` char(64) NOT NULL,\n  `closed_by_id` bigint(20) unsigned NOT NULL,\n  `closed_at` datetime(3) NOT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_month_closings_user_id_year_month_revision_unique` (`user_id`,`year`,`month`,`revision`),\n  KEY `smgv_month_closings_rule_set_id_foreign` (`rule_set_id`),\n  KEY `smgv_month_closings_closed_by_id_foreign` (`closed_by_id`),\n  CONSTRAINT `smgv_month_closings_closed_by_id_foreign` FOREIGN KEY (`closed_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_month_closings_rule_set_id_foreign` FOREIGN KEY (`rule_set_id`) REFERENCES `smgv_rule_sets` (`id`),\n  CONSTRAINT `smgv_month_closings_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_month_reopenings": {
      "ddl": "CREATE TABLE `smgv_month_reopenings` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `year` smallint(5) unsigned NOT NULL,\n  `month` tinyint(3) unsigned NOT NULL,\n  `from_revision` smallint(5) unsigned NOT NULL,\n  `reason` varchar(500) NOT NULL,\n  `reopened_by_id` bigint(20) unsigned NOT NULL,\n  `reopened_at` datetime(3) NOT NULL,\n  PRIMARY KEY (`id`),\n  KEY `smgv_month_reopenings_reopened_by_id_foreign` (`reopened_by_id`),\n  KEY `smgv_month_reopenings_user_id_year_month_index` (`user_id`,`year`,`month`),\n  CONSTRAINT `smgv_month_reopenings_reopened_by_id_foreign` FOREIGN KEY (`reopened_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_month_reopenings_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_month_reopenings_reason_check` CHECK (char_length(`reason`) >= 10)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_month_states": {
      "ddl": "CREATE TABLE `smgv_month_states` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `year` smallint(5) unsigned NOT NULL,\n  `month` tinyint(3) unsigned NOT NULL,\n  `status` varchar(16) NOT NULL DEFAULT 'draft',\n  `revision` smallint(5) unsigned NOT NULL DEFAULT 0,\n  `remark` text DEFAULT NULL,\n  `updated_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_month_states_user_id_year_month_unique` (`user_id`,`year`,`month`),\n  KEY `smgv_month_states_updated_by_id_foreign` (`updated_by_id`),\n  CONSTRAINT `smgv_month_states_updated_by_id_foreign` FOREIGN KEY (`updated_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_month_states_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_month_states_status_check` CHECK (`status` in ('draft','review','ready','closed','reopened')),\n  CONSTRAINT `smgv_month_states_month_check` CHECK (`month` between 1 and 12)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_opening_balances": {
      "ddl": "CREATE TABLE `smgv_opening_balances` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `year` smallint(5) unsigned NOT NULL,\n  `saldo_minutes` int(11) DEFAULT NULL,\n  `vacation_minutes` int(11) DEFAULT NULL,\n  `source` varchar(16) NOT NULL DEFAULT 'manual',\n  `import_batch_id` bigint(20) unsigned DEFAULT NULL,\n  `note` varchar(300) DEFAULT NULL,\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_opening_balances_user_id_year_unique` (`user_id`,`year`),\n  KEY `smgv_opening_balances_created_by_id_foreign` (`created_by_id`),\n  CONSTRAINT `smgv_opening_balances_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_opening_balances_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `smgv_opening_balances_source_check` CHECK (`source` in ('manual','import'))\n) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "smgv_rule_sets": {
      "ddl": "CREATE TABLE `smgv_rule_sets` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `version` varchar(40) NOT NULL,\n  `valid_from` date NOT NULL,\n  `valid_to` date DEFAULT NULL,\n  `status` varchar(16) NOT NULL DEFAULT 'unverified',\n  `rules` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`rules`)),\n  `notes` text DEFAULT NULL,\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `verified_by_id` bigint(20) unsigned DEFAULT NULL,\n  `verified_at` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `smgv_rule_sets_version_unique` (`version`),\n  KEY `smgv_rule_sets_created_by_id_foreign` (`created_by_id`),\n  KEY `smgv_rule_sets_verified_by_id_foreign` (`verified_by_id`),\n  CONSTRAINT `smgv_rule_sets_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_rule_sets_verified_by_id_foreign` FOREIGN KEY (`verified_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `smgv_rule_sets_status_check` CHECK (`status` in ('unverified','verified','retired'))\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "users": {
      "ddl": "CREATE TABLE `users` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `name` varchar(255) NOT NULL,\n  `email` varchar(255) DEFAULT NULL,\n  `password` varchar(255) NOT NULL,\n  `role` varchar(16) NOT NULL,\n  `locale` varchar(2) NOT NULL DEFAULT 'sq',\n  `status` varchar(16) NOT NULL DEFAULT 'active',\n  `phone` varchar(40) DEFAULT NULL,\n  `foreman_id` bigint(20) unsigned DEFAULT NULL,\n  `must_change_password` tinyint(1) NOT NULL DEFAULT 0,\n  `password_changed_at` datetime(3) DEFAULT NULL,\n  `last_login_at` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  `username` varchar(40) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `users_email_unique` (`email`),\n  UNIQUE KEY `users_legacy_id_unique` (`legacy_id`),\n  UNIQUE KEY `users_username_unique` (`username`),\n  KEY `users_foreman_id_foreign` (`foreman_id`),\n  KEY `users_role_index` (`role`),\n  KEY `users_status_role_index` (`status`,`role`),\n  CONSTRAINT `users_foreman_id_foreign` FOREIGN KEY (`foreman_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `users_locale_check` CHECK (`locale` in ('sq','de')),\n  CONSTRAINT `users_status_check` CHECK (`status` in ('active','suspended','archived')),\n  CONSTRAINT `users_role_check` CHECK (`role` in ('admin','worker'))\n) ENGINE=InnoDB AUTO_INCREMENT=947 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "weekly_report_snapshots": {
      "ddl": "CREATE TABLE `weekly_report_snapshots` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `weekly_report_id` bigint(20) unsigned NOT NULL,\n  `version` smallint(5) unsigned NOT NULL,\n  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`payload`)),\n  `content_hash` char(64) NOT NULL,\n  `created_by_id` bigint(20) unsigned DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `weekly_report_snapshots_weekly_report_id_version_unique` (`weekly_report_id`,`version`),\n  KEY `weekly_report_snapshots_created_by_id_foreign` (`created_by_id`),\n  CONSTRAINT `weekly_report_snapshots_created_by_id_foreign` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,\n  CONSTRAINT `weekly_report_snapshots_weekly_report_id_foreign` FOREIGN KEY (`weekly_report_id`) REFERENCES `weekly_team_reports` (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "weekly_team_reports": {
      "ddl": "CREATE TABLE `weekly_team_reports` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `foreman_id` bigint(20) unsigned DEFAULT NULL,\n  `week_start` date NOT NULL,\n  `status` varchar(8) NOT NULL DEFAULT 'draft',\n  `summary_completed` text DEFAULT NULL,\n  `summary_unfinished` text DEFAULT NULL,\n  `important_notes` text DEFAULT NULL,\n  `foreman_comments` text DEFAULT NULL,\n  `closed_at` datetime(3) DEFAULT NULL,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  `prepared_by_id` bigint(20) unsigned DEFAULT NULL,\n  `company_week` date DEFAULT NULL,\n  `administrator_comments` text DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `weekly_team_reports_foreman_id_week_start_unique` (`foreman_id`,`week_start`),\n  UNIQUE KEY `weekly_team_reports_legacy_id_unique` (`legacy_id`),\n  UNIQUE KEY `weekly_team_reports_company_week_unique` (`company_week`),\n  KEY `weekly_team_reports_week_start_status_index` (`week_start`,`status`),\n  KEY `weekly_team_reports_prepared_by_id_foreign` (`prepared_by_id`),\n  CONSTRAINT `weekly_team_reports_foreman_id_foreign` FOREIGN KEY (`foreman_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `weekly_team_reports_prepared_by_id_foreign` FOREIGN KEY (`prepared_by_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `weekly_reports_status_check` CHECK (`status` in ('draft','closed')),\n  CONSTRAINT `weekly_reports_closed_check` CHECK (`status` = 'closed' = (`closed_at` is not null)),\n  CONSTRAINT `weekly_company_identity_check` CHECK (`foreman_id` is not null and `company_week` is null or `foreman_id` is null and `company_week` is not null and `company_week` = `week_start` and `prepared_by_id` is not null)\n) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "worker_schedules": {
      "ddl": "CREATE TABLE `worker_schedules` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `legacy_id` varchar(40) DEFAULT NULL,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `weekday` tinyint(3) unsigned NOT NULL,\n  `start_time` char(5) NOT NULL,\n  `end_time` char(5) NOT NULL,\n  `valid_from` date NOT NULL,\n  `valid_to` date DEFAULT NULL,\n  `active` tinyint(1) NOT NULL DEFAULT 1,\n  `planned_break_minutes` smallint(5) unsigned NOT NULL DEFAULT 0,\n  `created_at` datetime(3) DEFAULT NULL,\n  `updated_at` datetime(3) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `worker_schedules_legacy_id_unique` (`legacy_id`),\n  KEY `worker_schedules_user_id_weekday_active_index` (`user_id`,`weekday`,`active`),\n  CONSTRAINT `worker_schedules_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `worker_schedules_weekday_check` CHECK (`weekday` between 1 and 7),\n  CONSTRAINT `worker_schedules_time_check` CHECK (`start_time` regexp '^([01][0-9]|2[0-3]):[0-5][0-9]$' and `end_time` regexp '^([01][0-9]|2[0-3]):[0-5][0-9]$' and `start_time` <> `end_time`),\n  CONSTRAINT `worker_schedules_dates_check` CHECK (`valid_to` is null or `valid_to` >= `valid_from`),\n  CONSTRAINT `worker_schedules_break_check` CHECK (`planned_break_minutes` between 0 and 240)\n) ENGINE=InnoDB AUTO_INCREMENT=54 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "worksite_user": {
      "ddl": "CREATE TABLE `worksite_user` (\n  `worksite_id` bigint(20) unsigned NOT NULL,\n  `user_id` bigint(20) unsigned NOT NULL,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`worksite_id`,`user_id`),\n  KEY `worksite_user_user_id_worksite_id_index` (`user_id`,`worksite_id`),\n  CONSTRAINT `worksite_user_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `worksite_user_worksite_id_foreign` FOREIGN KEY (`worksite_id`) REFERENCES `worksites` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    },
    "worksites": {
      "ddl": "CREATE TABLE `worksites` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `name` varchar(160) NOT NULL,\n  `address` varchar(255) NOT NULL,\n  `city` varchar(80) NOT NULL,\n  `postal_code` varchar(20) DEFAULT NULL,\n  `code` varchar(40) DEFAULT NULL,\n  `description` text DEFAULT NULL,\n  `foreman_id` bigint(20) unsigned DEFAULT NULL,\n  `created_by` bigint(20) unsigned DEFAULT NULL,\n  `updated_by` bigint(20) unsigned DEFAULT NULL,\n  `latitude` decimal(10,7) DEFAULT NULL,\n  `longitude` decimal(10,7) DEFAULT NULL,\n  `radius_meters` smallint(5) unsigned NOT NULL DEFAULT 100,\n  `active` tinyint(1) NOT NULL DEFAULT 1,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `worksites_code_unique` (`code`),\n  KEY `worksites_created_by_foreign` (`created_by`),\n  KEY `worksites_updated_by_foreign` (`updated_by`),\n  KEY `worksites_active_name_index` (`active`,`name`),\n  KEY `worksites_foreman_id_active_index` (`foreman_id`,`active`),\n  CONSTRAINT `worksites_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),\n  CONSTRAINT `worksites_foreman_id_foreign` FOREIGN KEY (`foreman_id`) REFERENCES `users` (`id`),\n  CONSTRAINT `worksites_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),\n  CONSTRAINT `worksites_coordinates_check` CHECK (`latitude` is null and `longitude` is null or `latitude` is not null and `longitude` is not null and `latitude` between -90 and 90 and `longitude` between -180 and 180),\n  CONSTRAINT `worksites_radius_check` CHECK (`radius_meters` between 10 and 5000)\n) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    }
  },
  "triggers": [
    {
      "TRIGGER_NAME": "attendance_events_no_delete",
      "EVENT_OBJECT_TABLE": "attendance_events",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'attendance_events are immutable'"
    },
    {
      "TRIGGER_NAME": "attendance_events_no_update",
      "EVENT_OBJECT_TABLE": "attendance_events",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'attendance_events are immutable'"
    },
    {
      "TRIGGER_NAME": "attendance_locations_no_update",
      "EVENT_OBJECT_TABLE": "attendance_locations",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'attendance_locations cannot be updated'"
    },
    {
      "TRIGGER_NAME": "audit_logs_no_delete",
      "EVENT_OBJECT_TABLE": "audit_logs",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'audit_logs are append-only'"
    },
    {
      "TRIGGER_NAME": "audit_logs_no_update",
      "EVENT_OBJECT_TABLE": "audit_logs",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'audit_logs are append-only'"
    },
    {
      "TRIGGER_NAME": "daily_work_reports_frozen_delete",
      "EVENT_OBJECT_TABLE": "daily_work_reports",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN IF OLD.status = 'submitted' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted daily report is final and cannot be changed'; END IF; END"
    },
    {
      "TRIGGER_NAME": "daily_work_reports_frozen_update",
      "EVENT_OBJECT_TABLE": "daily_work_reports",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN IF OLD.status = 'submitted' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted daily report is final and cannot be changed'; END IF; END"
    },
    {
      "TRIGGER_NAME": "daily_work_report_items_frozen_delete",
      "EVENT_OBJECT_TABLE": "daily_work_report_items",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN\n                DECLARE parent_status VARCHAR(12);\n                SELECT status INTO parent_status FROM daily_work_reports WHERE id = OLD.report_id;\n                IF parent_status = 'submitted' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted daily report is final and cannot be changed'; END IF;\n            END"
    },
    {
      "TRIGGER_NAME": "daily_work_report_items_frozen_insert",
      "EVENT_OBJECT_TABLE": "daily_work_report_items",
      "EVENT_MANIPULATION": "INSERT",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN\n                DECLARE parent_status VARCHAR(12);\n                SELECT status INTO parent_status FROM daily_work_reports WHERE id = NEW.report_id;\n                IF parent_status = 'submitted' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted daily report is final and cannot be changed'; END IF;\n            END"
    },
    {
      "TRIGGER_NAME": "daily_work_report_items_frozen_update",
      "EVENT_OBJECT_TABLE": "daily_work_report_items",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN\n                DECLARE parent_status VARCHAR(12);\n                SELECT status INTO parent_status FROM daily_work_reports WHERE id = OLD.report_id;\n                IF parent_status = 'submitted' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted daily report is final and cannot be changed'; END IF;\n            END"
    },
    {
      "TRIGGER_NAME": "delivery_policies_no_delete",
      "EVENT_OBJECT_TABLE": "delivery_policies",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'delivery_policies rows are immutable'"
    },
    {
      "TRIGGER_NAME": "delivery_policies_no_update",
      "EVENT_OBJECT_TABLE": "delivery_policies",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'delivery_policies rows are immutable'"
    },
    {
      "TRIGGER_NAME": "material_orders_guard_update",
      "EVENT_OBJECT_TABLE": "material_orders",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN\n                    IF NOT (NEW.reference <=> OLD.reference) OR NOT (NEW.requested_by <=> OLD.requested_by) OR NOT (NEW.submitted_at <=> OLD.submitted_at)\n                       OR NOT (NEW.expected_delivery_date <=> OLD.expected_delivery_date) OR NOT (NEW.delivery_policy_version <=> OLD.delivery_policy_version)\n                       OR NOT (NEW.notes <=> OLD.notes) OR NOT (NEW.worksite_name <=> OLD.worksite_name) OR NOT (NEW.idempotency_key <=> OLD.idempotency_key) THEN\n                        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted material order cannot be edited; only its status changes';\n                    END IF;\n                END"
    },
    {
      "TRIGGER_NAME": "material_orders_no_delete",
      "EVENT_OBJECT_TABLE": "material_orders",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Material orders are never deleted'"
    },
    {
      "TRIGGER_NAME": "material_order_items_no_delete",
      "EVENT_OBJECT_TABLE": "material_order_items",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'material_order_items rows are immutable'"
    },
    {
      "TRIGGER_NAME": "material_order_items_no_update",
      "EVENT_OBJECT_TABLE": "material_order_items",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'material_order_items rows are immutable'"
    },
    {
      "TRIGGER_NAME": "material_order_status_history_no_delete",
      "EVENT_OBJECT_TABLE": "material_order_status_history",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'material_order_status_history rows are immutable'"
    },
    {
      "TRIGGER_NAME": "material_order_status_history_no_update",
      "EVENT_OBJECT_TABLE": "material_order_status_history",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'material_order_status_history rows are immutable'"
    },
    {
      "TRIGGER_NAME": "notifications_guard_update",
      "EVENT_OBJECT_TABLE": "notifications",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN\n                    IF NOT (NEW.recipient_id <=> OLD.recipient_id) OR NOT (NEW.type <=> OLD.type) OR NOT (NEW.category <=> OLD.category)\n                       OR NOT (NEW.actor_id <=> OLD.actor_id) OR NOT (NEW.entity_type <=> OLD.entity_type) OR NOT (NEW.entity_id <=> OLD.entity_id)\n                       OR NOT (NEW.dedupe_key <=> OLD.dedupe_key) OR NOT (NEW.created_at <=> OLD.created_at) THEN\n                        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A notification cannot be edited; only its read state changes';\n                    END IF;\n                END"
    },
    {
      "TRIGGER_NAME": "report_attachments_frozen_delete",
      "EVENT_OBJECT_TABLE": "report_attachments",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN\n                DECLARE parent_status VARCHAR(12);\n                SELECT status INTO parent_status FROM daily_work_reports WHERE id = OLD.report_id;\n                IF parent_status = 'submitted' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted daily report is final and cannot be changed'; END IF;\n            END"
    },
    {
      "TRIGGER_NAME": "report_attachments_frozen_insert",
      "EVENT_OBJECT_TABLE": "report_attachments",
      "EVENT_MANIPULATION": "INSERT",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN\n                DECLARE parent_status VARCHAR(12);\n                SELECT status INTO parent_status FROM daily_work_reports WHERE id = NEW.report_id;\n                IF parent_status = 'submitted' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted daily report is final and cannot be changed'; END IF;\n            END"
    },
    {
      "TRIGGER_NAME": "report_attachments_frozen_update",
      "EVENT_OBJECT_TABLE": "report_attachments",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN\n                DECLARE parent_status VARCHAR(12);\n                SELECT status INTO parent_status FROM daily_work_reports WHERE id = OLD.report_id;\n                IF parent_status = 'submitted' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A submitted daily report is final and cannot be changed'; END IF;\n            END"
    },
    {
      "TRIGGER_NAME": "smgv_corrections_no_delete",
      "EVENT_OBJECT_TABLE": "smgv_corrections",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'smgv_corrections are append-only'"
    },
    {
      "TRIGGER_NAME": "smgv_corrections_no_update",
      "EVENT_OBJECT_TABLE": "smgv_corrections",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'smgv_corrections are append-only'"
    },
    {
      "TRIGGER_NAME": "smgv_month_closings_no_delete",
      "EVENT_OBJECT_TABLE": "smgv_month_closings",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'closed SMGV snapshots are immutable'"
    },
    {
      "TRIGGER_NAME": "smgv_month_closings_no_update",
      "EVENT_OBJECT_TABLE": "smgv_month_closings",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'closed SMGV snapshots are immutable'"
    },
    {
      "TRIGGER_NAME": "smgv_month_reopenings_no_delete",
      "EVENT_OBJECT_TABLE": "smgv_month_reopenings",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'SMGV reopenings are append-only'"
    },
    {
      "TRIGGER_NAME": "smgv_month_reopenings_no_update",
      "EVENT_OBJECT_TABLE": "smgv_month_reopenings",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'SMGV reopenings are append-only'"
    },
    {
      "TRIGGER_NAME": "weekly_report_snapshots_no_delete",
      "EVENT_OBJECT_TABLE": "weekly_report_snapshots",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'weekly_report_snapshots rows are immutable'"
    },
    {
      "TRIGGER_NAME": "weekly_report_snapshots_no_update",
      "EVENT_OBJECT_TABLE": "weekly_report_snapshots",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'weekly_report_snapshots rows are immutable'"
    },
    {
      "TRIGGER_NAME": "weekly_team_reports_frozen_delete",
      "EVENT_OBJECT_TABLE": "weekly_team_reports",
      "EVENT_MANIPULATION": "DELETE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN IF OLD.status = 'closed' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A closed weekly report is final and cannot be deleted'; END IF; END"
    },
    {
      "TRIGGER_NAME": "weekly_team_reports_frozen_update",
      "EVENT_OBJECT_TABLE": "weekly_team_reports",
      "EVENT_MANIPULATION": "UPDATE",
      "ACTION_TIMING": "BEFORE",
      "ACTION_STATEMENT": "BEGIN IF OLD.status = 'closed' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A closed weekly report is final and cannot be changed'; END IF; END"
    }
  ]
}