-- Aluminum QR Store cPanel import database
-- Full schema and currently deployed database migration records.
-- Only existing login/roles/permissions, Main Warehouse and label templates are retained.
-- Products, Bundles, Stock In, Stock Out, Returns and stock ledger are deliberately empty.
-- Select the cPanel database in phpMyAdmin before importing this file.
SET FOREIGN_KEY_CHECKS=0;
-- MySQL dump 10.13  Distrib 8.4.9, for Win64 (x86_64)
--
-- Host: 127.0.0.1    Database: aluminum_trial_local
-- ------------------------------------------------------
-- Server version	8.4.9

/*!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 */;
/*!50503 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 `activity_logs`
--

DROP TABLE IF EXISTS `activity_logs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `activity_logs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned DEFAULT NULL,
  `action` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `subject_type` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `subject_id` bigint unsigned DEFAULT NULL,
  `before_state` json DEFAULT NULL,
  `after_state` json DEFAULT NULL,
  `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `activity_logs_subject_type_subject_id_index` (`subject_type`,`subject_id`),
  KEY `activity_logs_user_id_created_at_index` (`user_id`,`created_at`),
  KEY `activity_logs_action_index` (`action`),
  CONSTRAINT `activity_logs_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `approvals`
--

DROP TABLE IF EXISTS `approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `document_type` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `document_id` bigint unsigned NOT NULL,
  `approval_type` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending',
  `submitted_snapshot` json DEFAULT NULL,
  `decision_reason` text COLLATE utf8mb4_unicode_ci,
  `decided_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `approvals_maker_id_foreign` (`maker_id`),
  KEY `approvals_checker_id_foreign` (`checker_id`),
  KEY `approvals_document_type_idx` (`document_type`,`document_id`,`approval_type`),
  KEY `approvals_status_index` (`status`),
  CONSTRAINT `approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `approvals_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `atomic_correction_case_batch_lines`
--

DROP TABLE IF EXISTS `atomic_correction_case_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `atomic_correction_case_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `case_id` bigint unsigned NOT NULL,
  `document_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `document_id` bigint unsigned NOT NULL,
  `adapter` varchar(48) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_id` bigint unsigned NOT NULL,
  `bundle_ids_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_snapshot_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `accbl_batch_case_uq` (`batch_id`,`case_id`),
  UNIQUE KEY `accbl_case_once_uq` (`case_id`),
  CONSTRAINT `atomic_correction_case_batch_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `atomic_correction_case_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `atomic_correction_case_batch_lines_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `atomic_correction_case_batches`
--

DROP TABLE IF EXISTS `atomic_correction_case_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `atomic_correction_case_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` bigint unsigned NOT NULL,
  `case_count` smallint unsigned NOT NULL,
  `case_set_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `accb_case_set_seal_uq` (`case_set_sha256`),
  KEY `atomic_correction_case_batches_warehouse_id_foreign` (`warehouse_id`),
  KEY `atomic_correction_case_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `atomic_correction_case_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `atomic_correction_case_batches_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `bundle_items`
--

DROP TABLE IF EXISTS `bundle_items`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `bundle_items` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `bundle_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `bundle_items_bundle_product_uq` (`bundle_id`,`product_id`),
  KEY `bundle_items_product_bundle_idx` (`product_id`,`bundle_id`),
  CONSTRAINT `bundle_items_bundle_fk` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_items_product_fk` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `bundle_physical_split_batches`
--

DROP TABLE IF EXISTS `bundle_physical_split_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `bundle_physical_split_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `parent_bundle_id` bigint unsigned NOT NULL,
  `operation_id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
  `parent_qr_id` bigint unsigned NOT NULL,
  `source_ledger_id` bigint unsigned NOT NULL,
  `source_balance_id` bigint unsigned NOT NULL,
  `source_balance_version` bigint unsigned NOT NULL,
  `source_location_key` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_bucket` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_quantity_pcs` bigint unsigned NOT NULL,
  `child_count` smallint unsigned NOT NULL,
  `allocation_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `split_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `bundle_physical_parent_split_once_uq` (`parent_bundle_id`),
  UNIQUE KEY `bundle_physical_split_batches_operation_id_unique` (`operation_id`),
  KEY `bundle_physical_split_batches_parent_qr_id_foreign` (`parent_qr_id`),
  KEY `bundle_physical_split_batches_source_ledger_id_foreign` (`source_ledger_id`),
  KEY `bundle_physical_split_batches_source_balance_id_foreign` (`source_balance_id`),
  KEY `bundle_physical_split_batches_split_by_foreign` (`split_by`),
  CONSTRAINT `bundle_physical_split_batches_parent_bundle_id_foreign` FOREIGN KEY (`parent_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_physical_split_batches_parent_qr_id_foreign` FOREIGN KEY (`parent_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_physical_split_batches_source_balance_id_foreign` FOREIGN KEY (`source_balance_id`) REFERENCES `stock_balances` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_physical_split_batches_source_ledger_id_foreign` FOREIGN KEY (`source_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_physical_split_batches_split_by_foreign` FOREIGN KEY (`split_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `bundle_physical_split_lines`
--

DROP TABLE IF EXISTS `bundle_physical_split_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `bundle_physical_split_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `line_no` smallint unsigned NOT NULL,
  `child_bundle_id` bigint unsigned NOT NULL,
  `new_qr_id` bigint unsigned NOT NULL,
  `split_ledger_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `physical_split_line_once_uq` (`batch_id`,`line_no`),
  UNIQUE KEY `physical_split_child_once_uq` (`child_bundle_id`),
  UNIQUE KEY `physical_split_ledger_once_uq` (`split_ledger_id`),
  KEY `bundle_physical_split_lines_new_qr_id_foreign` (`new_qr_id`),
  CONSTRAINT `bundle_physical_split_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `bundle_physical_split_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_physical_split_lines_child_bundle_id_foreign` FOREIGN KEY (`child_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_physical_split_lines_new_qr_id_foreign` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_physical_split_lines_split_ledger_id_foreign` FOREIGN KEY (`split_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `bundle_relations`
--

DROP TABLE IF EXISTS `bundle_relations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `bundle_relations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `parent_bundle_id` bigint unsigned NOT NULL,
  `child_bundle_id` bigint unsigned NOT NULL,
  `relation_type` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'split',
  `quantity_pcs` bigint unsigned NOT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `bundle_rel_parent_child_type_uq` (`parent_bundle_id`,`child_bundle_id`,`relation_type`),
  KEY `bundle_relations_created_by_foreign` (`created_by`),
  KEY `bundle_relations_child_bundle_id_index` (`child_bundle_id`),
  CONSTRAINT `bundle_relations_child_bundle_id_foreign` FOREIGN KEY (`child_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_relations_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundle_relations_parent_bundle_id_foreign` FOREIGN KEY (`parent_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `bundles`
--

DROP TABLE IF EXISTS `bundles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `bundles` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `product_id` bigint unsigned NOT NULL,
  `bundle_code` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `custody_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'not_received',
  `custody_id` bigint unsigned DEFAULT NULL,
  `condition` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'good',
  `status` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `label_state` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending',
  `label_attached_at` timestamp NULL DEFAULT NULL,
  `label_verified_by` bigint unsigned DEFAULT NULL,
  `current_qr_id` bigint unsigned DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `bundles_bundle_code_unique` (`bundle_code`),
  UNIQUE KEY `bundles_current_qr_pointer_uq` (`current_qr_id`),
  KEY `bundles_created_by_foreign` (`created_by`),
  KEY `bundles_product_id_status_index` (`product_id`,`status`),
  KEY `bundles_custody_type_index` (`custody_type`),
  KEY `bundles_condition_index` (`condition`),
  KEY `bundles_status_index` (`status`),
  KEY `bundles_label_state_index` (`label_state`),
  KEY `bundles_label_verified_by_foreign` (`label_verified_by`),
  CONSTRAINT `bundles_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundles_current_qr_id_foreign` FOREIGN KEY (`current_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundles_label_verified_by_foreign` FOREIGN KEY (`label_verified_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `bundles_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `categories`
--

DROP TABLE IF EXISTS `categories`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `categories` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `categories_code_unique` (`code`),
  UNIQUE KEY `categories_name_unique` (`name`),
  KEY `categories_is_active_index` (`is_active`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `composite_cross_custody_batches`
--

DROP TABLE IF EXISTS `composite_cross_custody_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `composite_cross_custody_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` tinyint unsigned NOT NULL DEFAULT '1',
  `received_batch_id` bigint unsigned NOT NULL,
  `dependent_batch_id` bigint unsigned NOT NULL,
  `received_count` tinyint unsigned NOT NULL,
  `case_count` tinyint unsigned NOT NULL,
  `transit_count` tinyint unsigned NOT NULL,
  `manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `child_posting_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `cccb_received_once` (`received_batch_id`),
  UNIQUE KEY `cccb_dependent_once` (`dependent_batch_id`),
  UNIQUE KEY `cccb_manifest_once` (`manifest_sha256`),
  UNIQUE KEY `cccb_child_once` (`child_posting_sha256`),
  KEY `composite_cross_custody_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `composite_cross_custody_batches_dependent_batch_id_foreign` FOREIGN KEY (`dependent_batch_id`) REFERENCES `dependent_cross_custody_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `composite_cross_custody_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `composite_cross_custody_batches_received_batch_id_foreign` FOREIGN KEY (`received_batch_id`) REFERENCES `received_repair_atomic_batches` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `count_exception_dispositions`
--

DROP TABLE IF EXISTS `count_exception_dispositions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `count_exception_dispositions` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `review_id` bigint unsigned NOT NULL,
  `stock_count_id` bigint unsigned NOT NULL,
  `variance_plan_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `resolution_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `retained_counted_pcs` bigint unsigned NOT NULL,
  `previously_missing_counted_pcs` bigint unsigned NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `frozen_identity_snapshot` json NOT NULL,
  `original_count_line_snapshot` json NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `decision_note` text COLLATE utf8mb4_unicode_ci,
  `submitted_at` timestamp NOT NULL,
  `applied_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `count_exception_dispositions_review_id_unique` (`review_id`),
  UNIQUE KEY `count_exception_dispositions_variance_plan_id_unique` (`variance_plan_id`),
  KEY `count_exception_dispositions_maker_id_foreign` (`maker_id`),
  KEY `count_exception_dispositions_checker_id_foreign` (`checker_id`),
  KEY `count_exception_dispositions_stock_count_id_status_index` (`stock_count_id`,`status`),
  KEY `count_exception_dispositions_warehouse_id_status_index` (`warehouse_id`,`status`),
  CONSTRAINT `count_exception_dispositions_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_dispositions_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_dispositions_review_id_foreign` FOREIGN KEY (`review_id`) REFERENCES `count_exception_reviews` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_dispositions_stock_count_id_foreign` FOREIGN KEY (`stock_count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_dispositions_variance_plan_id_foreign` FOREIGN KEY (`variance_plan_id`) REFERENCES `stock_count_variance_plans` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_dispositions_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `count_exception_reviews`
--

DROP TABLE IF EXISTS `count_exception_reviews`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `count_exception_reviews` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_count_id` bigint unsigned NOT NULL,
  `variance_plan_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `decision` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `decision_note` text COLLATE utf8mb4_unicode_ci,
  `frozen_identity_snapshot` json NOT NULL,
  `submitted_at` timestamp NOT NULL,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `count_exception_reviews_variance_plan_id_unique` (`variance_plan_id`),
  KEY `count_exception_reviews_maker_id_foreign` (`maker_id`),
  KEY `count_exception_reviews_checker_id_foreign` (`checker_id`),
  KEY `count_exception_reviews_warehouse_id_status_index` (`warehouse_id`,`status`),
  KEY `count_exception_reviews_stock_count_id_status_index` (`stock_count_id`,`status`),
  CONSTRAINT `count_exception_reviews_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_reviews_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_reviews_stock_count_id_foreign` FOREIGN KEY (`stock_count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_reviews_variance_plan_id_foreign` FOREIGN KEY (`variance_plan_id`) REFERENCES `stock_count_variance_plans` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `count_exception_reviews_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `dependent_cross_custody_batches`
--

DROP TABLE IF EXISTS `dependent_cross_custody_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `dependent_cross_custody_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` tinyint unsigned NOT NULL DEFAULT '1',
  `case_batch_id` bigint unsigned NOT NULL,
  `transit_batch_id` bigint unsigned NOT NULL,
  `case_count` tinyint unsigned NOT NULL,
  `transit_count` tinyint unsigned NOT NULL,
  `total_lost_pcs` bigint unsigned NOT NULL,
  `dependency_manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `child_posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `dccb_correction_once` (`case_batch_id`),
  UNIQUE KEY `dccb_transit_once` (`transit_batch_id`),
  UNIQUE KEY `dccb_request_once` (`request_manifest_sha256`),
  UNIQUE KEY `dccb_proof_once` (`child_posting_proof_sha256`),
  KEY `dependent_cross_custody_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `dependent_cross_custody_batches_case_batch_id_foreign` FOREIGN KEY (`case_batch_id`) REFERENCES `atomic_correction_case_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `dependent_cross_custody_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `dependent_cross_custody_batches_transit_batch_id_foreign` FOREIGN KEY (`transit_batch_id`) REFERENCES `transit_quantity_correction_batches` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `document_correction_authorizations`
--

DROP TABLE IF EXISTS `document_correction_authorizations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `document_correction_authorizations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `authorizer_id` bigint unsigned NOT NULL,
  `decision` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `snapshot_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `decision_reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `decided_at` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `document_correction_authorizations_case_id_unique` (`case_id`),
  KEY `document_correction_authorizations_authorizer_id_foreign` (`authorizer_id`),
  CONSTRAINT `document_correction_authorizations_authorizer_id_foreign` FOREIGN KEY (`authorizer_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_authorizations_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `document_correction_cases`
--

DROP TABLE IF EXISTS `document_correction_cases`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `document_correction_cases` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_no` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `document_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `document_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `document_snapshot` json NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `decision_note` text COLLATE utf8mb4_unicode_ci,
  `decided_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `one_open_correction_case_per_document` (`document_type`,`document_id`),
  UNIQUE KEY `document_correction_cases_case_no_unique` (`case_no`),
  KEY `document_correction_cases_maker_id_foreign` (`maker_id`),
  KEY `document_correction_cases_checker_id_foreign` (`checker_id`),
  KEY `document_correction_cases_warehouse_id_status_index` (`warehouse_id`,`status`),
  CONSTRAINT `document_correction_cases_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_cases_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_cases_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `document_correction_draft_reviews`
--

DROP TABLE IF EXISTS `document_correction_draft_reviews`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `document_correction_draft_reviews` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `draft_id` bigint unsigned NOT NULL,
  `reviewer_id` bigint unsigned NOT NULL,
  `plan_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `decision` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `reviewed_at` timestamp NOT NULL,
  `created_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `document_correction_draft_reviews_case_id_unique` (`case_id`),
  UNIQUE KEY `document_correction_draft_reviews_draft_id_unique` (`draft_id`),
  KEY `document_correction_draft_reviews_reviewer_id_foreign` (`reviewer_id`),
  CONSTRAINT `document_correction_draft_reviews_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_draft_reviews_draft_id_foreign` FOREIGN KEY (`draft_id`) REFERENCES `document_correction_reversal_drafts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_draft_reviews_reviewer_id_foreign` FOREIGN KEY (`reviewer_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `document_correction_execution_approvals`
--

DROP TABLE IF EXISTS `document_correction_execution_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `document_correction_execution_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `draft_id` bigint unsigned NOT NULL,
  `review_id` bigint unsigned NOT NULL,
  `approved_by` bigint unsigned NOT NULL,
  `plan_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_lines` json NOT NULL,
  `decision` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `document_correction_execution_approvals_case_id_unique` (`case_id`),
  KEY `document_correction_execution_approvals_draft_id_foreign` (`draft_id`),
  KEY `document_correction_execution_approvals_review_id_foreign` (`review_id`),
  KEY `document_correction_execution_approvals_approved_by_foreign` (`approved_by`),
  CONSTRAINT `document_correction_execution_approvals_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_execution_approvals_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_execution_approvals_draft_id_foreign` FOREIGN KEY (`draft_id`) REFERENCES `document_correction_reversal_drafts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_execution_approvals_review_id_foreign` FOREIGN KEY (`review_id`) REFERENCES `document_correction_draft_reviews` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `document_correction_execution_batches`
--

DROP TABLE IF EXISTS `document_correction_execution_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `document_correction_execution_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `execution_approval_id` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `plan_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `line_count` int unsigned NOT NULL,
  `total_pcs` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `document_correction_execution_batches_case_id_unique` (`case_id`),
  UNIQUE KEY `dceb_execution_approval_id_uq` (`execution_approval_id`),
  KEY `document_correction_execution_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `document_correction_execution_batches_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_execution_batches_execution_approval_fk` FOREIGN KEY (`execution_approval_id`) REFERENCES `document_correction_execution_approvals` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_execution_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `document_correction_posting_registry`
--

DROP TABLE IF EXISTS `document_correction_posting_registry`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `document_correction_posting_registry` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `posting_family` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `status` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_reference_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `dcp_registry_case_unique` (`case_id`),
  KEY `document_correction_posting_registry_posted_by_foreign` (`posted_by`),
  CONSTRAINT `document_correction_posting_registry_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_posting_registry_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `document_correction_reversal_drafts`
--

DROP TABLE IF EXISTS `document_correction_reversal_drafts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `document_correction_reversal_drafts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `authorization_id` bigint unsigned NOT NULL,
  `prepared_by` bigint unsigned NOT NULL,
  `snapshot_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `plan_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `inverse_lines` json NOT NULL,
  `created_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `document_correction_reversal_drafts_case_id_unique` (`case_id`),
  KEY `document_correction_reversal_drafts_authorization_id_foreign` (`authorization_id`),
  KEY `document_correction_reversal_drafts_prepared_by_foreign` (`prepared_by`),
  CONSTRAINT `document_correction_reversal_drafts_authorization_id_foreign` FOREIGN KEY (`authorization_id`) REFERENCES `document_correction_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_reversal_drafts_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `document_correction_reversal_drafts_prepared_by_foreign` FOREIGN KEY (`prepared_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `employees`
--

DROP TABLE IF EXISTS `employees`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `employees` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `employee_code` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(190) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `employees_employee_code_unique` (`employee_code`),
  UNIQUE KEY `employees_user_id_unique` (`user_id`),
  KEY `employees_is_active_index` (`is_active`),
  CONSTRAINT `employees_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `external_repair_condition_intents`
--

DROP TABLE IF EXISTS `external_repair_condition_intents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `external_repair_condition_intents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `repair_job_id` bigint unsigned NOT NULL,
  `design_authorization_id` bigint unsigned NOT NULL,
  `approved_by` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_payload` json NOT NULL,
  `decision` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `external_repair_condition_intents_case_id_unique` (`case_id`),
  UNIQUE KEY `external_repair_condition_intents_repair_job_id_unique` (`repair_job_id`),
  KEY `erci_design_auth_fk` (`design_authorization_id`),
  KEY `external_repair_condition_intents_approved_by_foreign` (`approved_by`),
  CONSTRAINT `erci_design_auth_fk` FOREIGN KEY (`design_authorization_id`) REFERENCES `document_correction_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `external_repair_condition_intents_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `external_repair_condition_intents_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `external_repair_condition_intents_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `external_repair_condition_postings`
--

DROP TABLE IF EXISTS `external_repair_condition_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `external_repair_condition_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `intent_id` bigint unsigned NOT NULL,
  `repair_job_id` bigint unsigned NOT NULL,
  `original_release_ledger_id` bigint unsigned NOT NULL,
  `old_qr_id` bigint unsigned NOT NULL,
  `return_qr_id` bigint unsigned NOT NULL,
  `previous_condition` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `effective_condition` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `external_repair_condition_postings_case_id_unique` (`case_id`),
  UNIQUE KEY `external_repair_condition_postings_intent_id_unique` (`intent_id`),
  UNIQUE KEY `external_repair_condition_postings_repair_job_id_unique` (`repair_job_id`),
  UNIQUE KEY `ercp_original_release_uq` (`original_release_ledger_id`),
  KEY `ercp_old_qr_fk` (`old_qr_id`),
  KEY `ercp_new_qr_fk` (`return_qr_id`),
  KEY `external_repair_condition_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `ercp_new_qr_fk` FOREIGN KEY (`return_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `ercp_old_qr_fk` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `ercp_original_release_fk` FOREIGN KEY (`original_release_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `external_repair_condition_postings_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `external_repair_condition_postings_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `external_repair_condition_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `external_repair_condition_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `external_repair_condition_postings_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_atomic_global_claims`
--

DROP TABLE IF EXISTS `historical_atomic_global_claims`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_atomic_global_claims` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `intent_id` bigint unsigned NOT NULL,
  `claim_kind` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `compensation_ledger_id` bigint unsigned NOT NULL,
  `idempotency_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hagc_original_once` (`original_ledger_id`),
  UNIQUE KEY `hagc_reversal_once` (`compensation_ledger_id`),
  UNIQUE KEY `hagc_key_once` (`idempotency_sha256`),
  KEY `historical_atomic_global_claims_posted_by_foreign` (`posted_by`),
  KEY `hagc_intent_kind` (`intent_id`,`claim_kind`),
  CONSTRAINT `historical_atomic_global_claims_compensation_ledger_id_foreign` FOREIGN KEY (`compensation_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_atomic_global_claims_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `historical_receipt_correction_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_atomic_global_claims_original_ledger_id_foreign` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_atomic_global_claims_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_count_atomic_batch_lines`
--

DROP TABLE IF EXISTS `historical_count_atomic_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_count_atomic_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `authorization_id` bigint unsigned NOT NULL,
  `posting_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `count_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `physical_ancestor_id` bigint unsigned NOT NULL,
  `original_receipt_ledger_id` bigint unsigned NOT NULL,
  `compensating_loss_ledger_id` bigint unsigned NOT NULL,
  `original_total_pcs` bigint unsigned NOT NULL,
  `effective_total_pcs` bigint unsigned NOT NULL,
  `loss_pcs` bigint unsigned NOT NULL,
  `authorization_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hist_count_batch_authorization_unique` (`batch_id`,`authorization_id`),
  KEY `historical_count_atomic_batch_lines_authorization_id_foreign` (`authorization_id`),
  KEY `historical_count_atomic_batch_lines_posting_id_foreign` (`posting_id`),
  KEY `historical_count_atomic_batch_lines_transfer_id_foreign` (`transfer_id`),
  KEY `historical_count_atomic_batch_lines_count_id_foreign` (`count_id`),
  KEY `historical_count_atomic_batch_lines_receipt_id_foreign` (`receipt_id`),
  KEY `historical_count_atomic_batch_lines_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `historical_count_atomic_batch_lines_original_receipt_ledger_fk` (`original_receipt_ledger_id`),
  KEY `historical_count_atomic_batch_lines_compensating_loss_ledger_fk` (`compensating_loss_ledger_id`),
  CONSTRAINT `historical_count_atomic_batch_lines_authorization_id_foreign` FOREIGN KEY (`authorization_id`) REFERENCES `historical_count_compensation_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_atomic_batch_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `historical_count_atomic_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_atomic_batch_lines_compensating_loss_ledger_fk` FOREIGN KEY (`compensating_loss_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_atomic_batch_lines_count_id_foreign` FOREIGN KEY (`count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_atomic_batch_lines_original_receipt_ledger_fk` FOREIGN KEY (`original_receipt_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_atomic_batch_lines_posting_id_foreign` FOREIGN KEY (`posting_id`) REFERENCES `historical_count_compensation_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_atomic_batch_lines_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_atomic_batch_lines_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_atomic_batch_lines_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_count_atomic_batches`
--

DROP TABLE IF EXISTS `historical_count_atomic_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_count_atomic_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` tinyint unsigned NOT NULL,
  `member_count` tinyint unsigned NOT NULL,
  `scope_manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `scope_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_total_pcs` bigint unsigned NOT NULL,
  `effective_total_pcs` bigint unsigned NOT NULL,
  `compensated_loss_pcs` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_count_atomic_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_count_atomic_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_count_compensation_authorizations`
--

DROP TABLE IF EXISTS `historical_count_compensation_authorizations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_count_compensation_authorizations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dossier_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `count_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `authorizer_id` bigint unsigned NOT NULL,
  `source_proof` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `authorization_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'authorized',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hcca_authorization_sha256_uq` (`authorization_sha256`),
  KEY `historical_count_compensation_authorizations_dossier_id_foreign` (`dossier_id`),
  KEY `historical_count_compensation_authorizations_transfer_id_foreign` (`transfer_id`),
  KEY `historical_count_compensation_authorizations_count_id_foreign` (`count_id`),
  KEY `historical_count_compensation_authorizations_receipt_id_foreign` (`receipt_id`),
  KEY `historical_count_compensation_authorizations_authorizer_fk` (`authorizer_id`),
  CONSTRAINT `historical_count_compensation_authorizations_authorizer_fk` FOREIGN KEY (`authorizer_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_authorizations_count_id_foreign` FOREIGN KEY (`count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_authorizations_dossier_id_foreign` FOREIGN KEY (`dossier_id`) REFERENCES `historical_transfer_delta_dossiers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_authorizations_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_authorizations_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_count_compensation_postings`
--

DROP TABLE IF EXISTS `historical_count_compensation_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_count_compensation_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `authorization_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `count_id` bigint unsigned NOT NULL,
  `original_receipt_ledger_id` bigint unsigned NOT NULL,
  `loss_ledger_id` bigint unsigned NOT NULL,
  `loss_pcs` bigint unsigned NOT NULL,
  `effective_good_pcs` bigint unsigned NOT NULL,
  `effective_damaged_pcs` bigint unsigned NOT NULL,
  `authorization_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `before_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `after_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_count_compensation_postings_authorization_id_foreign` (`authorization_id`),
  KEY `historical_count_compensation_postings_transfer_id_foreign` (`transfer_id`),
  KEY `historical_count_compensation_postings_receipt_id_foreign` (`receipt_id`),
  KEY `historical_count_compensation_postings_count_id_foreign` (`count_id`),
  KEY `hccp_original_receipt_ledger_fk` (`original_receipt_ledger_id`),
  KEY `historical_count_compensation_postings_loss_ledger_id_foreign` (`loss_ledger_id`),
  KEY `historical_count_compensation_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `hccp_original_receipt_ledger_fk` FOREIGN KEY (`original_receipt_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_postings_authorization_id_foreign` FOREIGN KEY (`authorization_id`) REFERENCES `historical_count_compensation_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_postings_count_id_foreign` FOREIGN KEY (`count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_postings_loss_ledger_id_foreign` FOREIGN KEY (`loss_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_postings_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_count_compensation_postings_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_cross_family_settlement_members`
--

DROP TABLE IF EXISTS `historical_cross_family_settlement_members`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_cross_family_settlement_members` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `settlement_id` bigint unsigned NOT NULL,
  `kind` varchar(8) COLLATE utf8mb4_unicode_ci NOT NULL,
  `count_family` varchar(24) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `document_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `ancestor_id` bigint unsigned NOT NULL,
  `document_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `member_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hcfs_member_settlement_transfer_kind_unique` (`settlement_id`,`transfer_id`,`kind`),
  UNIQUE KEY `hcfs_member_claim_unique` (`kind`,`count_family`,`document_id`),
  KEY `hcfs_member_receipt_fk` (`receipt_id`),
  KEY `hcfs_member_ancestor_fk` (`ancestor_id`),
  KEY `hcfs_member_transfer_lookup` (`transfer_id`),
  CONSTRAINT `hcfs_member_ancestor_fk` FOREIGN KEY (`ancestor_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hcfs_member_parent_fk` FOREIGN KEY (`settlement_id`) REFERENCES `historical_cross_family_settlements` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hcfs_member_receipt_fk` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hcfs_member_transfer_fk` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_cross_family_settlements`
--

DROP TABLE IF EXISTS `historical_cross_family_settlements`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_cross_family_settlements` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` tinyint unsigned NOT NULL,
  `count_batch_id` bigint unsigned NOT NULL,
  `return_batch_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `member_count` smallint unsigned NOT NULL,
  `source_manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `count_original_pcs` bigint unsigned NOT NULL,
  `count_effective_pcs` bigint unsigned NOT NULL,
  `count_loss_pcs` bigint unsigned NOT NULL,
  `count_found_pcs` bigint unsigned NOT NULL,
  `count_net_delta_pcs` bigint NOT NULL,
  `returned_movement_pcs` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `hcfs_count_fk` (`count_batch_id`),
  KEY `hcfs_return_fk` (`return_batch_id`),
  KEY `historical_cross_family_settlements_warehouse_id_foreign` (`warehouse_id`),
  KEY `historical_cross_family_settlements_posted_by_foreign` (`posted_by`),
  CONSTRAINT `hcfs_count_fk` FOREIGN KEY (`count_batch_id`) REFERENCES `historical_mixed_count_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hcfs_return_fk` FOREIGN KEY (`return_batch_id`) REFERENCES `historical_downstream_return_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_cross_family_settlements_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_cross_family_settlements_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_downstream_compensation_claims`
--

DROP TABLE IF EXISTS `historical_downstream_compensation_claims`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_downstream_compensation_claims` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `intent_id` bigint unsigned NOT NULL,
  `correction_case_id` bigint unsigned NOT NULL,
  `document_approval_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `compensation_ledger_id` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `idempotency_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hdcc_original_ledger_once` (`original_ledger_id`),
  UNIQUE KEY `hdcc_compensation_ledger_once` (`compensation_ledger_id`),
  UNIQUE KEY `hdcc_idempotency_once` (`idempotency_sha256`),
  KEY `historical_downstream_compensation_claims_correction_case_fk` (`correction_case_id`),
  KEY `historical_downstream_compensation_claims_document_approval_fk` (`document_approval_id`),
  KEY `historical_downstream_compensation_claims_posted_by_foreign` (`posted_by`),
  KEY `hdcc_intent_posted_idx` (`intent_id`,`posted_at`),
  CONSTRAINT `historical_downstream_compensation_claims_compensation_ledger_fk` FOREIGN KEY (`compensation_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_compensation_claims_correction_case_fk` FOREIGN KEY (`correction_case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_compensation_claims_document_approval_fk` FOREIGN KEY (`document_approval_id`) REFERENCES `document_correction_execution_approvals` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_compensation_claims_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `historical_receipt_correction_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_compensation_claims_original_ledger_fk` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_compensation_claims_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_downstream_return_batches`
--

DROP TABLE IF EXISTS `historical_downstream_return_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_downstream_return_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` tinyint unsigned NOT NULL,
  `member_count` tinyint unsigned NOT NULL,
  `scope_manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `scope_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `total_return_pcs` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_downstream_return_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_downstream_return_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_downstream_return_lines`
--

DROP TABLE IF EXISTS `historical_downstream_return_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_downstream_return_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `return_id` bigint unsigned NOT NULL,
  `return_detail_id` bigint unsigned NOT NULL,
  `issue_detail_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `physical_root_id` bigint unsigned NOT NULL,
  `original_receipt_ledger_id` bigint unsigned NOT NULL,
  `original_issue_ledger_id` bigint unsigned NOT NULL,
  `return_ledger_id` bigint unsigned NOT NULL,
  `retired_qr_id` bigint unsigned NOT NULL,
  `replacement_qr_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `historical_return_batch_member_unique` (`batch_id`,`return_id`),
  KEY `historical_downstream_return_lines_return_id_foreign` (`return_id`),
  KEY `historical_downstream_return_lines_return_detail_id_foreign` (`return_detail_id`),
  KEY `historical_downstream_return_lines_issue_detail_id_foreign` (`issue_detail_id`),
  KEY `historical_downstream_return_lines_bundle_id_foreign` (`bundle_id`),
  KEY `historical_downstream_return_lines_original_receipt_ledger_fk` (`original_receipt_ledger_id`),
  KEY `historical_downstream_return_lines_original_issue_ledger_fk` (`original_issue_ledger_id`),
  KEY `historical_downstream_return_lines_return_ledger_id_foreign` (`return_ledger_id`),
  KEY `historical_downstream_return_lines_retired_qr_id_foreign` (`retired_qr_id`),
  KEY `historical_downstream_return_lines_replacement_qr_id_foreign` (`replacement_qr_id`),
  KEY `hdr_transfer_lookup_idx` (`transfer_id`),
  KEY `hdr_receipt_lookup_idx` (`receipt_id`),
  CONSTRAINT `historical_downstream_return_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `historical_downstream_return_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_issue_detail_id_foreign` FOREIGN KEY (`issue_detail_id`) REFERENCES `stock_out_details` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_original_issue_ledger_fk` FOREIGN KEY (`original_issue_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_original_receipt_ledger_fk` FOREIGN KEY (`original_receipt_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_replacement_qr_id_foreign` FOREIGN KEY (`replacement_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_retired_qr_id_foreign` FOREIGN KEY (`retired_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_return_detail_id_foreign` FOREIGN KEY (`return_detail_id`) REFERENCES `stock_out_return_details` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_return_id_foreign` FOREIGN KEY (`return_id`) REFERENCES `stock_out_returns` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_return_ledger_id_foreign` FOREIGN KEY (`return_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_downstream_return_lines_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_found_extra_authorizations`
--

DROP TABLE IF EXISTS `historical_found_extra_authorizations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_found_extra_authorizations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `count_id` bigint unsigned NOT NULL,
  `plan_id` bigint unsigned NOT NULL,
  `authorizer_id` bigint unsigned NOT NULL,
  `source_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'authorized',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_found_extra_authorizations_transfer_id_foreign` (`transfer_id`),
  KEY `historical_found_extra_authorizations_receipt_id_foreign` (`receipt_id`),
  KEY `historical_found_extra_authorizations_count_id_foreign` (`count_id`),
  KEY `historical_found_extra_authorizations_plan_id_foreign` (`plan_id`),
  KEY `historical_found_extra_authorizations_authorizer_id_foreign` (`authorizer_id`),
  CONSTRAINT `historical_found_extra_authorizations_authorizer_id_foreign` FOREIGN KEY (`authorizer_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_authorizations_count_id_foreign` FOREIGN KEY (`count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_authorizations_plan_id_foreign` FOREIGN KEY (`plan_id`) REFERENCES `stock_count_variance_plans` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_authorizations_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_authorizations_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_found_extra_postings`
--

DROP TABLE IF EXISTS `historical_found_extra_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_found_extra_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `authorization_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `count_id` bigint unsigned NOT NULL,
  `plan_id` bigint unsigned NOT NULL,
  `found_bundle_id` bigint unsigned NOT NULL,
  `original_receipt_ledger_id` bigint unsigned NOT NULL,
  `found_ledger_id` bigint unsigned NOT NULL,
  `found_pcs` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_found_extra_postings_authorization_id_foreign` (`authorization_id`),
  KEY `historical_found_extra_postings_transfer_id_foreign` (`transfer_id`),
  KEY `historical_found_extra_postings_receipt_id_foreign` (`receipt_id`),
  KEY `historical_found_extra_postings_count_id_foreign` (`count_id`),
  KEY `historical_found_extra_postings_plan_id_foreign` (`plan_id`),
  KEY `historical_found_extra_postings_found_bundle_id_foreign` (`found_bundle_id`),
  KEY `historical_found_extra_postings_original_receipt_ledger_fk` (`original_receipt_ledger_id`),
  KEY `historical_found_extra_postings_found_ledger_id_foreign` (`found_ledger_id`),
  KEY `historical_found_extra_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_found_extra_postings_authorization_id_foreign` FOREIGN KEY (`authorization_id`) REFERENCES `historical_found_extra_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_postings_count_id_foreign` FOREIGN KEY (`count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_postings_found_bundle_id_foreign` FOREIGN KEY (`found_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_postings_found_ledger_id_foreign` FOREIGN KEY (`found_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_postings_original_receipt_ledger_fk` FOREIGN KEY (`original_receipt_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_postings_plan_id_foreign` FOREIGN KEY (`plan_id`) REFERENCES `stock_count_variance_plans` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_postings_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_found_extra_postings_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_mixed_count_batch_lines`
--

DROP TABLE IF EXISTS `historical_mixed_count_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_mixed_count_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `family` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `authorization_id` bigint unsigned NOT NULL,
  `posting_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `count_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `ancestor_id` bigint unsigned NOT NULL,
  `original_receipt_ledger_id` bigint unsigned NOT NULL,
  `compensation_ledger_id` bigint unsigned NOT NULL,
  `original_total_pcs` bigint unsigned NOT NULL,
  `effective_total_pcs` bigint unsigned NOT NULL,
  `delta_pcs` bigint NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `historical_mixed_auth_unique` (`family`,`authorization_id`),
  UNIQUE KEY `historical_mixed_post_unique` (`family`,`posting_id`),
  KEY `historical_mixed_count_batch_lines_batch_id_foreign` (`batch_id`),
  KEY `historical_mixed_count_batch_lines_transfer_id_foreign` (`transfer_id`),
  KEY `historical_mixed_count_batch_lines_receipt_id_foreign` (`receipt_id`),
  KEY `historical_mixed_count_batch_lines_count_id_foreign` (`count_id`),
  KEY `historical_mixed_count_batch_lines_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `historical_mixed_count_batch_lines_ancestor_id_foreign` (`ancestor_id`),
  KEY `hmcb_original_ledger_fk` (`original_receipt_ledger_id`),
  KEY `hmcb_compensation_ledger_fk` (`compensation_ledger_id`),
  CONSTRAINT `historical_mixed_count_batch_lines_ancestor_id_foreign` FOREIGN KEY (`ancestor_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_mixed_count_batch_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `historical_mixed_count_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_mixed_count_batch_lines_count_id_foreign` FOREIGN KEY (`count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_mixed_count_batch_lines_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_mixed_count_batch_lines_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_mixed_count_batch_lines_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hmcb_compensation_ledger_fk` FOREIGN KEY (`compensation_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hmcb_original_ledger_fk` FOREIGN KEY (`original_receipt_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_mixed_count_batches`
--

DROP TABLE IF EXISTS `historical_mixed_count_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_mixed_count_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` int unsigned NOT NULL,
  `member_count` smallint unsigned NOT NULL,
  `manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_pcs` bigint unsigned NOT NULL,
  `effective_pcs` bigint unsigned NOT NULL,
  `loss_pcs` bigint unsigned NOT NULL,
  `found_pcs` bigint unsigned NOT NULL,
  `net_delta_pcs` bigint NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_mixed_count_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_mixed_count_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_partial_count_authorizations`
--

DROP TABLE IF EXISTS `historical_partial_count_authorizations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_partial_count_authorizations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `count_id` bigint unsigned NOT NULL,
  `plan_id` bigint unsigned NOT NULL,
  `authorizer_id` bigint unsigned NOT NULL,
  `source_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'authorized',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_partial_count_authorizations_transfer_id_foreign` (`transfer_id`),
  KEY `historical_partial_count_authorizations_receipt_id_foreign` (`receipt_id`),
  KEY `historical_partial_count_authorizations_count_id_foreign` (`count_id`),
  KEY `historical_partial_count_authorizations_plan_id_foreign` (`plan_id`),
  KEY `historical_partial_count_authorizations_authorizer_id_foreign` (`authorizer_id`),
  CONSTRAINT `historical_partial_count_authorizations_authorizer_id_foreign` FOREIGN KEY (`authorizer_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_authorizations_count_id_foreign` FOREIGN KEY (`count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_authorizations_plan_id_foreign` FOREIGN KEY (`plan_id`) REFERENCES `stock_count_variance_plans` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_authorizations_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_authorizations_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_partial_count_postings`
--

DROP TABLE IF EXISTS `historical_partial_count_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_partial_count_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `authorization_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `count_id` bigint unsigned NOT NULL,
  `original_receipt_ledger_id` bigint unsigned NOT NULL,
  `loss_ledger_id` bigint unsigned NOT NULL,
  `retained_bundle_id` bigint unsigned NOT NULL,
  `missing_bundle_id` bigint unsigned NOT NULL,
  `retained_pcs` bigint unsigned NOT NULL,
  `missing_pcs` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_partial_count_postings_authorization_id_foreign` (`authorization_id`),
  KEY `historical_partial_count_postings_transfer_id_foreign` (`transfer_id`),
  KEY `historical_partial_count_postings_receipt_id_foreign` (`receipt_id`),
  KEY `historical_partial_count_postings_count_id_foreign` (`count_id`),
  KEY `historical_partial_count_postings_original_receipt_ledger_fk` (`original_receipt_ledger_id`),
  KEY `historical_partial_count_postings_loss_ledger_id_foreign` (`loss_ledger_id`),
  KEY `historical_partial_count_postings_retained_bundle_id_foreign` (`retained_bundle_id`),
  KEY `historical_partial_count_postings_missing_bundle_id_foreign` (`missing_bundle_id`),
  KEY `historical_partial_count_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_partial_count_postings_authorization_id_foreign` FOREIGN KEY (`authorization_id`) REFERENCES `historical_partial_count_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_postings_count_id_foreign` FOREIGN KEY (`count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_postings_loss_ledger_id_foreign` FOREIGN KEY (`loss_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_postings_missing_bundle_id_foreign` FOREIGN KEY (`missing_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_postings_original_receipt_ledger_fk` FOREIGN KEY (`original_receipt_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_postings_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_postings_retained_bundle_id_foreign` FOREIGN KEY (`retained_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_partial_count_postings_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_physical_merge_attestations`
--

DROP TABLE IF EXISTS `historical_physical_merge_attestations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_physical_merge_attestations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `result_bundle_id` bigint unsigned NOT NULL,
  `result_qr_id` bigint unsigned NOT NULL,
  `printed_log_id` bigint unsigned NOT NULL,
  `scan_log_id` bigint unsigned NOT NULL,
  `label_verified_by` bigint unsigned NOT NULL,
  `reviewed_by` bigint unsigned NOT NULL,
  `evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `reviewed_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `historical_physical_merge_attestations_batch_id_unique` (`batch_id`),
  UNIQUE KEY `historical_physical_merge_attestations_result_bundle_id_unique` (`result_bundle_id`),
  UNIQUE KEY `historical_physical_merge_attestations_result_qr_id_unique` (`result_qr_id`),
  UNIQUE KEY `historical_physical_merge_attestations_scan_log_id_unique` (`scan_log_id`),
  UNIQUE KEY `historical_physical_merge_attestations_evidence_sha256_unique` (`evidence_sha256`),
  KEY `historical_physical_merge_attestations_printed_log_id_foreign` (`printed_log_id`),
  KEY `historical_physical_merge_attestations_label_verified_by_foreign` (`label_verified_by`),
  KEY `historical_physical_merge_attestations_reviewed_by_foreign` (`reviewed_by`),
  CONSTRAINT `historical_physical_merge_attestations_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `historical_physical_merge_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_attestations_label_verified_by_foreign` FOREIGN KEY (`label_verified_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_attestations_printed_log_id_foreign` FOREIGN KEY (`printed_log_id`) REFERENCES `label_print_logs` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_attestations_result_bundle_id_foreign` FOREIGN KEY (`result_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_attestations_result_qr_id_foreign` FOREIGN KEY (`result_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_attestations_reviewed_by_foreign` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_attestations_scan_log_id_foreign` FOREIGN KEY (`scan_log_id`) REFERENCES `qr_scan_logs` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_physical_merge_batches`
--

DROP TABLE IF EXISTS `historical_physical_merge_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_physical_merge_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `operation_id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
  `idempotency_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_plan_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `result_bundle_id` bigint unsigned NOT NULL,
  `result_qr_id` bigint unsigned NOT NULL,
  `result_ledger_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `source_count` smallint unsigned NOT NULL,
  `merged_by` bigint unsigned NOT NULL,
  `merged_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `historical_physical_merge_batches_operation_id_unique` (`operation_id`),
  UNIQUE KEY `historical_physical_merge_batches_idempotency_sha256_unique` (`idempotency_sha256`),
  UNIQUE KEY `historical_physical_merge_batches_result_bundle_id_unique` (`result_bundle_id`),
  UNIQUE KEY `historical_physical_merge_batches_result_qr_id_unique` (`result_qr_id`),
  UNIQUE KEY `historical_physical_merge_batches_result_ledger_id_unique` (`result_ledger_id`),
  KEY `historical_physical_merge_batches_merged_by_foreign` (`merged_by`),
  CONSTRAINT `historical_physical_merge_batches_merged_by_foreign` FOREIGN KEY (`merged_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_batches_result_bundle_id_foreign` FOREIGN KEY (`result_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_batches_result_ledger_id_foreign` FOREIGN KEY (`result_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_batches_result_qr_id_foreign` FOREIGN KEY (`result_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_physical_merge_lines`
--

DROP TABLE IF EXISTS `historical_physical_merge_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_physical_merge_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `source_bundle_id` bigint unsigned NOT NULL,
  `source_qr_id` bigint unsigned NOT NULL,
  `source_balance_id` bigint unsigned NOT NULL,
  `source_ledger_id` bigint unsigned NOT NULL,
  `source_identity_ledger_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `line_no` smallint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `historical_physical_merge_lines_batch_id_line_no_unique` (`batch_id`,`line_no`),
  UNIQUE KEY `historical_physical_merge_lines_source_bundle_id_unique` (`source_bundle_id`),
  UNIQUE KEY `historical_physical_merge_lines_source_qr_id_unique` (`source_qr_id`),
  UNIQUE KEY `historical_physical_merge_lines_source_balance_id_unique` (`source_balance_id`),
  UNIQUE KEY `historical_physical_merge_lines_source_identity_ledger_id_unique` (`source_identity_ledger_id`),
  KEY `historical_physical_merge_lines_source_ledger_id_foreign` (`source_ledger_id`),
  CONSTRAINT `historical_physical_merge_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `historical_physical_merge_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_lines_source_balance_id_foreign` FOREIGN KEY (`source_balance_id`) REFERENCES `stock_balances` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_lines_source_bundle_id_foreign` FOREIGN KEY (`source_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_lines_source_identity_ledger_fk` FOREIGN KEY (`source_identity_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_lines_source_ledger_id_foreign` FOREIGN KEY (`source_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_physical_merge_lines_source_qr_id_foreign` FOREIGN KEY (`source_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_receipt_child_journal_batches`
--

DROP TABLE IF EXISTS `historical_receipt_child_journal_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_receipt_child_journal_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `intent_id` bigint unsigned NOT NULL,
  `approval_id` bigint unsigned NOT NULL,
  `original_receipt_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `reversal_ledger_id` bigint unsigned NOT NULL,
  `repost_ledger_id` bigint unsigned NOT NULL,
  `corrected_child_bundle_id` bigint unsigned NOT NULL,
  `corrected_child_qr_id` bigint unsigned NOT NULL,
  `before_pcs` int unsigned NOT NULL,
  `after_pcs` int unsigned NOT NULL,
  `claim_idempotency_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `journal_evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  `repost_provenance_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'split_child',
  `merge_attestation_id` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hrcjb_original_receipt_id_uq` (`original_receipt_id`),
  UNIQUE KEY `hrcjb_original_ledger_id_uq` (`original_ledger_id`),
  UNIQUE KEY `hrcjb_reversal_ledger_id_uq` (`reversal_ledger_id`),
  UNIQUE KEY `historical_receipt_child_journal_batches_repost_ledger_id_unique` (`repost_ledger_id`),
  UNIQUE KEY `hrcjb_claim_idempotency_sha256_uq` (`claim_idempotency_sha256`),
  UNIQUE KEY `hrcjb_corrected_bundle_unique` (`corrected_child_bundle_id`),
  UNIQUE KEY `hrcjb_corrected_qr_unique` (`corrected_child_qr_id`),
  UNIQUE KEY `hrcjb_attestation_unique` (`merge_attestation_id`),
  KEY `hrcjb_intent_approval_idx` (`intent_id`,`approval_id`),
  KEY `hrcjb_approval_fk` (`approval_id`),
  KEY `hrcjb_poster_fk` (`posted_by`),
  CONSTRAINT `hrcjb_approval_fk` FOREIGN KEY (`approval_id`) REFERENCES `historical_receipt_correction_approvals` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_child_bundle_fk` FOREIGN KEY (`corrected_child_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_child_qr_fk` FOREIGN KEY (`corrected_child_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_intent_fk` FOREIGN KEY (`intent_id`) REFERENCES `historical_receipt_correction_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_merge_attestation_fk` FOREIGN KEY (`merge_attestation_id`) REFERENCES `historical_physical_merge_attestations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_original_ledger_id_fk` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_poster_fk` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_receipt_fk` FOREIGN KEY (`original_receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_repost_ledger_id_fk` FOREIGN KEY (`repost_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrcjb_reversal_ledger_id_fk` FOREIGN KEY (`reversal_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_receipt_compensation_claims`
--

DROP TABLE IF EXISTS `historical_receipt_compensation_claims`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_receipt_compensation_claims` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `intent_id` bigint unsigned NOT NULL,
  `approval_id` bigint unsigned NOT NULL,
  `original_receipt_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `compensation_ledger_id` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `idempotency_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hrcc_original_receipt_once` (`original_receipt_id`),
  UNIQUE KEY `hrcc_original_ledger_once` (`original_ledger_id`),
  UNIQUE KEY `hrcc_compensation_ledger_once` (`compensation_ledger_id`),
  UNIQUE KEY `hrcc_idempotency_once` (`idempotency_sha256`),
  KEY `historical_receipt_compensation_claims_intent_id_foreign` (`intent_id`),
  KEY `historical_receipt_compensation_claims_approval_id_foreign` (`approval_id`),
  KEY `historical_receipt_compensation_claims_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_receipt_compensation_claims_approval_id_foreign` FOREIGN KEY (`approval_id`) REFERENCES `historical_receipt_correction_approvals` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_receipt_compensation_claims_compensation_ledger_fk` FOREIGN KEY (`compensation_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_receipt_compensation_claims_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `historical_receipt_correction_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_receipt_compensation_claims_original_ledger_fk` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_receipt_compensation_claims_original_receipt_fk` FOREIGN KEY (`original_receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_receipt_compensation_claims_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_receipt_correction_approvals`
--

DROP TABLE IF EXISTS `historical_receipt_correction_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_receipt_correction_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `intent_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned NOT NULL,
  `approved_intent_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `independent_approval_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hrca_intent_once` (`intent_id`),
  UNIQUE KEY `hrca_proof_unique` (`independent_approval_sha256`),
  KEY `historical_receipt_correction_approvals_checker_id_foreign` (`checker_id`),
  CONSTRAINT `historical_receipt_correction_approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_receipt_correction_approvals_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `historical_receipt_correction_intents` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_receipt_correction_intents`
--

DROP TABLE IF EXISTS `historical_receipt_correction_intents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_receipt_correction_intents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `target_good_pcs` bigint unsigned NOT NULL,
  `target_damaged_pcs` bigint unsigned NOT NULL,
  `preflight_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `allocation_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `documents_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `sealed_intent_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `intent_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `historical_receipt_correction_intents_request_key_unique` (`request_key`),
  UNIQUE KEY `historical_receipt_correction_intents_intent_sha256_unique` (`intent_sha256`),
  KEY `historical_receipt_correction_intents_maker_id_foreign` (`maker_id`),
  KEY `hrci_transfer_created_idx` (`transfer_id`,`created_at`),
  CONSTRAINT `historical_receipt_correction_intents_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_receipt_correction_intents_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_received_delta_batches`
--

DROP TABLE IF EXISTS `historical_received_delta_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_received_delta_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` bigint unsigned NOT NULL,
  `member_count` tinyint unsigned NOT NULL,
  `before_total_pcs` bigint unsigned NOT NULL,
  `after_total_pcs` bigint unsigned NOT NULL,
  `source_manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_received_delta_batches_warehouse_id_foreign` (`warehouse_id`),
  KEY `historical_received_delta_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_received_delta_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_received_delta_batches_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_received_delta_lineage_claims`
--

DROP TABLE IF EXISTS `historical_received_delta_lineage_claims`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_received_delta_lineage_claims` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `ancestry_anchor_id` bigint unsigned NOT NULL,
  `created_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hrda_root_uq` (`root_bundle_id`),
  UNIQUE KEY `hrda_anchor_uq` (`ancestry_anchor_id`),
  KEY `historical_received_delta_lineage_claims_batch_id_foreign` (`batch_id`),
  CONSTRAINT `historical_received_delta_lineage_claims_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `historical_received_delta_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrda_anchor_fk` FOREIGN KEY (`ancestry_anchor_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrda_root_fk` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_received_delta_members`
--

DROP TABLE IF EXISTS `historical_received_delta_members`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_received_delta_members` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `request_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `posting_id` bigint unsigned NOT NULL,
  `before_pcs` bigint unsigned NOT NULL,
  `after_pcs` bigint unsigned NOT NULL,
  `member_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_received_delta_members_batch_id_foreign` (`batch_id`),
  KEY `historical_received_delta_members_request_id_foreign` (`request_id`),
  KEY `historical_received_delta_members_transfer_id_foreign` (`transfer_id`),
  KEY `historical_received_delta_members_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `historical_received_delta_members_posting_id_foreign` (`posting_id`),
  CONSTRAINT `historical_received_delta_members_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `historical_received_delta_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_received_delta_members_posting_id_foreign` FOREIGN KEY (`posting_id`) REFERENCES `received_transit_reallocation_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_received_delta_members_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `received_transit_reallocation_requests` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_received_delta_members_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_received_delta_members_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_reversal_atomic_batches`
--

DROP TABLE IF EXISTS `historical_reversal_atomic_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_reversal_atomic_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` bigint unsigned NOT NULL,
  `member_count` tinyint unsigned NOT NULL,
  `total_quantity_pcs` bigint unsigned NOT NULL,
  `source_manifest_json` json NOT NULL,
  `source_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_reversal_atomic_batches_warehouse_id_foreign` (`warehouse_id`),
  KEY `historical_reversal_atomic_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_reversal_atomic_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_reversal_atomic_batches_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_reversal_atomic_members`
--

DROP TABLE IF EXISTS `historical_reversal_atomic_members`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_reversal_atomic_members` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `reversal_request_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `reversal_ledger_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `member_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hrev_member_unique_req` (`reversal_request_id`),
  UNIQUE KEY `hrev_member_unique_original` (`original_ledger_id`),
  UNIQUE KEY `hrev_member_unique_inverse` (`reversal_ledger_id`),
  KEY `hrev_member_batch_fk` (`batch_id`),
  KEY `hrev_member_bundle_fk` (`bundle_id`),
  KEY `hrev_member_root_fk` (`root_bundle_id`),
  CONSTRAINT `hrev_member_batch_fk` FOREIGN KEY (`batch_id`) REFERENCES `historical_reversal_atomic_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrev_member_bundle_fk` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrev_member_inverse_fk` FOREIGN KEY (`reversal_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrev_member_original_fk` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrev_member_req_fk` FOREIGN KEY (`reversal_request_id`) REFERENCES `stock_reversal_requests` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrev_member_root_fk` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_reversal_return_members`
--

DROP TABLE IF EXISTS `historical_reversal_return_members`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_reversal_return_members` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `settlement_id` bigint unsigned NOT NULL,
  `kind` varchar(12) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `member_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hrret_source_unique` (`kind`,`source_id`),
  UNIQUE KEY `hrret_root_unique` (`root_bundle_id`),
  KEY `hrret_member_settlement_fk` (`settlement_id`),
  KEY `hrret_member_bundle_fk` (`bundle_id`),
  CONSTRAINT `hrret_member_bundle_fk` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrret_member_root_fk` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrret_member_settlement_fk` FOREIGN KEY (`settlement_id`) REFERENCES `historical_reversal_return_settlements` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_reversal_return_settlements`
--

DROP TABLE IF EXISTS `historical_reversal_return_settlements`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_reversal_return_settlements` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` bigint unsigned NOT NULL,
  `reversal_batch_id` bigint unsigned NOT NULL,
  `return_batch_id` bigint unsigned NOT NULL,
  `member_count` smallint unsigned NOT NULL,
  `reversed_pcs` bigint unsigned NOT NULL,
  `returned_pcs` bigint unsigned NOT NULL,
  `source_manifest_json` json NOT NULL,
  `source_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `hrret_reverse_unique` (`reversal_batch_id`),
  UNIQUE KEY `hrret_return_unique` (`return_batch_id`),
  KEY `historical_reversal_return_settlements_warehouse_id_foreign` (`warehouse_id`),
  KEY `historical_reversal_return_settlements_posted_by_foreign` (`posted_by`),
  CONSTRAINT `historical_reversal_return_settlements_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_reversal_return_settlements_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrret_return_fk` FOREIGN KEY (`return_batch_id`) REFERENCES `historical_downstream_return_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `hrret_reverse_fk` FOREIGN KEY (`reversal_batch_id`) REFERENCES `historical_reversal_atomic_batches` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_transfer_delta_dossiers`
--

DROP TABLE IF EXISTS `historical_transfer_delta_dossiers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_transfer_delta_dossiers` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `target_good_pcs` bigint unsigned NOT NULL,
  `target_damaged_pcs` bigint unsigned NOT NULL,
  `source_snapshot` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `dossier_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `historical_transfer_delta_dossiers_dossier_sha256_unique` (`dossier_sha256`),
  KEY `historical_transfer_delta_dossiers_transfer_id_foreign` (`transfer_id`),
  KEY `historical_transfer_delta_dossiers_warehouse_id_foreign` (`warehouse_id`),
  KEY `historical_transfer_delta_dossiers_maker_id_foreign` (`maker_id`),
  CONSTRAINT `historical_transfer_delta_dossiers_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_transfer_delta_dossiers_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_transfer_delta_dossiers_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `historical_transfer_delta_reviews`
--

DROP TABLE IF EXISTS `historical_transfer_delta_reviews`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `historical_transfer_delta_reviews` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dossier_id` bigint unsigned NOT NULL,
  `reviewer_id` bigint unsigned NOT NULL,
  `dossier_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `review_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `decision` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `review_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `reviewed_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `historical_transfer_delta_reviews_dossier_id_foreign` (`dossier_id`),
  KEY `historical_transfer_delta_reviews_reviewer_id_foreign` (`reviewer_id`),
  CONSTRAINT `historical_transfer_delta_reviews_dossier_id_foreign` FOREIGN KEY (`dossier_id`) REFERENCES `historical_transfer_delta_dossiers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `historical_transfer_delta_reviews_reviewer_id_foreign` FOREIGN KEY (`reviewer_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `idempotency_requests`
--

DROP TABLE IF EXISTS `idempotency_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `idempotency_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `idempotency_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `endpoint` varchar(160) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'processing',
  `response_code` smallint unsigned DEFAULT NULL,
  `response_body` json DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `expires_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idempotency_user_key_uq` (`user_id`,`idempotency_key`),
  KEY `idempotency_requests_status_index` (`status`),
  KEY `idempotency_requests_expires_at_index` (`expires_at`),
  CONSTRAINT `idempotency_requests_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=99 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `label_print_logs`
--

DROP TABLE IF EXISTS `label_print_logs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `label_print_logs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `bundle_id` bigint unsigned NOT NULL,
  `qr_code_id` bigint unsigned NOT NULL,
  `label_template_id` bigint unsigned DEFAULT NULL,
  `attempt_type` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `result` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'requested',
  `copy_count` smallint unsigned NOT NULL DEFAULT '1',
  `printer_name` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `operator_note` text COLLATE utf8mb4_unicode_ci,
  `printed_by` bigint unsigned NOT NULL,
  `confirmed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `label_print_logs_label_template_id_foreign` (`label_template_id`),
  KEY `label_print_logs_printed_by_foreign` (`printed_by`),
  KEY `label_print_logs_bundle_id_created_at_index` (`bundle_id`,`created_at`),
  KEY `label_print_logs_qr_code_id_created_at_index` (`qr_code_id`,`created_at`),
  KEY `label_print_logs_result_created_at_index` (`result`,`created_at`),
  CONSTRAINT `label_print_logs_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `label_print_logs_label_template_id_foreign` FOREIGN KEY (`label_template_id`) REFERENCES `label_templates` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `label_print_logs_printed_by_foreign` FOREIGN KEY (`printed_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `label_print_logs_qr_code_id_foreign` FOREIGN KEY (`qr_code_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `label_templates`
--

DROP TABLE IF EXISTS `label_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `label_templates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `version` smallint unsigned NOT NULL DEFAULT '1',
  `width_mm` decimal(6,2) NOT NULL,
  `height_mm` decimal(6,2) NOT NULL,
  `layout` json DEFAULT NULL,
  `is_default` tinyint(1) NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `label_templates_code_unique` (`code`),
  KEY `label_templates_width_mm_height_mm_is_active_index` (`width_mm`,`height_mm`,`is_active`),
  KEY `label_templates_is_default_index` (`is_default`),
  KEY `label_templates_is_active_index` (`is_active`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_claim_correction_plans`
--

DROP TABLE IF EXISTS `legacy_claim_correction_plans`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_claim_correction_plans` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `claim_case_id` bigint unsigned NOT NULL,
  `dossier_id` bigint unsigned NOT NULL,
  `retained_review_id` bigint unsigned NOT NULL,
  `source_bundle_id` bigint unsigned NOT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `destination_warehouse_id` bigint unsigned NOT NULL,
  `action` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `verified_physical_pcs` bigint unsigned NOT NULL,
  `evidence_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evidence_snapshot` json NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `technical_reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `checker_verified_pcs` bigint unsigned DEFAULT NULL,
  `decision_note` text COLLATE utf8mb4_unicode_ci,
  `decided_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lccp_maker_request_uq` (`maker_id`,`request_key`),
  UNIQUE KEY `lccp_claim_once_uq` (`claim_case_id`),
  UNIQUE KEY `lccp_dossier_once_uq` (`dossier_id`),
  KEY `legacy_claim_correction_plans_retained_review_id_foreign` (`retained_review_id`),
  KEY `legacy_claim_correction_plans_source_bundle_id_foreign` (`source_bundle_id`),
  KEY `legacy_claim_correction_plans_destination_warehouse_id_foreign` (`destination_warehouse_id`),
  KEY `legacy_claim_correction_plans_checker_id_foreign` (`checker_id`),
  KEY `lccp_origin_status_idx` (`origin_warehouse_id`,`status`),
  KEY `legacy_claim_correction_plans_status_index` (`status`),
  CONSTRAINT `legacy_claim_correction_plans_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_correction_plans_claim_case_id_foreign` FOREIGN KEY (`claim_case_id`) REFERENCES `legacy_claim_exception_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_correction_plans_destination_warehouse_id_foreign` FOREIGN KEY (`destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_correction_plans_dossier_id_foreign` FOREIGN KEY (`dossier_id`) REFERENCES `legacy_claim_reconciliation_dossiers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_correction_plans_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_correction_plans_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_correction_plans_retained_review_id_foreign` FOREIGN KEY (`retained_review_id`) REFERENCES `legacy_retained_child_return_reviews` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_correction_plans_source_bundle_id_foreign` FOREIGN KEY (`source_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_claim_exception_cases`
--

DROP TABLE IF EXISTS `legacy_claim_exception_cases`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_claim_exception_cases` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `retained_review_id` bigint unsigned NOT NULL,
  `source_bundle_id` bigint unsigned NOT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `destination_warehouse_id` bigint unsigned NOT NULL,
  `source_status` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_pcs` bigint unsigned NOT NULL,
  `active_hold_pcs` bigint unsigned NOT NULL,
  `source_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_snapshot` json NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `investigation_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` enum('submitted','confirmed_blocked','needs_recount','rejected') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `decision_note` text COLLATE utf8mb4_unicode_ci,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `decided_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lcec_maker_request_uq` (`maker_id`,`request_key`),
  UNIQUE KEY `lcec_review_once_uq` (`retained_review_id`),
  KEY `legacy_claim_exception_cases_source_bundle_id_foreign` (`source_bundle_id`),
  KEY `legacy_claim_exception_cases_destination_warehouse_id_foreign` (`destination_warehouse_id`),
  KEY `legacy_claim_exception_cases_checker_id_foreign` (`checker_id`),
  KEY `lcec_origin_status_idx` (`origin_warehouse_id`,`status`),
  KEY `legacy_claim_exception_cases_status_index` (`status`),
  CONSTRAINT `legacy_claim_exception_cases_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_exception_cases_destination_warehouse_id_foreign` FOREIGN KEY (`destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_exception_cases_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_exception_cases_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_exception_cases_retained_review_id_foreign` FOREIGN KEY (`retained_review_id`) REFERENCES `legacy_retained_child_return_reviews` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_exception_cases_source_bundle_id_foreign` FOREIGN KEY (`source_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_claim_reconciliation_dossiers`
--

DROP TABLE IF EXISTS `legacy_claim_reconciliation_dossiers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_claim_reconciliation_dossiers` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `claim_case_id` bigint unsigned NOT NULL,
  `retained_review_id` bigint unsigned NOT NULL,
  `source_bundle_id` bigint unsigned NOT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `destination_warehouse_id` bigint unsigned NOT NULL,
  `verified_physical_pcs` bigint unsigned NOT NULL,
  `evidence_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evidence_snapshot` json NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `recount_evidence_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `maker_id` bigint unsigned NOT NULL,
  `checker_verified_pcs` bigint unsigned DEFAULT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `decision_note` text COLLATE utf8mb4_unicode_ci,
  `decided_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lcrd_maker_key_uq` (`maker_id`,`request_key`),
  UNIQUE KEY `lcrd_case_once_uq` (`claim_case_id`),
  KEY `legacy_claim_reconciliation_dossiers_retained_review_id_foreign` (`retained_review_id`),
  KEY `legacy_claim_reconciliation_dossiers_source_bundle_id_foreign` (`source_bundle_id`),
  KEY `legacy_claim_reconciliation_dossiers_destination_warehouse_fk` (`destination_warehouse_id`),
  KEY `legacy_claim_reconciliation_dossiers_checker_id_foreign` (`checker_id`),
  KEY `lcrd_origin_status_idx` (`origin_warehouse_id`,`status`),
  KEY `legacy_claim_reconciliation_dossiers_status_index` (`status`),
  CONSTRAINT `legacy_claim_reconciliation_dossiers_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_reconciliation_dossiers_claim_case_id_foreign` FOREIGN KEY (`claim_case_id`) REFERENCES `legacy_claim_exception_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_reconciliation_dossiers_destination_warehouse_fk` FOREIGN KEY (`destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_reconciliation_dossiers_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_reconciliation_dossiers_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_reconciliation_dossiers_retained_review_id_foreign` FOREIGN KEY (`retained_review_id`) REFERENCES `legacy_retained_child_return_reviews` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_claim_reconciliation_dossiers_source_bundle_id_foreign` FOREIGN KEY (`source_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_custody_evidence_links`
--

DROP TABLE IF EXISTS `legacy_custody_evidence_links`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_custody_evidence_links` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `opening_row_id` bigint unsigned NOT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `reference_kind` varchar(42) COLLATE utf8mb4_unicode_ci NOT NULL,
  `reference_no` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evidence_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `submitted_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `review_note` text COLLATE utf8mb4_unicode_ci,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `legacy_custody_evidence_links_opening_row_id_unique` (`opening_row_id`),
  KEY `legacy_custody_evidence_links_maker_id_foreign` (`maker_id`),
  KEY `legacy_custody_evidence_links_checker_id_foreign` (`checker_id`),
  KEY `legacy_custody_evidence_links_origin_warehouse_id_status_index` (`origin_warehouse_id`,`status`),
  KEY `legacy_custody_evidence_links_status_index` (`status`),
  CONSTRAINT `legacy_custody_evidence_links_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_custody_evidence_links_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_custody_evidence_links_opening_row_id_foreign` FOREIGN KEY (`opening_row_id`) REFERENCES `nonstore_opening_rows` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_custody_evidence_links_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_issued_returns`
--

DROP TABLE IF EXISTS `legacy_issued_returns`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_issued_returns` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `opening_row_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `old_qr_id` bigint unsigned NOT NULL,
  `new_qr_id` bigint unsigned DEFAULT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `receive_warehouse_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `condition` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `return_no` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `physical_receipt_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `review_note` text COLLATE utf8mb4_unicode_ci,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `approved_digest` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `physical_received_at` timestamp NOT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `legacy_return_maker_request_unique` (`maker_id`,`request_key`),
  UNIQUE KEY `legacy_issued_returns_opening_row_id_unique` (`opening_row_id`),
  UNIQUE KEY `legacy_issued_returns_return_no_unique` (`return_no`),
  UNIQUE KEY `legacy_issued_returns_ledger_id_unique` (`ledger_id`),
  KEY `legacy_issued_returns_bundle_id_foreign` (`bundle_id`),
  KEY `legacy_issued_returns_old_qr_id_foreign` (`old_qr_id`),
  KEY `legacy_issued_returns_new_qr_id_foreign` (`new_qr_id`),
  KEY `legacy_issued_returns_checker_id_foreign` (`checker_id`),
  KEY `legacy_return_origin_status_idx` (`origin_warehouse_id`,`status`),
  KEY `legacy_return_destination_status_idx` (`receive_warehouse_id`,`status`),
  KEY `legacy_issued_returns_status_index` (`status`),
  CONSTRAINT `legacy_issued_returns_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_issued_returns_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_issued_returns_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_issued_returns_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_issued_returns_new_qr_id_foreign` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_issued_returns_old_qr_id_foreign` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_issued_returns_opening_row_id_foreign` FOREIGN KEY (`opening_row_id`) REFERENCES `nonstore_opening_rows` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_issued_returns_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_issued_returns_receive_warehouse_id_foreign` FOREIGN KEY (`receive_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_partial_return_plans`
--

DROP TABLE IF EXISTS `legacy_partial_return_plans`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_partial_return_plans` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `opening_row_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `root_qr_id` bigint unsigned NOT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `destination_warehouse_id` bigint unsigned NOT NULL,
  `original_pcs` bigint unsigned NOT NULL,
  `requested_return_pcs` bigint unsigned NOT NULL,
  `retained_pcs` bigint unsigned NOT NULL,
  `condition` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `preparation_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `review_note` text COLLATE utf8mb4_unicode_ci,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `approved_contract_digest` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `legacy_partial_plan_actor_request_uq` (`maker_id`,`request_key`),
  UNIQUE KEY `legacy_partial_return_plans_opening_row_id_unique` (`opening_row_id`),
  KEY `legacy_partial_return_plans_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `legacy_partial_return_plans_root_qr_id_foreign` (`root_qr_id`),
  KEY `legacy_partial_return_plans_destination_warehouse_id_foreign` (`destination_warehouse_id`),
  KEY `legacy_partial_return_plans_checker_id_foreign` (`checker_id`),
  KEY `legacy_partial_plan_origin_status_idx` (`origin_warehouse_id`,`status`),
  CONSTRAINT `legacy_partial_return_plans_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_plans_destination_warehouse_id_foreign` FOREIGN KEY (`destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_plans_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_plans_opening_row_id_foreign` FOREIGN KEY (`opening_row_id`) REFERENCES `nonstore_opening_rows` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_plans_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_plans_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_plans_root_qr_id_foreign` FOREIGN KEY (`root_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_partial_return_postings`
--

DROP TABLE IF EXISTS `legacy_partial_return_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_partial_return_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `plan_id` bigint unsigned NOT NULL,
  `opening_row_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `retained_bundle_id` bigint unsigned NOT NULL,
  `returned_bundle_id` bigint unsigned NOT NULL,
  `old_root_qr_id` bigint unsigned NOT NULL,
  `retained_qr_id` bigint unsigned NOT NULL,
  `returned_qr_id` bigint unsigned NOT NULL,
  `receive_warehouse_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `condition` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `return_no` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'posting',
  `ledger_id` bigint unsigned DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `legacy_partial_return_postings_plan_id_unique` (`plan_id`),
  UNIQUE KEY `legacy_partial_return_postings_retained_bundle_id_unique` (`retained_bundle_id`),
  UNIQUE KEY `legacy_partial_return_postings_returned_bundle_id_unique` (`returned_bundle_id`),
  UNIQUE KEY `legacy_partial_return_postings_return_no_unique` (`return_no`),
  UNIQUE KEY `legacy_partial_return_postings_ledger_id_unique` (`ledger_id`),
  KEY `legacy_partial_return_postings_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `legacy_partial_return_postings_old_root_qr_id_foreign` (`old_root_qr_id`),
  KEY `legacy_partial_return_postings_retained_qr_id_foreign` (`retained_qr_id`),
  KEY `legacy_partial_return_postings_returned_qr_id_foreign` (`returned_qr_id`),
  KEY `legacy_partial_post_opening_status_idx` (`opening_row_id`,`status`),
  KEY `legacy_partial_post_receive_status_idx` (`receive_warehouse_id`,`status`),
  KEY `legacy_partial_return_postings_status_index` (`status`),
  CONSTRAINT `legacy_partial_return_postings_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_old_root_qr_id_foreign` FOREIGN KEY (`old_root_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_opening_row_id_foreign` FOREIGN KEY (`opening_row_id`) REFERENCES `nonstore_opening_rows` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_plan_id_foreign` FOREIGN KEY (`plan_id`) REFERENCES `legacy_partial_return_plans` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_receive_warehouse_id_foreign` FOREIGN KEY (`receive_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_retained_bundle_id_foreign` FOREIGN KEY (`retained_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_retained_qr_id_foreign` FOREIGN KEY (`retained_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_returned_bundle_id_foreign` FOREIGN KEY (`returned_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_returned_qr_id_foreign` FOREIGN KEY (`returned_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_partial_return_postings_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_qr_witness_evidence`
--

DROP TABLE IF EXISTS `legacy_qr_witness_evidence`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_qr_witness_evidence` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `receipt_plan_id` bigint unsigned NOT NULL,
  `new_qr_id` bigint unsigned NOT NULL,
  `print_log_id` bigint unsigned NOT NULL,
  `print_actor_id` bigint unsigned NOT NULL,
  `attachment_verifier_id` bigint unsigned NOT NULL,
  `scan_witness_id` bigint unsigned NOT NULL,
  `scanned_qr_id` bigint unsigned NOT NULL,
  `print_result` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `printed_at` timestamp NOT NULL,
  `attachment_state` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `attached_at` timestamp NOT NULL,
  `scan_result` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `scanned_at` timestamp NOT NULL,
  `old_qr_rejected` tinyint(1) NOT NULL,
  `evidence_reference` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evidence_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `recorded_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `legacy_qr_witness_evidence_receipt_plan_id_unique` (`receipt_plan_id`),
  UNIQUE KEY `legacy_qr_witness_evidence_evidence_reference_unique` (`evidence_reference`),
  KEY `lqwe_new_qr_fk` (`new_qr_id`),
  KEY `lqwe_print_fk` (`print_log_id`),
  KEY `lqwe_scan_qr_fk` (`scanned_qr_id`),
  CONSTRAINT `lqwe_new_qr_fk` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `lqwe_print_fk` FOREIGN KEY (`print_log_id`) REFERENCES `label_print_logs` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `lqwe_receipt_fk` FOREIGN KEY (`receipt_plan_id`) REFERENCES `legacy_transit_repair_receipt_plans` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `lqwe_scan_qr_fk` FOREIGN KEY (`scanned_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_remaining_child_returns`
--

DROP TABLE IF EXISTS `legacy_remaining_child_returns`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_remaining_child_returns` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `predecessor_type` enum('first_partial','second_partial') COLLATE utf8mb4_unicode_ci NOT NULL,
  `predecessor_id` bigint unsigned NOT NULL,
  `opening_row_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `old_qr_id` bigint unsigned NOT NULL,
  `new_qr_id` bigint unsigned DEFAULT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `receive_warehouse_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `condition` enum('good','damaged') COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `return_no` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` enum('submitted','approved','rejected','posting','posted') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `physical_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `review_note` text COLLATE utf8mb4_unicode_ci,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `approved_digest` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lrem_maker_key_unique` (`maker_id`,`request_key`),
  UNIQUE KEY `lrem_predecessor_unique` (`predecessor_type`,`predecessor_id`),
  UNIQUE KEY `lrem_bundle_unique` (`bundle_id`),
  UNIQUE KEY `legacy_remaining_child_returns_return_no_unique` (`return_no`),
  UNIQUE KEY `lrem_new_qr_unique` (`new_qr_id`),
  UNIQUE KEY `lrem_ledger_unique` (`ledger_id`),
  KEY `legacy_remaining_child_returns_old_qr_id_foreign` (`old_qr_id`),
  KEY `legacy_remaining_child_returns_origin_warehouse_id_foreign` (`origin_warehouse_id`),
  KEY `legacy_remaining_child_returns_receive_warehouse_id_foreign` (`receive_warehouse_id`),
  KEY `legacy_remaining_child_returns_checker_id_foreign` (`checker_id`),
  KEY `lrem_opening_status_idx` (`opening_row_id`,`status`),
  KEY `legacy_remaining_child_returns_status_index` (`status`),
  CONSTRAINT `legacy_remaining_child_returns_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_remaining_child_returns_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_remaining_child_returns_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_remaining_child_returns_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_remaining_child_returns_new_qr_id_foreign` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_remaining_child_returns_old_qr_id_foreign` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_remaining_child_returns_opening_row_id_foreign` FOREIGN KEY (`opening_row_id`) REFERENCES `nonstore_opening_rows` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_remaining_child_returns_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_remaining_child_returns_receive_warehouse_id_foreign` FOREIGN KEY (`receive_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_retained_child_postings`
--

DROP TABLE IF EXISTS `legacy_retained_child_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_retained_child_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `review_id` bigint unsigned NOT NULL,
  `predecessor_posting_id` bigint unsigned NOT NULL,
  `opening_row_id` bigint unsigned NOT NULL,
  `source_bundle_id` bigint unsigned NOT NULL,
  `source_qr_id` bigint unsigned NOT NULL,
  `returned_bundle_id` bigint unsigned NOT NULL,
  `retained_bundle_id` bigint unsigned NOT NULL,
  `returned_qr_id` bigint unsigned NOT NULL,
  `retained_qr_id` bigint unsigned NOT NULL,
  `receive_warehouse_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `remaining_pcs` bigint unsigned NOT NULL,
  `condition` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `return_no` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'posting',
  `ledger_id` bigint unsigned DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lrcp_review_uq` (`review_id`),
  UNIQUE KEY `lrcp_predecessor_uq` (`predecessor_posting_id`),
  UNIQUE KEY `lrcp_source_bundle_uq` (`source_bundle_id`),
  UNIQUE KEY `lrcp_returned_bundle_uq` (`returned_bundle_id`),
  UNIQUE KEY `lrcp_retained_bundle_uq` (`retained_bundle_id`),
  UNIQUE KEY `legacy_retained_child_postings_return_no_unique` (`return_no`),
  UNIQUE KEY `lrcp_ledger_uq` (`ledger_id`),
  KEY `legacy_retained_child_postings_source_qr_id_foreign` (`source_qr_id`),
  KEY `legacy_retained_child_postings_returned_qr_id_foreign` (`returned_qr_id`),
  KEY `legacy_retained_child_postings_retained_qr_id_foreign` (`retained_qr_id`),
  KEY `legacy_retained_child_postings_receive_warehouse_id_foreign` (`receive_warehouse_id`),
  KEY `lrcp_open_status_idx` (`opening_row_id`,`status`),
  KEY `legacy_retained_child_postings_status_index` (`status`),
  CONSTRAINT `legacy_retained_child_postings_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_opening_row_id_foreign` FOREIGN KEY (`opening_row_id`) REFERENCES `nonstore_opening_rows` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_predecessor_posting_id_foreign` FOREIGN KEY (`predecessor_posting_id`) REFERENCES `legacy_partial_return_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_receive_warehouse_id_foreign` FOREIGN KEY (`receive_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_retained_bundle_id_foreign` FOREIGN KEY (`retained_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_retained_qr_id_foreign` FOREIGN KEY (`retained_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_returned_bundle_id_foreign` FOREIGN KEY (`returned_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_returned_qr_id_foreign` FOREIGN KEY (`returned_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_review_id_foreign` FOREIGN KEY (`review_id`) REFERENCES `legacy_retained_child_return_reviews` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_source_bundle_id_foreign` FOREIGN KEY (`source_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_postings_source_qr_id_foreign` FOREIGN KEY (`source_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_retained_child_return_reviews`
--

DROP TABLE IF EXISTS `legacy_retained_child_return_reviews`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_retained_child_return_reviews` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `predecessor_posting_id` bigint unsigned NOT NULL,
  `opening_row_id` bigint unsigned NOT NULL,
  `source_bundle_id` bigint unsigned NOT NULL,
  `source_qr_id` bigint unsigned NOT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `destination_warehouse_id` bigint unsigned NOT NULL,
  `source_pcs` bigint unsigned NOT NULL,
  `requested_return_pcs` bigint unsigned NOT NULL,
  `remaining_pcs` bigint unsigned NOT NULL,
  `condition` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `preparation_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `review_note` text COLLATE utf8mb4_unicode_ci,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `approved_contract_digest` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lrcr_maker_request_uq` (`maker_id`,`request_key`),
  UNIQUE KEY `lrcr_predecessor_uq` (`predecessor_posting_id`),
  UNIQUE KEY `lrcr_source_bundle_uq` (`source_bundle_id`),
  KEY `legacy_retained_child_return_reviews_opening_row_id_foreign` (`opening_row_id`),
  KEY `legacy_retained_child_return_reviews_source_qr_id_foreign` (`source_qr_id`),
  KEY `legacy_retained_child_return_reviews_destination_warehouse_fk` (`destination_warehouse_id`),
  KEY `legacy_retained_child_return_reviews_checker_id_foreign` (`checker_id`),
  KEY `lrcr_origin_status_idx` (`origin_warehouse_id`,`status`),
  CONSTRAINT `legacy_retained_child_return_reviews_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_return_reviews_destination_warehouse_fk` FOREIGN KEY (`destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_return_reviews_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_return_reviews_opening_row_id_foreign` FOREIGN KEY (`opening_row_id`) REFERENCES `nonstore_opening_rows` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_return_reviews_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_return_reviews_predecessor_posting_fk` FOREIGN KEY (`predecessor_posting_id`) REFERENCES `legacy_partial_return_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_return_reviews_source_bundle_id_foreign` FOREIGN KEY (`source_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_retained_child_return_reviews_source_qr_id_foreign` FOREIGN KEY (`source_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_transit_repair_posting_authorizations`
--

DROP TABLE IF EXISTS `legacy_transit_repair_posting_authorizations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_transit_repair_posting_authorizations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `receipt_plan_id` bigint unsigned NOT NULL,
  `authorizer_id` bigint unsigned NOT NULL,
  `verified_pcs` bigint unsigned NOT NULL,
  `receipt_reviewer_id` bigint unsigned NOT NULL,
  `review_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `authorization_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `authorization_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'authorized',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ltrpa_receipt_plan_id_uq` (`receipt_plan_id`),
  KEY `ltr_post_auth_actor_fk` (`authorizer_id`),
  KEY `ltr_post_auth_reviewer_fk` (`receipt_reviewer_id`),
  CONSTRAINT `ltr_post_auth_actor_fk` FOREIGN KEY (`authorizer_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `ltr_post_auth_plan_fk` FOREIGN KEY (`receipt_plan_id`) REFERENCES `legacy_transit_repair_receipt_plans` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `ltr_post_auth_reviewer_fk` FOREIGN KEY (`receipt_reviewer_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `legacy_transit_repair_receipt_plans`
--

DROP TABLE IF EXISTS `legacy_transit_repair_receipt_plans`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `legacy_transit_repair_receipt_plans` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `opening_row_id` bigint unsigned NOT NULL,
  `evidence_link_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `old_qr_id` bigint unsigned NOT NULL,
  `opening_ledger_id` bigint unsigned NOT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `destination_warehouse_id` bigint unsigned NOT NULL,
  `intent` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `destination_bucket` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'label_hold',
  `arrival_condition` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evidence_snapshot` json NOT NULL,
  `physical_receipt_note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `checker_verified_pcs` bigint unsigned DEFAULT NULL,
  `review_note` text COLLATE utf8mb4_unicode_ci,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `new_qr_id` bigint unsigned DEFAULT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `legacy_transit_repair_receipt_plans_opening_row_id_unique` (`opening_row_id`),
  UNIQUE KEY `legacy_transit_repair_receipt_plans_request_key_unique` (`request_key`),
  UNIQUE KEY `ltr_receipt_new_qr_uq` (`new_qr_id`),
  UNIQUE KEY `ltr_receipt_ledger_uq` (`ledger_id`),
  KEY `legacy_transit_repair_receipt_plans_evidence_link_id_foreign` (`evidence_link_id`),
  KEY `legacy_transit_repair_receipt_plans_bundle_id_foreign` (`bundle_id`),
  KEY `legacy_transit_repair_receipt_plans_old_qr_id_foreign` (`old_qr_id`),
  KEY `legacy_transit_repair_receipt_plans_opening_ledger_id_foreign` (`opening_ledger_id`),
  KEY `ltr_receipt_destination_fk` (`destination_warehouse_id`),
  KEY `legacy_transit_repair_receipt_plans_maker_id_foreign` (`maker_id`),
  KEY `legacy_transit_repair_receipt_plans_checker_id_foreign` (`checker_id`),
  KEY `legacy_transit_receipt_scope_idx` (`origin_warehouse_id`,`status`),
  KEY `legacy_transit_repair_receipt_plans_status_index` (`status`),
  CONSTRAINT `legacy_transit_repair_receipt_plans_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_transit_repair_receipt_plans_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_transit_repair_receipt_plans_evidence_link_id_foreign` FOREIGN KEY (`evidence_link_id`) REFERENCES `legacy_custody_evidence_links` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_transit_repair_receipt_plans_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_transit_repair_receipt_plans_old_qr_id_foreign` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_transit_repair_receipt_plans_opening_ledger_id_foreign` FOREIGN KEY (`opening_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_transit_repair_receipt_plans_opening_row_id_foreign` FOREIGN KEY (`opening_row_id`) REFERENCES `nonstore_opening_rows` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `legacy_transit_repair_receipt_plans_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `ltr_receipt_destination_fk` FOREIGN KEY (`destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `ltr_receipt_ledger_fk` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `ltr_receipt_new_qr_fk` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `migrations`
--

DROP TABLE IF EXISTS `migrations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `migrations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `mixed_repair_atomic_batch_lines`
--

DROP TABLE IF EXISTS `mixed_repair_atomic_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `mixed_repair_atomic_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `atomic_batch_id` bigint unsigned NOT NULL,
  `outcome_batch_id` bigint unsigned NOT NULL,
  `reinspection_id` bigint unsigned NOT NULL,
  `source_bundle_id` bigint unsigned NOT NULL,
  `reinspection_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `mrabl_group_line_uq` (`atomic_batch_id`,`outcome_batch_id`),
  UNIQUE KEY `mrabl_outcome_once_uq` (`outcome_batch_id`),
  UNIQUE KEY `mrabl_reinspection_once_uq` (`reinspection_id`),
  KEY `mixed_repair_atomic_batch_lines_source_bundle_id_foreign` (`source_bundle_id`),
  CONSTRAINT `mixed_repair_atomic_batch_lines_atomic_batch_id_foreign` FOREIGN KEY (`atomic_batch_id`) REFERENCES `mixed_repair_atomic_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mixed_repair_atomic_batch_lines_outcome_batch_id_foreign` FOREIGN KEY (`outcome_batch_id`) REFERENCES `repair_outcome_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mixed_repair_atomic_batch_lines_reinspection_id_foreign` FOREIGN KEY (`reinspection_id`) REFERENCES `repair_fractional_reinspections` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mixed_repair_atomic_batch_lines_source_bundle_id_foreign` FOREIGN KEY (`source_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `mixed_repair_atomic_batches`
--

DROP TABLE IF EXISTS `mixed_repair_atomic_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `mixed_repair_atomic_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `repair_job_id` bigint unsigned NOT NULL,
  `batch_count` smallint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `plan_manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `reinspected_by` bigint unsigned NOT NULL,
  `reinspected_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `mrab_request_seal_uq` (`request_sha256`),
  KEY `mixed_repair_atomic_batches_repair_job_id_foreign` (`repair_job_id`),
  KEY `mixed_repair_atomic_batches_reinspected_by_foreign` (`reinspected_by`),
  CONSTRAINT `mixed_repair_atomic_batches_reinspected_by_foreign` FOREIGN KEY (`reinspected_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mixed_repair_atomic_batches_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `multi_document_condition_batch_lines`
--

DROP TABLE IF EXISTS `multi_document_condition_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `multi_document_condition_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `request_id` bigint unsigned NOT NULL,
  `posting_id` bigint unsigned NOT NULL,
  `source_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `inverse_ledger_id` bigint unsigned NOT NULL,
  `replacement_ledger_id` bigint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `mdcbl_request_uq` (`request_id`),
  UNIQUE KEY `mdcbl_post_uq` (`posting_id`),
  KEY `mdcbl_original_fk` (`original_ledger_id`),
  KEY `mdcbl_inverse_fk` (`inverse_ledger_id`),
  KEY `mdcbl_replace_fk` (`replacement_ledger_id`),
  KEY `mdcbl_batch_source_idx` (`batch_id`,`source_id`),
  CONSTRAINT `mdcbl_batch_fk` FOREIGN KEY (`batch_id`) REFERENCES `multi_document_condition_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mdcbl_inverse_fk` FOREIGN KEY (`inverse_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mdcbl_original_fk` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mdcbl_post_fk` FOREIGN KEY (`posting_id`) REFERENCES `posted_condition_amendment_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mdcbl_replace_fk` FOREIGN KEY (`replacement_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `mdcbl_request_fk` FOREIGN KEY (`request_id`) REFERENCES `posted_condition_amendment_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `multi_document_condition_batches`
--

DROP TABLE IF EXISTS `multi_document_condition_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `multi_document_condition_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `family` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_group_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `line_count` smallint unsigned NOT NULL,
  `total_quantity_pcs` bigint unsigned NOT NULL,
  `requests_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `mdcb_group_seal_uq` (`family`,`source_group_id`,`requests_sha256`),
  KEY `multi_document_condition_batches_warehouse_id_foreign` (`warehouse_id`),
  KEY `multi_document_condition_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `multi_document_condition_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `multi_document_condition_batches_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `multi_outward_return_batch_lines`
--

DROP TABLE IF EXISTS `multi_outward_return_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `multi_outward_return_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `return_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `ledger_ids_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `multi_return_document_once_uq` (`return_id`),
  UNIQUE KEY `multi_return_batch_line_uq` (`batch_id`,`return_id`),
  CONSTRAINT `multi_outward_return_batch_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `multi_outward_return_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `multi_outward_return_batch_lines_return_id_foreign` FOREIGN KEY (`return_id`) REFERENCES `stock_out_returns` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `multi_outward_return_batches`
--

DROP TABLE IF EXISTS `multi_outward_return_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `multi_outward_return_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_out_id` bigint unsigned NOT NULL,
  `return_count` smallint unsigned NOT NULL,
  `total_quantity_pcs` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `multi_return_batch_seal_uq` (`stock_out_id`,`request_sha256`),
  KEY `multi_outward_return_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `multi_outward_return_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `multi_outward_return_batches_stock_out_id_foreign` FOREIGN KEY (`stock_out_id`) REFERENCES `stock_out` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `nonstore_opening_batches`
--

DROP TABLE IF EXISTS `nonstore_opening_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `nonstore_opening_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_no` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `cutoff_date` date NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'staged',
  `maker_id` bigint unsigned NOT NULL,
  `counted_by` bigint unsigned DEFAULT NULL,
  `verified_by` bigint unsigned DEFAULT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `approved_digest` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `submitted_at` timestamp NULL DEFAULT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `nonstore_opening_batches_batch_no_unique` (`batch_no`),
  KEY `nonstore_opening_batches_maker_id_foreign` (`maker_id`),
  KEY `nonstore_opening_batches_counted_by_foreign` (`counted_by`),
  KEY `nonstore_opening_batches_verified_by_foreign` (`verified_by`),
  KEY `nonstore_opening_batches_checker_id_foreign` (`checker_id`),
  KEY `nonstore_opening_batches_status_index` (`status`),
  CONSTRAINT `nonstore_opening_batches_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `nonstore_opening_batches_counted_by_foreign` FOREIGN KEY (`counted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `nonstore_opening_batches_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `nonstore_opening_batches_verified_by_foreign` FOREIGN KEY (`verified_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `nonstore_opening_rows`
--

DROP TABLE IF EXISTS `nonstore_opening_rows`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `nonstore_opening_rows` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `row_no` int unsigned NOT NULL,
  `legacy_ref` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `origin_warehouse_id` bigint unsigned NOT NULL,
  `custody_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `custody_id` bigint unsigned DEFAULT NULL,
  `custodian_reference` varchar(160) COLLATE utf8mb4_unicode_ci NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `verified_pcs` bigint unsigned DEFAULT NULL,
  `condition` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'good',
  `row_digest` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'staged',
  `bundle_id` bigint unsigned DEFAULT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `nonstore_opening_rows_batch_id_row_no_unique` (`batch_id`,`row_no`),
  UNIQUE KEY `nonstore_opening_rows_legacy_ref_unique` (`legacy_ref`),
  UNIQUE KEY `nonstore_opening_rows_bundle_id_unique` (`bundle_id`),
  UNIQUE KEY `nonstore_opening_rows_ledger_id_unique` (`ledger_id`),
  KEY `nonstore_opening_rows_product_id_foreign` (`product_id`),
  KEY `nonstore_origin_custody_status_idx` (`origin_warehouse_id`,`custody_type`,`status`),
  KEY `nonstore_opening_rows_status_index` (`status`),
  CONSTRAINT `nonstore_opening_rows_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `nonstore_opening_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `nonstore_opening_rows_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `nonstore_opening_rows_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `nonstore_opening_rows_origin_warehouse_id_foreign` FOREIGN KEY (`origin_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `nonstore_opening_rows_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `opening_import_batches`
--

DROP TABLE IF EXISTS `opening_import_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `opening_import_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_no` varchar(75) COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_filename` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `file_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `cutoff_date` date NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'staged',
  `row_count` int unsigned NOT NULL DEFAULT '0',
  `total_pcs` bigint unsigned NOT NULL DEFAULT '0',
  `maker_id` bigint unsigned NOT NULL,
  `counted_by` bigint unsigned DEFAULT NULL,
  `verified_by` bigint unsigned DEFAULT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `submitted_at` timestamp NULL DEFAULT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `notes` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `opening_import_batches_batch_no_unique` (`batch_no`),
  UNIQUE KEY `opening_import_batches_file_sha256_unique` (`file_sha256`),
  KEY `opening_import_batches_maker_id_foreign` (`maker_id`),
  KEY `opening_import_batches_counted_by_foreign` (`counted_by`),
  KEY `opening_import_batches_verified_by_foreign` (`verified_by`),
  KEY `opening_import_batches_checker_id_foreign` (`checker_id`),
  KEY `opening_import_batches_status_index` (`status`),
  CONSTRAINT `opening_import_batches_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `opening_import_batches_counted_by_foreign` FOREIGN KEY (`counted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `opening_import_batches_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `opening_import_batches_verified_by_foreign` FOREIGN KEY (`verified_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `opening_import_rows`
--

DROP TABLE IF EXISTS `opening_import_rows`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `opening_import_rows` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `row_no` int unsigned NOT NULL,
  `legacy_ref` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sku` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `warehouse_code` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `raw_pcs` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `condition` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `original_source_ref` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `remarks` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `row_fingerprint` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `validation_errors` json DEFAULT NULL,
  `product_id` bigint unsigned DEFAULT NULL,
  `warehouse_id` bigint unsigned DEFAULT NULL,
  `quantity_pcs` bigint unsigned DEFAULT NULL,
  `verified_pcs` bigint unsigned DEFAULT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'staged',
  `bundle_id` bigint unsigned DEFAULT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `opening_import_rows_batch_id_row_no_unique` (`batch_id`,`row_no`),
  UNIQUE KEY `opening_import_rows_batch_id_legacy_ref_unique` (`batch_id`,`legacy_ref`),
  UNIQUE KEY `opening_import_rows_bundle_id_unique` (`bundle_id`),
  UNIQUE KEY `opening_import_rows_ledger_id_unique` (`ledger_id`),
  KEY `opening_import_rows_product_id_foreign` (`product_id`),
  KEY `opening_import_rows_warehouse_id_foreign` (`warehouse_id`),
  KEY `opening_import_rows_legacy_ref_status_index` (`legacy_ref`,`status`),
  CONSTRAINT `opening_import_rows_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `opening_import_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `opening_import_rows_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `opening_import_rows_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `opening_import_rows_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `opening_import_rows_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `opening_legacy_claims`
--

DROP TABLE IF EXISTS `opening_legacy_claims`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `opening_legacy_claims` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `legacy_ref` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `row_id` bigint unsigned NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `opening_legacy_claims_legacy_ref_unique` (`legacy_ref`),
  UNIQUE KEY `opening_legacy_claims_row_id_unique` (`row_id`),
  CONSTRAINT `opening_legacy_claims_row_id_foreign` FOREIGN KEY (`row_id`) REFERENCES `opening_import_rows` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `opening_legacy_registry`
--

DROP TABLE IF EXISTS `opening_legacy_registry`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `opening_legacy_registry` (
  `legacy_ref` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_row_id` bigint unsigned NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`legacy_ref`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `operational_alerts`
--

DROP TABLE IF EXISTS `operational_alerts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `operational_alerts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `category` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
  `severity` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'info',
  `title` varchar(160) COLLATE utf8mb4_unicode_ci NOT NULL,
  `message` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `reference_type` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reference_id` bigint unsigned DEFAULT NULL,
  `read_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `operational_alerts_user_id_read_at_id_index` (`user_id`,`read_at`,`id`),
  CONSTRAINT `operational_alerts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `outstanding_transit_atomic_batches`
--

DROP TABLE IF EXISTS `outstanding_transit_atomic_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `outstanding_transit_atomic_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` bigint unsigned NOT NULL,
  `member_count` int unsigned NOT NULL,
  `newly_received_pcs` bigint unsigned NOT NULL,
  `manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `outstanding_transit_atomic_batches_warehouse_id_foreign` (`warehouse_id`),
  KEY `outstanding_transit_atomic_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `outstanding_transit_atomic_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_atomic_batches_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `outstanding_transit_atomic_members`
--

DROP TABLE IF EXISTS `outstanding_transit_atomic_members`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `outstanding_transit_atomic_members` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `request_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `ancestry_anchor_id` bigint unsigned NOT NULL,
  `posting_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `receipt_ledger_id` bigint unsigned NOT NULL,
  `received_pcs` bigint unsigned NOT NULL,
  `member_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ota_anchor_uq` (`ancestry_anchor_id`),
  KEY `outstanding_transit_atomic_members_batch_id_foreign` (`batch_id`),
  KEY `outstanding_transit_atomic_members_request_id_foreign` (`request_id`),
  KEY `outstanding_transit_atomic_members_transfer_id_foreign` (`transfer_id`),
  KEY `outstanding_transit_atomic_members_bundle_id_foreign` (`bundle_id`),
  KEY `outstanding_transit_atomic_members_posting_id_foreign` (`posting_id`),
  KEY `outstanding_transit_atomic_members_receipt_id_foreign` (`receipt_id`),
  KEY `outstanding_transit_atomic_members_receipt_ledger_id_foreign` (`receipt_ledger_id`),
  CONSTRAINT `ota_anchor_fk` FOREIGN KEY (`ancestry_anchor_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_atomic_members_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `outstanding_transit_atomic_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_atomic_members_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_atomic_members_posting_id_foreign` FOREIGN KEY (`posting_id`) REFERENCES `outstanding_transit_receipt_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_atomic_members_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_atomic_members_receipt_ledger_id_foreign` FOREIGN KEY (`receipt_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_atomic_members_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `outstanding_transit_receipt_requests` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_atomic_members_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `outstanding_transit_receipt_approvals`
--

DROP TABLE IF EXISTS `outstanding_transit_receipt_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `outstanding_transit_receipt_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `outstanding_transit_receipt_approvals_request_id_foreign` (`request_id`),
  KEY `outstanding_transit_receipt_approvals_checker_id_foreign` (`checker_id`),
  CONSTRAINT `outstanding_transit_receipt_approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_approvals_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `outstanding_transit_receipt_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `outstanding_transit_receipt_postings`
--

DROP TABLE IF EXISTS `outstanding_transit_receipt_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `outstanding_transit_receipt_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `receipt_ledger_id` bigint unsigned NOT NULL,
  `dispatch_ledger_id` bigint unsigned NOT NULL,
  `before_received_pcs` bigint unsigned NOT NULL,
  `after_received_pcs` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `receipt_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `outstanding_receipt_posting_once` (`transfer_id`,`bundle_id`),
  KEY `outstanding_transit_receipt_postings_request_id_foreign` (`request_id`),
  KEY `outstanding_transit_receipt_postings_bundle_id_foreign` (`bundle_id`),
  KEY `outstanding_transit_receipt_postings_receipt_id_foreign` (`receipt_id`),
  KEY `outstanding_transit_receipt_postings_receipt_ledger_id_foreign` (`receipt_ledger_id`),
  KEY `outstanding_transit_receipt_postings_dispatch_ledger_id_foreign` (`dispatch_ledger_id`),
  KEY `outstanding_transit_receipt_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `outstanding_transit_receipt_postings_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_postings_dispatch_ledger_id_foreign` FOREIGN KEY (`dispatch_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_postings_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_postings_receipt_ledger_id_foreign` FOREIGN KEY (`receipt_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_postings_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `outstanding_transit_receipt_requests` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_postings_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `outstanding_transit_receipt_requests`
--

DROP TABLE IF EXISTS `outstanding_transit_receipt_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `outstanding_transit_receipt_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `condition` varchar(12) COLLATE utf8mb4_unicode_ci NOT NULL,
  `expected_pcs` bigint unsigned NOT NULL,
  `source_snapshot` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `outstanding_receipt_request_once` (`transfer_id`,`bundle_id`),
  KEY `outstanding_transit_receipt_requests_bundle_id_foreign` (`bundle_id`),
  KEY `outstanding_transit_receipt_requests_warehouse_id_foreign` (`warehouse_id`),
  KEY `outstanding_transit_receipt_requests_maker_id_foreign` (`maker_id`),
  CONSTRAINT `outstanding_transit_receipt_requests_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_requests_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_requests_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `outstanding_transit_receipt_requests_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `permission_role`
--

DROP TABLE IF EXISTS `permission_role`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `permission_role` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `permission_id` bigint unsigned NOT NULL,
  `role_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `permission_role_permission_id_role_id_unique` (`permission_id`,`role_id`),
  KEY `permission_role_role_id_foreign` (`role_id`),
  CONSTRAINT `permission_role_permission_id_foreign` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `permission_role_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `permissions`
--

DROP TABLE IF EXISTS `permissions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `permissions` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `group_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `permissions_slug_unique` (`slug`),
  KEY `permissions_group_name_index` (`group_name`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `posted_condition_amendment_approvals`
--

DROP TABLE IF EXISTS `posted_condition_amendment_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `posted_condition_amendment_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `pcaa_request_uq` (`request_id`),
  KEY `posted_condition_amendment_approvals_checker_id_foreign` (`checker_id`),
  CONSTRAINT `posted_condition_amendment_approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_condition_amendment_approvals_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `posted_condition_amendment_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `posted_condition_amendment_postings`
--

DROP TABLE IF EXISTS `posted_condition_amendment_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `posted_condition_amendment_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `family` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `inverse_ledger_id` bigint unsigned NOT NULL,
  `replacement_ledger_id` bigint unsigned NOT NULL,
  `old_condition` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `new_condition` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `pcap_family_source_uq` (`family`,`source_id`),
  UNIQUE KEY `pcap_request_uq` (`request_id`),
  UNIQUE KEY `pcap_original_ledger_uq` (`original_ledger_id`),
  UNIQUE KEY `pcap_inverse_ledger_uq` (`inverse_ledger_id`),
  UNIQUE KEY `pcap_new_ledger_uq` (`replacement_ledger_id`),
  KEY `posted_condition_amendment_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `pcap_new_ledger_fk` FOREIGN KEY (`replacement_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_condition_amendment_postings_inverse_ledger_id_foreign` FOREIGN KEY (`inverse_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_condition_amendment_postings_original_ledger_id_foreign` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_condition_amendment_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_condition_amendment_postings_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `posted_condition_amendment_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `posted_condition_amendment_requests`
--

DROP TABLE IF EXISTS `posted_condition_amendment_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `posted_condition_amendment_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `family` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `old_condition` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `new_condition` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_snapshot` json NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `pcar_family_source_uq` (`family`,`source_id`),
  UNIQUE KEY `pcar_original_ledger_uq` (`original_ledger_id`),
  KEY `posted_condition_amendment_requests_bundle_id_foreign` (`bundle_id`),
  KEY `posted_condition_amendment_requests_warehouse_id_foreign` (`warehouse_id`),
  KEY `posted_condition_amendment_requests_maker_id_foreign` (`maker_id`),
  CONSTRAINT `posted_condition_amendment_requests_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_condition_amendment_requests_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_condition_amendment_requests_original_ledger_id_foreign` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_condition_amendment_requests_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `posted_repair_quantity_approvals`
--

DROP TABLE IF EXISTS `posted_repair_quantity_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `posted_repair_quantity_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `prqa_request_uq` (`request_id`),
  KEY `posted_repair_quantity_approvals_checker_id_foreign` (`checker_id`),
  CONSTRAINT `posted_repair_quantity_approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_approvals_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `posted_repair_quantity_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `posted_repair_quantity_posting_lines`
--

DROP TABLE IF EXISTS `posted_repair_quantity_posting_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `posted_repair_quantity_posting_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `posting_id` bigint unsigned NOT NULL,
  `line_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `inverse_ledger_id` bigint unsigned NOT NULL,
  `replacement_ledger_id` bigint unsigned NOT NULL,
  `split_ledger_id` bigint unsigned NOT NULL,
  `relation_id` bigint unsigned NOT NULL,
  `balance_id` bigint unsigned NOT NULL,
  `outcome` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `before_pcs` bigint unsigned NOT NULL,
  `after_pcs` bigint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `prqpl_line_uq` (`line_id`),
  UNIQUE KEY `prqpl_original_uq` (`original_ledger_id`),
  UNIQUE KEY `prqpl_inverse_uq` (`inverse_ledger_id`),
  UNIQUE KEY `prqpl_replacement_uq` (`replacement_ledger_id`),
  KEY `posted_repair_quantity_posting_lines_posting_id_foreign` (`posting_id`),
  KEY `posted_repair_quantity_posting_lines_bundle_id_foreign` (`bundle_id`),
  KEY `posted_repair_quantity_posting_lines_split_ledger_id_foreign` (`split_ledger_id`),
  KEY `posted_repair_quantity_posting_lines_relation_id_foreign` (`relation_id`),
  KEY `posted_repair_quantity_posting_lines_balance_id_foreign` (`balance_id`),
  CONSTRAINT `posted_repair_quantity_posting_lines_balance_id_foreign` FOREIGN KEY (`balance_id`) REFERENCES `stock_balances` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_posting_lines_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_posting_lines_inverse_ledger_id_foreign` FOREIGN KEY (`inverse_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_posting_lines_line_id_foreign` FOREIGN KEY (`line_id`) REFERENCES `repair_outcome_lines` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_posting_lines_original_ledger_id_foreign` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_posting_lines_posting_id_foreign` FOREIGN KEY (`posting_id`) REFERENCES `posted_repair_quantity_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_posting_lines_relation_id_foreign` FOREIGN KEY (`relation_id`) REFERENCES `bundle_relations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_posting_lines_replacement_ledger_fk` FOREIGN KEY (`replacement_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_posting_lines_split_ledger_id_foreign` FOREIGN KEY (`split_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `posted_repair_quantity_postings`
--

DROP TABLE IF EXISTS `posted_repair_quantity_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `posted_repair_quantity_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `batch_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `before_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `after_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `old_good_pcs` bigint unsigned NOT NULL,
  `old_damaged_pcs` bigint unsigned NOT NULL,
  `new_good_pcs` bigint unsigned NOT NULL,
  `new_damaged_pcs` bigint unsigned NOT NULL,
  `ledger_operation_id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `prqp_request_uq` (`request_id`),
  UNIQUE KEY `prqp_batch_uq` (`batch_id`),
  KEY `posted_repair_quantity_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `posted_repair_quantity_postings_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `repair_outcome_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_postings_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `posted_repair_quantity_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `posted_repair_quantity_requests`
--

DROP TABLE IF EXISTS `posted_repair_quantity_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `posted_repair_quantity_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `repair_job_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `new_good_pcs` bigint unsigned NOT NULL,
  `new_damaged_pcs` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_snapshot` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `prqr_batch_uq` (`batch_id`),
  KEY `posted_repair_quantity_requests_repair_job_id_foreign` (`repair_job_id`),
  KEY `posted_repair_quantity_requests_warehouse_id_foreign` (`warehouse_id`),
  KEY `posted_repair_quantity_requests_maker_id_foreign` (`maker_id`),
  CONSTRAINT `posted_repair_quantity_requests_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `repair_outcome_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_requests_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_requests_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `posted_repair_quantity_requests_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_qr_codes`
--

DROP TABLE IF EXISTS `product_qr_codes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_qr_codes` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `bundle_id` bigint unsigned NOT NULL,
  `token_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `token_encrypted` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `version` int unsigned NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'generated',
  `print_state` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending',
  `generated_by` bigint unsigned DEFAULT NULL,
  `retired_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `product_qr_codes_bundle_id_version_unique` (`bundle_id`,`version`),
  UNIQUE KEY `product_qr_codes_token_hash_unique` (`token_hash`),
  KEY `product_qr_codes_generated_by_foreign` (`generated_by`),
  KEY `product_qr_codes_bundle_id_status_index` (`bundle_id`,`status`),
  KEY `product_qr_codes_status_index` (`status`),
  KEY `product_qr_codes_print_state_index` (`print_state`),
  CONSTRAINT `product_qr_codes_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `product_qr_codes_generated_by_foreign` FOREIGN KEY (`generated_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_standard_costs`
--

DROP TABLE IF EXISTS `product_standard_costs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_standard_costs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `product_id` bigint unsigned NOT NULL,
  `unit_cost_bdt` decimal(18,4) NOT NULL,
  `basis` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'approved_standard',
  `approved_by` bigint unsigned NOT NULL,
  `approved_at` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `product_standard_costs_product_id_unique` (`product_id`),
  KEY `product_standard_costs_approved_by_foreign` (`approved_by`),
  CONSTRAINT `product_standard_costs_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `product_standard_costs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `product_warehouse_settings`
--

DROP TABLE IF EXISTS `product_warehouse_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `product_warehouse_settings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `product_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `minimum_stock_pcs` bigint unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `product_warehouse_settings_uq` (`product_id`,`warehouse_id`),
  KEY `product_warehouse_settings_warehouse_id_is_active_index` (`warehouse_id`,`is_active`),
  KEY `product_warehouse_settings_is_active_index` (`is_active`),
  CONSTRAINT `product_warehouse_settings_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `product_warehouse_settings_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `products`
--

DROP TABLE IF EXISTS `products`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `products` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sku` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
  `category_id` bigint unsigned DEFAULT NULL,
  `specification` json DEFAULT NULL,
  `photo_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `unit` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Pcs',
  `tracking_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Bundle',
  `default_pcs_per_bundle` bigint unsigned DEFAULT NULL,
  `minimum_stock_pcs` bigint unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `products_sku_unique` (`sku`),
  KEY `products_category_id_is_active_index` (`category_id`,`is_active`),
  KEY `products_is_active_index` (`is_active`),
  CONSTRAINT `products_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `project_user`
--

DROP TABLE IF EXISTS `project_user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `project_user` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `project_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `assigned_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `project_user_project_id_user_id_unique` (`project_id`,`user_id`),
  KEY `project_user_assigned_by_foreign` (`assigned_by`),
  KEY `project_user_user_id_project_id_index` (`user_id`,`project_id`),
  CONSTRAINT `project_user_assigned_by_foreign` FOREIGN KEY (`assigned_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `project_user_project_id_foreign` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `project_user_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `projects`
--

DROP TABLE IF EXISTS `projects`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `projects` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `project_code` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `projects_project_code_unique` (`project_code`),
  KEY `projects_status_index` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `qr_code_history`
--

DROP TABLE IF EXISTS `qr_code_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `qr_code_history` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `bundle_id` bigint unsigned NOT NULL,
  `old_qr_id` bigint unsigned DEFAULT NULL,
  `new_qr_id` bigint unsigned DEFAULT NULL,
  `event_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `reason` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `actor_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `qr_code_history_old_qr_id_foreign` (`old_qr_id`),
  KEY `qr_code_history_new_qr_id_foreign` (`new_qr_id`),
  KEY `qr_code_history_actor_id_foreign` (`actor_id`),
  KEY `qr_code_history_bundle_id_created_at_index` (`bundle_id`,`created_at`),
  KEY `qr_history_legacy_return_proof_idx` (`bundle_id`,`old_qr_id`,`new_qr_id`,`event_type`),
  CONSTRAINT `qr_code_history_actor_id_foreign` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `qr_code_history_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `qr_code_history_new_qr_id_foreign` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `qr_code_history_old_qr_id_foreign` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `qr_scan_logs`
--

DROP TABLE IF EXISTS `qr_scan_logs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `qr_scan_logs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `qr_code_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `result` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `scan_source` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'qr_url_open',
  `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` text COLLATE utf8mb4_unicode_ci,
  `scanned_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `qr_scan_logs_user_id_foreign` (`user_id`),
  KEY `qr_scan_user_time_idx` (`qr_code_id`,`user_id`,`scanned_at`),
  KEY `qr_scan_logs_bundle_id_scanned_at_index` (`bundle_id`,`scanned_at`),
  KEY `qr_scan_logs_result_index` (`result`),
  CONSTRAINT `qr_scan_logs_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `qr_scan_logs_qr_code_id_foreign` FOREIGN KEY (`qr_code_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `qr_scan_logs_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `received_repair_atomic_batch_lines`
--

DROP TABLE IF EXISTS `received_repair_atomic_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `received_repair_atomic_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `family` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_id` bigint unsigned NOT NULL,
  `posting_id` bigint unsigned NOT NULL,
  `source_document_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `before_pcs` bigint unsigned NOT NULL,
  `after_pcs` bigint unsigned NOT NULL,
  `journal_count` tinyint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `received_repair_batch_request_unique` (`family`,`request_id`),
  UNIQUE KEY `received_repair_batch_posting_unique` (`family`,`posting_id`),
  UNIQUE KEY `received_repair_batch_root_unique` (`batch_id`,`root_bundle_id`),
  KEY `received_repair_atomic_batch_lines_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `received_repair_atomic_batch_lines_warehouse_id_foreign` (`warehouse_id`),
  CONSTRAINT `received_repair_atomic_batch_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `received_repair_atomic_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_repair_atomic_batch_lines_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_repair_atomic_batch_lines_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `received_repair_atomic_batches`
--

DROP TABLE IF EXISTS `received_repair_atomic_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `received_repair_atomic_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` tinyint unsigned NOT NULL DEFAULT '1',
  `line_count` tinyint unsigned NOT NULL,
  `request_manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `received_repair_atomic_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `received_repair_atomic_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `received_transit_multi_batch_lines`
--

DROP TABLE IF EXISTS `received_transit_multi_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `received_transit_multi_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `request_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `posting_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `before_pcs` bigint unsigned NOT NULL,
  `after_pcs` bigint unsigned NOT NULL,
  `journal_count` tinyint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `rtmbl_batch_request_once` (`batch_id`,`request_id`),
  UNIQUE KEY `rtmbl_request_once` (`request_id`),
  UNIQUE KEY `rtmbl_transfer_once` (`transfer_id`),
  UNIQUE KEY `rtmbl_posting_once` (`posting_id`),
  KEY `received_transit_multi_batch_lines_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `received_transit_multi_batch_lines_warehouse_id_foreign` (`warehouse_id`),
  CONSTRAINT `received_transit_multi_batch_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `received_transit_multi_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_multi_batch_lines_posting_id_foreign` FOREIGN KEY (`posting_id`) REFERENCES `received_transit_reallocation_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_multi_batch_lines_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `received_transit_reallocation_requests` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_multi_batch_lines_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_multi_batch_lines_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_multi_batch_lines_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `received_transit_multi_batches`
--

DROP TABLE IF EXISTS `received_transit_multi_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `received_transit_multi_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` tinyint unsigned NOT NULL DEFAULT '1',
  `request_count` tinyint unsigned NOT NULL,
  `manifest_json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `manifest_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_proof_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `rtmb_manifest_once` (`manifest_sha256`),
  UNIQUE KEY `rtmb_proof_once` (`posting_proof_sha256`),
  KEY `received_transit_multi_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `received_transit_multi_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `received_transit_reallocation_approvals`
--

DROP TABLE IF EXISTS `received_transit_reallocation_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `received_transit_reallocation_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `received_transit_reallocation_approvals_request_id_foreign` (`request_id`),
  KEY `received_transit_reallocation_approvals_checker_id_foreign` (`checker_id`),
  CONSTRAINT `received_transit_reallocation_approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_approvals_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `received_transit_reallocation_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `received_transit_reallocation_lines`
--

DROP TABLE IF EXISTS `received_transit_reallocation_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `received_transit_reallocation_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `posting_id` bigint unsigned NOT NULL,
  `receipt_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `relation_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `inverse_ledger_id` bigint unsigned NOT NULL,
  `replacement_ledger_id` bigint unsigned NOT NULL,
  `label_hold_ledger_id` bigint unsigned NOT NULL,
  `old_qr_id` bigint unsigned NOT NULL,
  `new_qr_id` bigint unsigned NOT NULL,
  `before_pcs` bigint unsigned NOT NULL,
  `after_pcs` bigint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `received_reallocation_posting_bundle_unique` (`posting_id`,`bundle_id`),
  KEY `received_transit_reallocation_lines_receipt_id_foreign` (`receipt_id`),
  KEY `received_transit_reallocation_lines_bundle_id_foreign` (`bundle_id`),
  KEY `received_transit_reallocation_lines_relation_id_foreign` (`relation_id`),
  KEY `received_transit_reallocation_lines_original_ledger_id_foreign` (`original_ledger_id`),
  KEY `received_transit_reallocation_lines_inverse_ledger_id_foreign` (`inverse_ledger_id`),
  KEY `received_transit_reallocation_lines_replacement_ledger_fk` (`replacement_ledger_id`),
  KEY `received_transit_reallocation_lines_label_hold_ledger_id_foreign` (`label_hold_ledger_id`),
  KEY `received_transit_reallocation_lines_old_qr_id_foreign` (`old_qr_id`),
  KEY `received_transit_reallocation_lines_new_qr_id_foreign` (`new_qr_id`),
  CONSTRAINT `received_transit_reallocation_lines_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_inverse_ledger_id_foreign` FOREIGN KEY (`inverse_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_label_hold_ledger_id_foreign` FOREIGN KEY (`label_hold_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_new_qr_id_foreign` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_old_qr_id_foreign` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_original_ledger_id_foreign` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_posting_id_foreign` FOREIGN KEY (`posting_id`) REFERENCES `received_transit_reallocation_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_transfer_receipts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_relation_id_foreign` FOREIGN KEY (`relation_id`) REFERENCES `bundle_relations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_lines_replacement_ledger_fk` FOREIGN KEY (`replacement_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `received_transit_reallocation_postings`
--

DROP TABLE IF EXISTS `received_transit_reallocation_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `received_transit_reallocation_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `before_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `after_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ledger_operation_id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `rtrp_ledger_operation_id_uq` (`ledger_operation_id`),
  KEY `received_transit_reallocation_postings_request_id_foreign` (`request_id`),
  KEY `received_transit_reallocation_postings_transfer_id_foreign` (`transfer_id`),
  KEY `received_transit_reallocation_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `received_transit_reallocation_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_postings_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `received_transit_reallocation_requests` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_postings_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `received_transit_reallocation_requests`
--

DROP TABLE IF EXISTS `received_transit_reallocation_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `received_transit_reallocation_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `target_quantities` json NOT NULL,
  `source_snapshot` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `received_transit_reallocation_requests_transfer_id_foreign` (`transfer_id`),
  KEY `received_transit_reallocation_requests_warehouse_id_foreign` (`warehouse_id`),
  KEY `received_transit_reallocation_requests_maker_id_foreign` (`maker_id`),
  CONSTRAINT `received_transit_reallocation_requests_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_requests_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `received_transit_reallocation_requests_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `repair_fractional_reinspections`
--

DROP TABLE IF EXISTS `repair_fractional_reinspections`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `repair_fractional_reinspections` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `repair_job_id` bigint unsigned NOT NULL,
  `batch_id` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `before_snapshot` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `after_snapshot` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `reinspected_by` bigint unsigned NOT NULL,
  `ledger_operation_id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `rfr_batch_uq` (`batch_id`),
  UNIQUE KEY `rfr_ledger_operation_uq` (`ledger_operation_id`),
  KEY `repair_fractional_reinspections_repair_job_id_foreign` (`repair_job_id`),
  KEY `repair_fractional_reinspections_reinspected_by_foreign` (`reinspected_by`),
  CONSTRAINT `repair_fractional_reinspections_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `repair_outcome_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_fractional_reinspections_reinspected_by_foreign` FOREIGN KEY (`reinspected_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_fractional_reinspections_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `repair_jobs`
--

DROP TABLE IF EXISTS `repair_jobs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `repair_jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `job_no` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `mode` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `repairer_name` varchar(180) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `expected_return_date` date DEFAULT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `dispatch_checker_id` bigint unsigned DEFAULT NULL,
  `dispatch_approved_at` timestamp NULL DEFAULT NULL,
  `dispatched_at` timestamp NULL DEFAULT NULL,
  `dispatch_qr_id` bigint unsigned DEFAULT NULL,
  `inspection_qr_id` bigint unsigned DEFAULT NULL,
  `dispatch_ledger_id` bigint unsigned DEFAULT NULL,
  `inspection_condition` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `inspection_note` text COLLATE utf8mb4_unicode_ci,
  `inspected_by` bigint unsigned DEFAULT NULL,
  `inspected_at` timestamp NULL DEFAULT NULL,
  `release_checker_id` bigint unsigned DEFAULT NULL,
  `release_approved_at` timestamp NULL DEFAULT NULL,
  `release_ledger_id` bigint unsigned DEFAULT NULL,
  `old_qr_id` bigint unsigned DEFAULT NULL,
  `new_qr_id` bigint unsigned DEFAULT NULL,
  `closed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `repair_jobs_job_no_unique` (`job_no`),
  UNIQUE KEY `repair_jobs_dispatch_ledger_id_unique` (`dispatch_ledger_id`),
  UNIQUE KEY `repair_jobs_release_ledger_id_unique` (`release_ledger_id`),
  KEY `repair_jobs_product_id_foreign` (`product_id`),
  KEY `repair_jobs_maker_id_foreign` (`maker_id`),
  KEY `repair_jobs_dispatch_checker_id_foreign` (`dispatch_checker_id`),
  KEY `repair_jobs_dispatch_qr_id_foreign` (`dispatch_qr_id`),
  KEY `repair_jobs_inspection_qr_id_foreign` (`inspection_qr_id`),
  KEY `repair_jobs_inspected_by_foreign` (`inspected_by`),
  KEY `repair_jobs_release_checker_id_foreign` (`release_checker_id`),
  KEY `repair_jobs_old_qr_id_foreign` (`old_qr_id`),
  KEY `repair_jobs_new_qr_id_foreign` (`new_qr_id`),
  KEY `repair_jobs_warehouse_id_status_expected_return_date_index` (`warehouse_id`,`status`,`expected_return_date`),
  KEY `repair_jobs_bundle_id_status_index` (`bundle_id`,`status`),
  KEY `repair_jobs_status_index` (`status`),
  CONSTRAINT `repair_jobs_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_dispatch_checker_id_foreign` FOREIGN KEY (`dispatch_checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_dispatch_ledger_id_foreign` FOREIGN KEY (`dispatch_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_dispatch_qr_id_foreign` FOREIGN KEY (`dispatch_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_inspected_by_foreign` FOREIGN KEY (`inspected_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_inspection_qr_id_foreign` FOREIGN KEY (`inspection_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_new_qr_id_foreign` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_old_qr_id_foreign` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_release_checker_id_foreign` FOREIGN KEY (`release_checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_release_ledger_id_foreign` FOREIGN KEY (`release_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_jobs_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `repair_movements`
--

DROP TABLE IF EXISTS `repair_movements`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `repair_movements` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `repair_job_id` bigint unsigned NOT NULL,
  `event_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `condition` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `actor_id` bigint unsigned NOT NULL,
  `note` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `repair_movements_ledger_id_unique` (`ledger_id`),
  KEY `repair_movements_actor_id_foreign` (`actor_id`),
  KEY `repair_movements_repair_job_id_created_at_index` (`repair_job_id`,`created_at`),
  CONSTRAINT `repair_movements_actor_id_foreign` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_movements_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_movements_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `repair_outcome_batches`
--

DROP TABLE IF EXISTS `repair_outcome_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `repair_outcome_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `repair_job_id` bigint unsigned NOT NULL,
  `batch_no` int unsigned NOT NULL,
  `source_bundle_id` bigint unsigned NOT NULL,
  `good_pcs` bigint unsigned NOT NULL,
  `damaged_pcs` bigint unsigned NOT NULL,
  `pending_pcs` bigint unsigned NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'inspected',
  `inspected_by` bigint unsigned NOT NULL,
  `approved_by` bigint unsigned DEFAULT NULL,
  `note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `repair_batch_no_unique` (`repair_job_id`,`batch_no`),
  KEY `repair_outcome_batches_source_bundle_id_foreign` (`source_bundle_id`),
  KEY `repair_outcome_batches_inspected_by_foreign` (`inspected_by`),
  KEY `repair_outcome_batches_approved_by_foreign` (`approved_by`),
  KEY `repair_outcome_batches_repair_job_id_status_index` (`repair_job_id`,`status`),
  CONSTRAINT `repair_outcome_batches_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_outcome_batches_inspected_by_foreign` FOREIGN KEY (`inspected_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_outcome_batches_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_outcome_batches_source_bundle_id_foreign` FOREIGN KEY (`source_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `repair_outcome_lines`
--

DROP TABLE IF EXISTS `repair_outcome_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `repair_outcome_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `inspection_qr_id` bigint unsigned NOT NULL,
  `outcome` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `return_qr_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `repair_batch_bundle_unique` (`batch_id`,`bundle_id`),
  UNIQUE KEY `repair_batch_outcome_unique` (`batch_id`,`outcome`),
  UNIQUE KEY `repair_outcome_lines_ledger_id_unique` (`ledger_id`),
  KEY `repair_outcome_lines_bundle_id_foreign` (`bundle_id`),
  KEY `repair_outcome_lines_inspection_qr_id_foreign` (`inspection_qr_id`),
  KEY `repair_outcome_lines_return_qr_id_foreign` (`return_qr_id`),
  CONSTRAINT `repair_outcome_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `repair_outcome_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_outcome_lines_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_outcome_lines_inspection_qr_id_foreign` FOREIGN KEY (`inspection_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_outcome_lines_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_outcome_lines_return_qr_id_foreign` FOREIGN KEY (`return_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `repair_preapproval_reallocations`
--

DROP TABLE IF EXISTS `repair_preapproval_reallocations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `repair_preapproval_reallocations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `repair_job_id` bigint unsigned NOT NULL,
  `batch_id` bigint unsigned NOT NULL,
  `before_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `after_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `before_snapshot` json NOT NULL,
  `after_snapshot` json NOT NULL,
  `reinspection_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `reinspected_by` bigint unsigned NOT NULL,
  `reinspected_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `repair_preapproval_reallocations_repair_job_id_foreign` (`repair_job_id`),
  KEY `repair_preapproval_reallocations_batch_id_foreign` (`batch_id`),
  KEY `repair_preapproval_reallocations_reinspected_by_foreign` (`reinspected_by`),
  CONSTRAINT `repair_preapproval_reallocations_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `repair_outcome_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_preapproval_reallocations_reinspected_by_foreign` FOREIGN KEY (`reinspected_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_preapproval_reallocations_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `repair_return_correction_intents`
--

DROP TABLE IF EXISTS `repair_return_correction_intents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `repair_return_correction_intents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `repair_job_id` bigint unsigned NOT NULL,
  `design_authorization_id` bigint unsigned NOT NULL,
  `approved_by` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_payload` json NOT NULL,
  `decision` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `repair_return_correction_intents_case_id_unique` (`case_id`),
  UNIQUE KEY `repair_return_correction_intents_repair_job_id_unique` (`repair_job_id`),
  KEY `repair_return_correction_intents_design_authorization_id_foreign` (`design_authorization_id`),
  KEY `repair_return_correction_intents_approved_by_foreign` (`approved_by`),
  CONSTRAINT `repair_return_correction_intents_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_return_correction_intents_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_return_correction_intents_design_authorization_id_foreign` FOREIGN KEY (`design_authorization_id`) REFERENCES `document_correction_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_return_correction_intents_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `repair_return_correction_postings`
--

DROP TABLE IF EXISTS `repair_return_correction_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `repair_return_correction_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `intent_id` bigint unsigned NOT NULL,
  `repair_job_id` bigint unsigned NOT NULL,
  `original_release_ledger_id` bigint unsigned NOT NULL,
  `inverse_ledger_id` bigint unsigned NOT NULL,
  `replacement_ledger_id` bigint unsigned NOT NULL,
  `previous_condition` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `corrected_condition` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `repair_return_correction_postings_case_id_unique` (`case_id`),
  UNIQUE KEY `repair_return_correction_postings_intent_id_unique` (`intent_id`),
  UNIQUE KEY `repair_return_correction_postings_repair_job_id_unique` (`repair_job_id`),
  UNIQUE KEY `rrcp_original_release_uq` (`original_release_ledger_id`),
  UNIQUE KEY `repair_return_correction_postings_inverse_ledger_id_unique` (`inverse_ledger_id`),
  UNIQUE KEY `repair_return_correction_postings_replacement_ledger_id_unique` (`replacement_ledger_id`),
  KEY `repair_return_correction_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `repair_return_correction_postings_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_return_correction_postings_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `repair_return_correction_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_return_correction_postings_inverse_ledger_id_foreign` FOREIGN KEY (`inverse_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_return_correction_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_return_correction_postings_repair_job_id_foreign` FOREIGN KEY (`repair_job_id`) REFERENCES `repair_jobs` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `repair_return_correction_postings_replacement_ledger_id_foreign` FOREIGN KEY (`replacement_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `rrcp_original_release_fk` FOREIGN KEY (`original_release_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `role_user`
--

DROP TABLE IF EXISTS `role_user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `role_user` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `role_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `role_user_role_id_user_id_unique` (`role_id`,`user_id`),
  KEY `role_user_user_id_foreign` (`user_id`),
  CONSTRAINT `role_user_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `role_user_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `roles`
--

DROP TABLE IF EXISTS `roles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `roles` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `roles_slug_unique` (`slug`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_balances`
--

DROP TABLE IF EXISTS `stock_balances`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_balances` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `product_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `location_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `location_id` bigint unsigned DEFAULT NULL,
  `location_key` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
  `bucket` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL DEFAULT '0',
  `version` bigint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_balance_bundle_product_loc_bucket_uq` (`bundle_id`,`product_id`,`location_key`,`bucket`),
  KEY `stock_balances_product_id_location_key_bucket_index` (`product_id`,`location_key`,`bucket`),
  CONSTRAINT `stock_balances_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_balances_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_count_lines`
--

DROP TABLE IF EXISTS `stock_count_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_count_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_count_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `bucket` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `system_pcs` bigint unsigned NOT NULL,
  `counted_pcs` bigint unsigned DEFAULT NULL,
  `counted_by` bigint unsigned DEFAULT NULL,
  `counted_at` timestamp NULL DEFAULT NULL,
  `evidence_note` text COLLATE utf8mb4_unicode_ci,
  `adjustment_ledger_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_count_identity_uq` (`stock_count_id`,`bundle_id`,`bucket`),
  UNIQUE KEY `stock_count_lines_adjustment_ledger_id_unique` (`adjustment_ledger_id`),
  KEY `stock_count_lines_bundle_id_foreign` (`bundle_id`),
  KEY `stock_count_lines_counted_by_foreign` (`counted_by`),
  CONSTRAINT `stock_count_lines_adjustment_ledger_id_foreign` FOREIGN KEY (`adjustment_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_count_lines_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_count_lines_counted_by_foreign` FOREIGN KEY (`counted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_count_lines_stock_count_id_foreign` FOREIGN KEY (`stock_count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_count_variance_plans`
--

DROP TABLE IF EXISTS `stock_count_variance_plans`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_count_variance_plans` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_count_id` bigint unsigned NOT NULL,
  `stock_count_line_id` bigint unsigned NOT NULL,
  `kind` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_bundle_id` bigint unsigned NOT NULL,
  `retained_bundle_id` bigint unsigned DEFAULT NULL,
  `variance_bundle_id` bigint unsigned NOT NULL,
  `variance_pcs` bigint unsigned NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'prepared',
  `prepared_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `count_variance_single_plan_per_line` (`stock_count_id`,`stock_count_line_id`),
  UNIQUE KEY `count_variance_bundle_once` (`variance_bundle_id`),
  KEY `stock_count_variance_plans_stock_count_line_id_foreign` (`stock_count_line_id`),
  KEY `stock_count_variance_plans_original_bundle_id_foreign` (`original_bundle_id`),
  KEY `stock_count_variance_plans_retained_bundle_id_foreign` (`retained_bundle_id`),
  KEY `stock_count_variance_plans_prepared_by_foreign` (`prepared_by`),
  KEY `stock_count_variance_plans_stock_count_id_kind_status_index` (`stock_count_id`,`kind`,`status`),
  CONSTRAINT `stock_count_variance_plans_original_bundle_id_foreign` FOREIGN KEY (`original_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_count_variance_plans_prepared_by_foreign` FOREIGN KEY (`prepared_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_count_variance_plans_retained_bundle_id_foreign` FOREIGN KEY (`retained_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_count_variance_plans_stock_count_id_foreign` FOREIGN KEY (`stock_count_id`) REFERENCES `stock_counts` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_count_variance_plans_stock_count_line_id_foreign` FOREIGN KEY (`stock_count_line_id`) REFERENCES `stock_count_lines` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_count_variance_plans_variance_bundle_id_foreign` FOREIGN KEY (`variance_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_counts`
--

DROP TABLE IF EXISTS `stock_counts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_counts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `count_no` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `snapshot_ledger_id` bigint unsigned NOT NULL DEFAULT '0',
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'draft',
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `reason` text COLLATE utf8mb4_unicode_ci,
  `decision_note` text COLLATE utf8mb4_unicode_ci,
  `submitted_at` timestamp NULL DEFAULT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_counts_count_no_unique` (`count_no`),
  KEY `stock_counts_product_id_foreign` (`product_id`),
  KEY `stock_counts_maker_id_foreign` (`maker_id`),
  KEY `stock_counts_checker_id_foreign` (`checker_id`),
  KEY `stock_counts_warehouse_id_product_id_status_index` (`warehouse_id`,`product_id`,`status`),
  KEY `stock_counts_status_index` (`status`),
  CONSTRAINT `stock_counts_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_counts_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_counts_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_counts_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_holds`
--

DROP TABLE IF EXISTS `stock_holds`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_holds` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `hold_ref` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `operation_type` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `operation_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `location_key` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
  `bucket` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_by` bigint unsigned NOT NULL,
  `approved_by` bigint unsigned DEFAULT NULL,
  `released_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_holds_hold_ref_unique` (`hold_ref`),
  KEY `stock_holds_created_by_foreign` (`created_by`),
  KEY `stock_holds_approved_by_foreign` (`approved_by`),
  KEY `stock_holds_bundle_id_status_index` (`bundle_id`,`status`),
  KEY `stock_holds_balance_lookup_idx` (`bundle_id`,`location_key`,`bucket`,`status`),
  KEY `stock_holds_operation_type_operation_id_index` (`operation_type`,`operation_id`),
  KEY `stock_holds_status_index` (`status`),
  CONSTRAINT `stock_holds_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_holds_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_holds_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_in`
--

DROP TABLE IF EXISTS `stock_in`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_in` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `receipt_no` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `source_name` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_reference` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `received_by` bigint unsigned NOT NULL,
  `effective_date` date NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'draft',
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_in_receipt_no_unique` (`receipt_no`),
  KEY `stock_in_warehouse_id_foreign` (`warehouse_id`),
  KEY `stock_in_received_by_foreign` (`received_by`),
  KEY `stock_in_status_index` (`status`),
  CONSTRAINT `stock_in_received_by_foreign` FOREIGN KEY (`received_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_in_component_details`
--

DROP TABLE IF EXISTS `stock_in_component_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_in_component_details` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_in_detail_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `ledger_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_in_component_product_uq` (`stock_in_detail_id`,`product_id`),
  UNIQUE KEY `stock_in_component_details_ledger_id_unique` (`ledger_id`),
  KEY `stock_in_component_product_idx` (`product_id`,`stock_in_detail_id`),
  CONSTRAINT `stock_in_component_details_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_component_details_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_component_details_stock_in_detail_id_foreign` FOREIGN KEY (`stock_in_detail_id`) REFERENCES `stock_in_details` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_in_details`
--

DROP TABLE IF EXISTS `stock_in_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_in_details` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_in_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `condition` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_in_details_bundle_id_unique` (`bundle_id`),
  UNIQUE KEY `stock_in_details_ledger_id_unique` (`ledger_id`),
  KEY `stock_in_details_stock_in_id_foreign` (`stock_in_id`),
  KEY `stock_in_details_product_id_foreign` (`product_id`),
  CONSTRAINT `stock_in_details_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_details_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_details_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_details_stock_in_id_foreign` FOREIGN KEY (`stock_in_id`) REFERENCES `stock_in` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_in_re_receipts`
--

DROP TABLE IF EXISTS `stock_in_re_receipts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_in_re_receipts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `receipt_no` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL,
  `return_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `condition` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `received_by` bigint unsigned NOT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_in_re_receipts_receipt_no_unique` (`receipt_no`),
  UNIQUE KEY `stock_in_re_receipts_return_id_unique` (`return_id`),
  UNIQUE KEY `stock_in_re_receipts_ledger_id_unique` (`ledger_id`),
  KEY `stock_in_re_receipts_bundle_id_foreign` (`bundle_id`),
  KEY `stock_in_re_receipts_warehouse_id_foreign` (`warehouse_id`),
  KEY `stock_in_re_receipts_received_by_foreign` (`received_by`),
  CONSTRAINT `stock_in_re_receipts_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_re_receipts_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_re_receipts_received_by_foreign` FOREIGN KEY (`received_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_re_receipts_return_id_foreign` FOREIGN KEY (`return_id`) REFERENCES `stock_in_returns` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_re_receipts_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_in_request_keys`
--

DROP TABLE IF EXISTS `stock_in_request_keys`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_in_request_keys` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `stock_in_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_in_request_keys_user_id_request_key_unique` (`user_id`,`request_key`),
  KEY `stock_in_request_keys_stock_in_id_foreign` (`stock_in_id`),
  CONSTRAINT `stock_in_request_keys_stock_in_id_foreign` FOREIGN KEY (`stock_in_id`) REFERENCES `stock_in` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_request_keys_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_in_returns`
--

DROP TABLE IF EXISTS `stock_in_returns`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_in_returns` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `return_no` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL,
  `origin_type` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `origin_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `source_bucket` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `destination` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
  `reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `dispatched_at` timestamp NULL DEFAULT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `old_qr_id` bigint unsigned DEFAULT NULL,
  `new_qr_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_in_returns_return_no_unique` (`return_no`),
  UNIQUE KEY `stock_in_returns_ledger_id_unique` (`ledger_id`),
  KEY `stock_in_returns_warehouse_id_foreign` (`warehouse_id`),
  KEY `stock_in_returns_maker_id_foreign` (`maker_id`),
  KEY `stock_in_returns_checker_id_foreign` (`checker_id`),
  KEY `stock_in_returns_old_qr_id_foreign` (`old_qr_id`),
  KEY `stock_in_returns_new_qr_id_foreign` (`new_qr_id`),
  KEY `source_return_origin_idx` (`origin_type`,`origin_id`,`status`),
  KEY `stock_in_returns_bundle_id_status_index` (`bundle_id`,`status`),
  KEY `stock_in_returns_status_index` (`status`),
  CONSTRAINT `stock_in_returns_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_returns_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_returns_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_returns_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_returns_new_qr_id_foreign` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_returns_old_qr_id_foreign` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_in_returns_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_ledger`
--

DROP TABLE IF EXISTS `stock_ledger`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_ledger` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `operation_id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
  `line_no` smallint unsigned NOT NULL DEFAULT '1',
  `event_type` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `from_location_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `from_location_id` bigint unsigned DEFAULT NULL,
  `from_location_key` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
  `from_bucket` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `to_location_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `to_location_id` bigint unsigned DEFAULT NULL,
  `to_location_key` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
  `to_bucket` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reference_type` varchar(60) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reference_id` bigint unsigned DEFAULT NULL,
  `reference_no` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `effective_at` timestamp NOT NULL,
  `posted_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `posted_by` bigint unsigned NOT NULL,
  `reversal_of_id` bigint unsigned DEFAULT NULL,
  `metadata` json DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_ledger_operation_line_uq` (`operation_id`,`line_no`),
  UNIQUE KEY `stock_ledger_single_reversal_uq` (`reversal_of_id`),
  KEY `stock_ledger_bundle_id_foreign` (`bundle_id`),
  KEY `stock_ledger_posted_by_foreign` (`posted_by`),
  KEY `stock_ledger_product_bundle_posted_idx` (`product_id`,`bundle_id`,`posted_at`),
  KEY `stock_ledger_from_location_idx` (`from_location_key`,`from_bucket`,`posted_at`),
  KEY `stock_ledger_to_location_idx` (`to_location_key`,`to_bucket`,`posted_at`),
  KEY `stock_ledger_reference_type_reference_id_index` (`reference_type`,`reference_id`),
  CONSTRAINT `stock_ledger_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_ledger_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_ledger_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_ledger_reversal_of_id_foreign` FOREIGN KEY (`reversal_of_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out`
--

DROP TABLE IF EXISTS `stock_out`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `issue_no` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `receiver_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `receiver_id` bigint unsigned NOT NULL,
  `receiving_employee_id` bigint unsigned NOT NULL,
  `purpose` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `effective_date` date NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'posted',
  `maker_id` bigint unsigned NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `acknowledged_by` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
  `acknowledged_at` timestamp NOT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_out_user_request_unique` (`maker_id`,`request_key`),
  UNIQUE KEY `stock_out_issue_no_unique` (`issue_no`),
  KEY `stock_out_receiving_employee_id_foreign` (`receiving_employee_id`),
  KEY `stock_out_receiver_type_receiver_id_status_index` (`receiver_type`,`receiver_id`,`status`),
  KEY `stock_out_warehouse_id_posted_at_index` (`warehouse_id`,`posted_at`),
  KEY `stock_out_status_index` (`status`),
  CONSTRAINT `stock_out_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_receiving_employee_id_foreign` FOREIGN KEY (`receiving_employee_id`) REFERENCES `employees` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_component_details`
--

DROP TABLE IF EXISTS `stock_out_component_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_component_details` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_out_detail_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `ledger_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_out_component_product_uq` (`stock_out_detail_id`,`product_id`),
  UNIQUE KEY `stock_out_component_details_ledger_id_unique` (`ledger_id`),
  KEY `stock_out_component_product_idx` (`product_id`,`stock_out_detail_id`),
  CONSTRAINT `stock_out_component_details_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_component_details_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_component_details_stock_out_detail_id_foreign` FOREIGN KEY (`stock_out_detail_id`) REFERENCES `stock_out_details` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_correction_intents`
--

DROP TABLE IF EXISTS `stock_out_correction_intents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_correction_intents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `original_stock_out_id` bigint unsigned NOT NULL,
  `design_authorization_id` bigint unsigned NOT NULL,
  `approved_by` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_payload` json NOT NULL,
  `decision` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_out_correction_intents_case_id_unique` (`case_id`),
  UNIQUE KEY `stock_out_correction_intents_original_stock_out_id_unique` (`original_stock_out_id`),
  KEY `stock_out_correction_intents_design_authorization_id_foreign` (`design_authorization_id`),
  KEY `stock_out_correction_intents_approved_by_foreign` (`approved_by`),
  CONSTRAINT `stock_out_correction_intents_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_intents_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_intents_design_authorization_id_foreign` FOREIGN KEY (`design_authorization_id`) REFERENCES `document_correction_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_intents_original_stock_out_id_foreign` FOREIGN KEY (`original_stock_out_id`) REFERENCES `stock_out` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_correction_postings`
--

DROP TABLE IF EXISTS `stock_out_correction_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_correction_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `intent_id` bigint unsigned NOT NULL,
  `original_stock_out_id` bigint unsigned NOT NULL,
  `replacement_stock_out_id` bigint unsigned NOT NULL,
  `reversal_ledger_id` bigint unsigned NOT NULL,
  `replacement_ledger_id` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_out_correction_postings_case_id_unique` (`case_id`),
  UNIQUE KEY `stock_out_correction_postings_intent_id_unique` (`intent_id`),
  UNIQUE KEY `stock_out_correction_postings_original_stock_out_id_unique` (`original_stock_out_id`),
  UNIQUE KEY `stock_out_correction_postings_replacement_stock_out_id_unique` (`replacement_stock_out_id`),
  UNIQUE KEY `stock_out_correction_postings_reversal_ledger_id_unique` (`reversal_ledger_id`),
  UNIQUE KEY `stock_out_correction_postings_replacement_ledger_id_unique` (`replacement_ledger_id`),
  KEY `stock_out_correction_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `stock_out_correction_postings_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_postings_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `stock_out_correction_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_postings_original_stock_out_id_foreign` FOREIGN KEY (`original_stock_out_id`) REFERENCES `stock_out` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_postings_replacement_ledger_id_foreign` FOREIGN KEY (`replacement_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_postings_replacement_stock_out_id_foreign` FOREIGN KEY (`replacement_stock_out_id`) REFERENCES `stock_out` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_correction_postings_reversal_ledger_id_foreign` FOREIGN KEY (`reversal_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_details`
--

DROP TABLE IF EXISTS `stock_out_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_details` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_out_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `ledger_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_out_details_stock_out_id_bundle_id_unique` (`stock_out_id`,`bundle_id`),
  UNIQUE KEY `stock_out_details_ledger_id_unique` (`ledger_id`),
  KEY `stock_out_details_product_id_foreign` (`product_id`),
  KEY `stock_out_details_bundle_id_stock_out_id_index` (`bundle_id`,`stock_out_id`),
  CONSTRAINT `stock_out_details_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_details_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_details_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_details_stock_out_id_foreign` FOREIGN KEY (`stock_out_id`) REFERENCES `stock_out` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_return_component_details`
--

DROP TABLE IF EXISTS `stock_out_return_component_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_return_component_details` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_out_return_detail_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `ledger_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `out_ret_component_parent_fk` (`stock_out_return_detail_id`),
  KEY `out_ret_component_product_fk` (`product_id`),
  KEY `out_ret_component_ledger_fk` (`ledger_id`),
  CONSTRAINT `out_ret_component_ledger_fk` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `out_ret_component_parent_fk` FOREIGN KEY (`stock_out_return_detail_id`) REFERENCES `stock_out_return_details` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `out_ret_component_product_fk` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_return_condition_intents`
--

DROP TABLE IF EXISTS `stock_out_return_condition_intents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_return_condition_intents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `return_id` bigint unsigned NOT NULL,
  `design_authorization_id` bigint unsigned NOT NULL,
  `approved_by` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `detail_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_payload` json NOT NULL,
  `decision` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `sorci_case_uq` (`case_id`),
  UNIQUE KEY `sorci_return_uq` (`return_id`),
  KEY `sorci_auth_fk` (`design_authorization_id`),
  KEY `stock_out_return_condition_intents_approved_by_foreign` (`approved_by`),
  CONSTRAINT `sorci_auth_fk` FOREIGN KEY (`design_authorization_id`) REFERENCES `document_correction_authorizations` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_intents_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_intents_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_intents_return_id_foreign` FOREIGN KEY (`return_id`) REFERENCES `stock_out_returns` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_return_condition_lines`
--

DROP TABLE IF EXISTS `stock_out_return_condition_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_return_condition_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `posting_id` bigint unsigned NOT NULL,
  `return_detail_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `return_qr_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `original_condition` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `effective_condition` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `sorcl_detail_uq` (`return_detail_id`),
  UNIQUE KEY `sorcl_ledger_uq` (`original_ledger_id`),
  KEY `stock_out_return_condition_lines_posting_id_foreign` (`posting_id`),
  KEY `stock_out_return_condition_lines_bundle_id_foreign` (`bundle_id`),
  KEY `stock_out_return_condition_lines_return_qr_id_foreign` (`return_qr_id`),
  CONSTRAINT `stock_out_return_condition_lines_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_lines_original_ledger_id_foreign` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_lines_posting_id_foreign` FOREIGN KEY (`posting_id`) REFERENCES `stock_out_return_condition_postings` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_lines_return_detail_id_foreign` FOREIGN KEY (`return_detail_id`) REFERENCES `stock_out_return_details` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_lines_return_qr_id_foreign` FOREIGN KEY (`return_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_return_condition_postings`
--

DROP TABLE IF EXISTS `stock_out_return_condition_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_return_condition_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `case_id` bigint unsigned NOT NULL,
  `return_id` bigint unsigned NOT NULL,
  `intent_id` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `detail_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `replacement_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `changed_line_count` int unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `sorcp_case_uq` (`case_id`),
  UNIQUE KEY `sorcp_return_uq` (`return_id`),
  UNIQUE KEY `sorcp_intent_uq` (`intent_id`),
  KEY `stock_out_return_condition_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `stock_out_return_condition_postings_case_id_foreign` FOREIGN KEY (`case_id`) REFERENCES `document_correction_cases` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_postings_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `stock_out_return_condition_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_condition_postings_return_id_foreign` FOREIGN KEY (`return_id`) REFERENCES `stock_out_returns` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_return_details`
--

DROP TABLE IF EXISTS `stock_out_return_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_return_details` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stock_out_return_id` bigint unsigned NOT NULL,
  `stock_out_detail_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `condition` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,
  `old_qr_id` bigint unsigned NOT NULL,
  `new_qr_id` bigint unsigned DEFAULT NULL,
  `ledger_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_out_return_details_ledger_id_unique` (`ledger_id`),
  KEY `stock_out_return_details_bundle_id_foreign` (`bundle_id`),
  KEY `stock_out_return_details_old_qr_id_foreign` (`old_qr_id`),
  KEY `stock_out_return_details_new_qr_id_foreign` (`new_qr_id`),
  KEY `out_return_original_bundle_lookup` (`stock_out_detail_id`,`bundle_id`),
  KEY `stock_out_return_details_stock_out_return_id_condition_index` (`stock_out_return_id`,`condition`),
  CONSTRAINT `stock_out_return_details_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_details_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_details_new_qr_id_foreign` FOREIGN KEY (`new_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_details_old_qr_id_foreign` FOREIGN KEY (`old_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_details_stock_out_detail_id_foreign` FOREIGN KEY (`stock_out_detail_id`) REFERENCES `stock_out_details` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_return_details_stock_out_return_id_foreign` FOREIGN KEY (`stock_out_return_id`) REFERENCES `stock_out_returns` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_out_returns`
--

DROP TABLE IF EXISTS `stock_out_returns`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_out_returns` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `return_no` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL,
  `stock_out_id` bigint unsigned NOT NULL,
  `warehouse_id` bigint unsigned NOT NULL,
  `status` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `received_by` bigint unsigned NOT NULL,
  `physical_received_at` timestamp NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `decision_reason` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_out_return_user_request_uq` (`maker_id`,`request_key`),
  UNIQUE KEY `stock_out_returns_return_no_unique` (`return_no`),
  KEY `stock_out_returns_received_by_foreign` (`received_by`),
  KEY `stock_out_returns_checker_id_foreign` (`checker_id`),
  KEY `stock_out_returns_stock_out_id_status_index` (`stock_out_id`,`status`),
  KEY `stock_out_returns_warehouse_id_status_index` (`warehouse_id`,`status`),
  KEY `stock_out_returns_status_index` (`status`),
  CONSTRAINT `stock_out_returns_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_returns_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_returns_received_by_foreign` FOREIGN KEY (`received_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_returns_stock_out_id_foreign` FOREIGN KEY (`stock_out_id`) REFERENCES `stock_out` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_out_returns_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `stock_reversal_requests`
--

DROP TABLE IF EXISTS `stock_reversal_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `stock_reversal_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_no` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_ledger_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `posted_by` bigint unsigned DEFAULT NULL,
  `reversal_ledger_id` bigint unsigned DEFAULT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `reason` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `decision_note` text COLLATE utf8mb4_unicode_ci,
  `movement_snapshot` json NOT NULL,
  `decided_at` timestamp NULL DEFAULT NULL,
  `posted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `one_request_per_original_ledger` (`original_ledger_id`),
  UNIQUE KEY `stock_reversal_requests_request_no_unique` (`request_no`),
  UNIQUE KEY `stock_reversal_requests_reversal_ledger_id_unique` (`reversal_ledger_id`),
  KEY `stock_reversal_requests_bundle_id_foreign` (`bundle_id`),
  KEY `stock_reversal_requests_maker_id_foreign` (`maker_id`),
  KEY `stock_reversal_requests_checker_id_foreign` (`checker_id`),
  KEY `stock_reversal_requests_posted_by_foreign` (`posted_by`),
  KEY `stock_reversal_requests_status_index` (`status`),
  CONSTRAINT `stock_reversal_requests_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_reversal_requests_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_reversal_requests_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_reversal_requests_original_ledger_id_foreign` FOREIGN KEY (`original_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_reversal_requests_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `stock_reversal_requests_reversal_ledger_id_foreign` FOREIGN KEY (`reversal_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transfer_destination_amendment_intents`
--

DROP TABLE IF EXISTS `transfer_destination_amendment_intents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transfer_destination_amendment_intents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `approved_by` bigint unsigned NOT NULL,
  `original_destination_warehouse_id` bigint unsigned NOT NULL,
  `new_destination_warehouse_id` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `authorization_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `physical_reroute_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `transfer_destination_amendment_intents_transfer_id_unique` (`transfer_id`),
  KEY `transfer_destination_amendment_intents_approved_by_foreign` (`approved_by`),
  KEY `tda_old_warehouse_fk` (`original_destination_warehouse_id`),
  KEY `tda_new_warehouse_fk` (`new_destination_warehouse_id`),
  CONSTRAINT `tda_new_warehouse_fk` FOREIGN KEY (`new_destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `tda_old_warehouse_fk` FOREIGN KEY (`original_destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transfer_destination_amendment_intents_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transfer_destination_amendment_intents_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transfer_destination_amendment_postings`
--

DROP TABLE IF EXISTS `transfer_destination_amendment_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transfer_destination_amendment_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `intent_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `source_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `authorization_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `transfer_destination_amendment_postings_intent_id_unique` (`intent_id`),
  UNIQUE KEY `transfer_destination_amendment_postings_transfer_id_unique` (`transfer_id`),
  KEY `transfer_destination_amendment_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `transfer_destination_amendment_postings_intent_id_foreign` FOREIGN KEY (`intent_id`) REFERENCES `transfer_destination_amendment_intents` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transfer_destination_amendment_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transfer_destination_amendment_postings_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_child_loss_approvals`
--

DROP TABLE IF EXISTS `transit_child_loss_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_child_loss_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tcla_request_uq` (`request_id`),
  KEY `transit_child_loss_approvals_checker_id_foreign` (`checker_id`),
  CONSTRAINT `transit_child_loss_approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_child_loss_approvals_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `transit_child_loss_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_child_loss_postings`
--

DROP TABLE IF EXISTS `transit_child_loss_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_child_loss_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `loss_ledger_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tclp_request_uq` (`request_id`),
  UNIQUE KEY `tclp_ledger_uq` (`loss_ledger_id`),
  KEY `transit_child_loss_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `transit_child_loss_postings_loss_ledger_id_foreign` FOREIGN KEY (`loss_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_child_loss_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_child_loss_postings_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `transit_child_loss_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_child_loss_requests`
--

DROP TABLE IF EXISTS `transit_child_loss_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_child_loss_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `discrepancy_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `child_bundle_id` bigint unsigned NOT NULL,
  `dispatch_ledger_id` bigint unsigned NOT NULL,
  `snapshot_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `locked_source_snapshot` json NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tclr_discrepancy_uq` (`discrepancy_id`),
  UNIQUE KEY `tclr_child_uq` (`child_bundle_id`),
  KEY `transit_child_loss_requests_transfer_id_foreign` (`transfer_id`),
  KEY `transit_child_loss_requests_dispatch_ledger_id_foreign` (`dispatch_ledger_id`),
  KEY `transit_child_loss_requests_maker_id_foreign` (`maker_id`),
  CONSTRAINT `transit_child_loss_requests_child_bundle_id_foreign` FOREIGN KEY (`child_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_child_loss_requests_discrepancy_id_foreign` FOREIGN KEY (`discrepancy_id`) REFERENCES `warehouse_transfer_discrepancies` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_child_loss_requests_dispatch_ledger_id_foreign` FOREIGN KEY (`dispatch_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_child_loss_requests_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_child_loss_requests_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_fractional_loss_approvals`
--

DROP TABLE IF EXISTS `transit_fractional_loss_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_fractional_loss_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tflfa_request_uq` (`request_id`),
  KEY `transit_fractional_loss_approvals_checker_id_foreign` (`checker_id`),
  CONSTRAINT `transit_fractional_loss_approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_fractional_loss_approvals_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `transit_fractional_loss_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_fractional_loss_postings`
--

DROP TABLE IF EXISTS `transit_fractional_loss_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_fractional_loss_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `survivor_bundle_id` bigint unsigned NOT NULL,
  `lost_bundle_id` bigint unsigned NOT NULL,
  `loss_ledger_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tflfp_request_uq` (`request_id`),
  UNIQUE KEY `tflfp_survivor_uq` (`survivor_bundle_id`),
  UNIQUE KEY `tflfp_lost_uq` (`lost_bundle_id`),
  UNIQUE KEY `tflfp_ledger_uq` (`loss_ledger_id`),
  KEY `transit_fractional_loss_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `transit_fractional_loss_postings_loss_ledger_id_foreign` FOREIGN KEY (`loss_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_fractional_loss_postings_lost_bundle_id_foreign` FOREIGN KEY (`lost_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_fractional_loss_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_fractional_loss_postings_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `transit_fractional_loss_requests` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_fractional_loss_postings_survivor_bundle_id_foreign` FOREIGN KEY (`survivor_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_fractional_loss_requests`
--

DROP TABLE IF EXISTS `transit_fractional_loss_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_fractional_loss_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `discrepancy_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `lost_pcs` bigint unsigned NOT NULL,
  `snapshot_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `scanned_qr_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `locked_source_snapshot` json NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tflfr_discrepancy_uq` (`discrepancy_id`),
  UNIQUE KEY `tflfr_root_uq` (`root_bundle_id`),
  KEY `transit_fractional_loss_requests_transfer_id_foreign` (`transfer_id`),
  KEY `transit_fractional_loss_requests_maker_id_foreign` (`maker_id`),
  CONSTRAINT `transit_fractional_loss_requests_discrepancy_id_foreign` FOREIGN KEY (`discrepancy_id`) REFERENCES `warehouse_transfer_discrepancies` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_fractional_loss_requests_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_fractional_loss_requests_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_fractional_loss_requests_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_full_loss_approvals`
--

DROP TABLE IF EXISTS `transit_full_loss_approvals`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_full_loss_approvals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tfla_request_uq` (`request_id`),
  KEY `transit_full_loss_approvals_checker_id_foreign` (`checker_id`),
  CONSTRAINT `transit_full_loss_approvals_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_full_loss_approvals_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `transit_full_loss_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_full_loss_postings`
--

DROP TABLE IF EXISTS `transit_full_loss_postings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_full_loss_postings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` bigint unsigned NOT NULL,
  `loss_ledger_id` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tflp_request_uq` (`request_id`),
  UNIQUE KEY `tflp_ledger_uq` (`loss_ledger_id`),
  KEY `transit_full_loss_postings_posted_by_foreign` (`posted_by`),
  CONSTRAINT `transit_full_loss_postings_loss_ledger_id_foreign` FOREIGN KEY (`loss_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_full_loss_postings_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_full_loss_postings_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `transit_full_loss_requests` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_full_loss_requests`
--

DROP TABLE IF EXISTS `transit_full_loss_requests`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_full_loss_requests` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `discrepancy_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `dispatch_ledger_id` bigint unsigned NOT NULL,
  `snapshot_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `locked_source_snapshot` json NOT NULL,
  `physical_evidence` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tflr_discrepancy_uq` (`discrepancy_id`),
  KEY `transit_full_loss_requests_transfer_id_foreign` (`transfer_id`),
  KEY `transit_full_loss_requests_bundle_id_foreign` (`bundle_id`),
  KEY `transit_full_loss_requests_dispatch_ledger_id_foreign` (`dispatch_ledger_id`),
  KEY `transit_full_loss_requests_maker_id_foreign` (`maker_id`),
  CONSTRAINT `transit_full_loss_requests_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_full_loss_requests_discrepancy_id_foreign` FOREIGN KEY (`discrepancy_id`) REFERENCES `warehouse_transfer_discrepancies` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_full_loss_requests_dispatch_ledger_id_foreign` FOREIGN KEY (`dispatch_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_full_loss_requests_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_full_loss_requests_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_quantity_correction_batch_lines`
--

DROP TABLE IF EXISTS `transit_quantity_correction_batch_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_quantity_correction_batch_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` bigint unsigned NOT NULL,
  `family` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_id` bigint unsigned NOT NULL,
  `transfer_id` bigint unsigned NOT NULL,
  `discrepancy_id` bigint unsigned NOT NULL,
  `transfer_line_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `lost_bundle_id` bigint unsigned NOT NULL,
  `survivor_bundle_id` bigint unsigned DEFAULT NULL,
  `loss_ledger_id` bigint unsigned NOT NULL,
  `source_quantity_pcs` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `surviving_quantity_pcs` bigint unsigned NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `request_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `snapshot_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `qr_scan_sha256` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tqcb_family_request_once` (`family`,`request_id`),
  UNIQUE KEY `tqcb_source_once` (`batch_id`,`root_bundle_id`),
  UNIQUE KEY `tqcb_transfer_once` (`transfer_id`),
  UNIQUE KEY `tqcb_discrepancy_once` (`discrepancy_id`),
  UNIQUE KEY `tqcb_loss_ledger_once` (`loss_ledger_id`),
  KEY `transit_quantity_correction_batch_lines_transfer_line_id_foreign` (`transfer_line_id`),
  KEY `transit_quantity_correction_batch_lines_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `transit_quantity_correction_batch_lines_lost_bundle_id_foreign` (`lost_bundle_id`),
  KEY `transit_quantity_correction_batch_lines_survivor_bundle_fk` (`survivor_bundle_id`),
  KEY `transit_quantity_correction_batch_lines_posted_by_foreign` (`posted_by`),
  CONSTRAINT `transit_quantity_correction_batch_lines_batch_id_foreign` FOREIGN KEY (`batch_id`) REFERENCES `transit_quantity_correction_batches` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_quantity_correction_batch_lines_discrepancy_id_foreign` FOREIGN KEY (`discrepancy_id`) REFERENCES `warehouse_transfer_discrepancies` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_quantity_correction_batch_lines_loss_ledger_id_foreign` FOREIGN KEY (`loss_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_quantity_correction_batch_lines_lost_bundle_id_foreign` FOREIGN KEY (`lost_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_quantity_correction_batch_lines_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_quantity_correction_batch_lines_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_quantity_correction_batch_lines_survivor_bundle_fk` FOREIGN KEY (`survivor_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_quantity_correction_batch_lines_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `transit_quantity_correction_batch_lines_transfer_line_id_foreign` FOREIGN KEY (`transfer_line_id`) REFERENCES `warehouse_transfer_lines` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `transit_quantity_correction_batches`
--

DROP TABLE IF EXISTS `transit_quantity_correction_batches`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transit_quantity_correction_batches` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schema_version` tinyint unsigned NOT NULL DEFAULT '1',
  `line_count` tinyint unsigned NOT NULL,
  `total_lost_pcs` bigint unsigned NOT NULL,
  `request_set_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posting_evidence_sha256` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `posted_by` bigint unsigned NOT NULL,
  `posted_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `transit_quantity_correction_batches_posted_by_foreign` (`posted_by`),
  CONSTRAINT `transit_quantity_correction_batches_posted_by_foreign` FOREIGN KEY (`posted_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `users`
--

DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `last_login_at` timestamp NULL DEFAULT NULL,
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `session_epoch` bigint unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`),
  KEY `users_is_active_index` (`is_active`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `warehouse_transfer_discrepancies`
--

DROP TABLE IF EXISTS `warehouse_transfer_discrepancies`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `warehouse_transfer_discrepancies` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `transfer_line_id` bigint unsigned NOT NULL,
  `kind` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `status` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'open',
  `note` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `reported_by` bigint unsigned NOT NULL,
  `reviewed_by` bigint unsigned DEFAULT NULL,
  `reviewed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `warehouse_transfer_discrepancies_transfer_id_foreign` (`transfer_id`),
  KEY `warehouse_transfer_discrepancies_transfer_line_id_foreign` (`transfer_line_id`),
  KEY `warehouse_transfer_discrepancies_reported_by_foreign` (`reported_by`),
  KEY `warehouse_transfer_discrepancies_reviewed_by_foreign` (`reviewed_by`),
  CONSTRAINT `warehouse_transfer_discrepancies_reported_by_foreign` FOREIGN KEY (`reported_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_discrepancies_reviewed_by_foreign` FOREIGN KEY (`reviewed_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_discrepancies_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_discrepancies_transfer_line_id_foreign` FOREIGN KEY (`transfer_line_id`) REFERENCES `warehouse_transfer_lines` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `warehouse_transfer_lines`
--

DROP TABLE IF EXISTS `warehouse_transfer_lines`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `warehouse_transfer_lines` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `root_bundle_id` bigint unsigned NOT NULL,
  `product_id` bigint unsigned NOT NULL,
  `approved_qr_id` bigint unsigned DEFAULT NULL,
  `requested_pcs` bigint unsigned NOT NULL,
  `dispatched_pcs` bigint unsigned NOT NULL DEFAULT '0',
  `received_good_pcs` bigint unsigned NOT NULL DEFAULT '0',
  `received_damaged_pcs` bigint unsigned NOT NULL DEFAULT '0',
  `discrepancy_resolved_pcs` bigint unsigned NOT NULL DEFAULT '0',
  `dispatch_ledger_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `line_no` smallint unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `transfer_root_unique` (`transfer_id`,`root_bundle_id`),
  UNIQUE KEY `transfer_line_number_unique` (`transfer_id`,`line_no`),
  KEY `warehouse_transfer_lines_root_bundle_id_foreign` (`root_bundle_id`),
  KEY `warehouse_transfer_lines_product_id_foreign` (`product_id`),
  KEY `warehouse_transfer_lines_approved_qr_id_foreign` (`approved_qr_id`),
  KEY `warehouse_transfer_lines_dispatch_ledger_id_foreign` (`dispatch_ledger_id`),
  CONSTRAINT `warehouse_transfer_lines_approved_qr_id_foreign` FOREIGN KEY (`approved_qr_id`) REFERENCES `product_qr_codes` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_lines_dispatch_ledger_id_foreign` FOREIGN KEY (`dispatch_ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_lines_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_lines_root_bundle_id_foreign` FOREIGN KEY (`root_bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_lines_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `warehouse_transfer_receipts`
--

DROP TABLE IF EXISTS `warehouse_transfer_receipts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `warehouse_transfer_receipts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_id` bigint unsigned NOT NULL,
  `transfer_line_id` bigint unsigned NOT NULL,
  `bundle_id` bigint unsigned NOT NULL,
  `quantity_pcs` bigint unsigned NOT NULL,
  `condition` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ledger_id` bigint unsigned NOT NULL,
  `received_by` bigint unsigned NOT NULL,
  `received_at` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `transfer_receipt_once_per_bundle` (`transfer_id`,`bundle_id`),
  UNIQUE KEY `transfer_receipt_ledger_once` (`ledger_id`),
  KEY `warehouse_transfer_receipts_transfer_line_id_foreign` (`transfer_line_id`),
  KEY `warehouse_transfer_receipts_bundle_id_foreign` (`bundle_id`),
  KEY `warehouse_transfer_receipts_received_by_foreign` (`received_by`),
  CONSTRAINT `warehouse_transfer_receipts_bundle_id_foreign` FOREIGN KEY (`bundle_id`) REFERENCES `bundles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_receipts_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `stock_ledger` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_receipts_received_by_foreign` FOREIGN KEY (`received_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_receipts_transfer_id_foreign` FOREIGN KEY (`transfer_id`) REFERENCES `warehouse_transfers` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfer_receipts_transfer_line_id_foreign` FOREIGN KEY (`transfer_line_id`) REFERENCES `warehouse_transfer_lines` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `warehouse_transfers`
--

DROP TABLE IF EXISTS `warehouse_transfers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `warehouse_transfers` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `transfer_no` varchar(70) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_warehouse_id` bigint unsigned NOT NULL,
  `destination_warehouse_id` bigint unsigned NOT NULL,
  `maker_id` bigint unsigned NOT NULL,
  `checker_id` bigint unsigned DEFAULT NULL,
  `status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'submitted',
  `requested_pcs` bigint unsigned NOT NULL,
  `purpose` varchar(1000) COLLATE utf8mb4_unicode_ci NOT NULL,
  `request_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `dispatched_at` timestamp NULL DEFAULT NULL,
  `closed_at` timestamp NULL DEFAULT NULL,
  `decision_reason` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `is_multi` tinyint(1) NOT NULL DEFAULT '0',
  `payload_hash` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `warehouse_transfers_transfer_no_unique` (`transfer_no`),
  UNIQUE KEY `warehouse_transfers_request_key_unique` (`request_key`),
  KEY `warehouse_transfers_maker_id_foreign` (`maker_id`),
  KEY `warehouse_transfers_checker_id_foreign` (`checker_id`),
  KEY `warehouse_transfers_source_warehouse_id_status_index` (`source_warehouse_id`,`status`),
  KEY `warehouse_transfers_destination_warehouse_id_status_index` (`destination_warehouse_id`,`status`),
  KEY `warehouse_transfers_status_index` (`status`),
  CONSTRAINT `warehouse_transfers_checker_id_foreign` FOREIGN KEY (`checker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfers_destination_warehouse_id_foreign` FOREIGN KEY (`destination_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfers_maker_id_foreign` FOREIGN KEY (`maker_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_transfers_source_warehouse_id_foreign` FOREIGN KEY (`source_warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `warehouse_user`
--

DROP TABLE IF EXISTS `warehouse_user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `warehouse_user` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `assigned_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `warehouse_user_warehouse_id_user_id_unique` (`warehouse_id`,`user_id`),
  KEY `warehouse_user_assigned_by_foreign` (`assigned_by`),
  KEY `warehouse_user_user_id_warehouse_id_index` (`user_id`,`warehouse_id`),
  CONSTRAINT `warehouse_user_assigned_by_foreign` FOREIGN KEY (`assigned_by`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_user_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `warehouse_user_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `warehouses`
--

DROP TABLE IF EXISTS `warehouses`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `warehouses` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `location` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `manager_user_id` bigint unsigned DEFAULT NULL,
  `contact` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `warehouses_code_unique` (`code`),
  KEY `warehouses_manager_user_id_foreign` (`manager_user_id`),
  KEY `warehouses_is_active_index` (`is_active`),
  CONSTRAINT `warehouses_manager_user_id_foreign` FOREIGN KEY (`manager_user_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!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-11-25 18:51:11

-- MySQL dump 10.13  Distrib 8.4.9, for Win64 (x86_64)
--
-- Host: 127.0.0.1    Database: aluminum_trial_local
-- ------------------------------------------------------
-- Server version	8.4.9

/*!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 */;
/*!50503 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 */;

--
-- Dumping data for table `migrations`
--

LOCK TABLES `migrations` WRITE;
/*!40000 ALTER TABLE `migrations` DISABLE KEYS */;
INSERT INTO `migrations` VALUES (1,'2026_11_03_000001_create_identity_access_and_warehouse_tables',1),(2,'2026_11_03_000002_create_product_bundle_and_qr_tables',1),(3,'2026_11_03_000003_create_stock_ledger_and_balance_tables',1),(4,'2026_11_03_000004_create_stock_controls_and_audit_tables',1),(5,'2026_11_03_000005_create_label_and_product_warehouse_tables',1),(6,'2026_11_03_000006_add_unique_current_qr_pointer',1),(7,'2026_11_03_000007_create_qr_scan_logs_table',1),(8,'2026_11_04_000008_create_inward_and_return_tables',1),(9,'2026_11_04_000009_create_employee_project_issues_and_returns',1),(10,'2026_11_04_000010_create_repair_count_and_adjustment_tables',1),(11,'2026_11_04_000011_create_warehouse_transfer_workflow',1),(12,'2026_11_04_000012_enforce_single_reversal_per_ledger_entry',1),(13,'2026_11_04_000013_create_repair_outcome_batches',1),(14,'2026_11_04_000014_add_multiline_transfer_controls',1),(15,'2026_11_04_000015_create_controlled_reversal_requests',1),(16,'2026_11_04_000016_create_count_variance_plans',1),(17,'2026_11_04_000017_create_count_exception_reviews',1),(18,'2026_11_04_000018_create_count_exception_dispositions',1),(19,'2026_11_04_000019_create_document_correction_cases',1),(20,'2026_11_04_000020_create_nonstore_opening_custody',1),(21,'2026_11_05_000021_create_legacy_custody_evidence_links',1),(22,'2026_11_05_000022_create_legacy_issued_returns',1),(23,'2026_11_05_000023_index_legacy_return_qr_lineage',1),(24,'2026_11_05_000024_create_legacy_partial_return_plans',1),(25,'2026_11_05_000025_create_legacy_partial_return_postings',1),(26,'2026_11_05_000026_create_legacy_retained_child_return_reviews',2),(27,'2026_11_05_000027_create_legacy_retained_child_postings',2),(28,'2026_11_05_000028_create_legacy_remaining_child_returns',2),(29,'2026_11_05_000029_create_legacy_claim_exception_cases',2),(30,'2026_11_06_000030_create_legacy_claim_reconciliation_dossiers',2),(31,'2026_11_06_000031_create_legacy_claim_correction_plans',2),(32,'2026_11_06_000032_create_legacy_transit_repair_receipt_plans',2),(33,'2026_11_06_000033_create_legacy_transit_repair_posting_authorizations',3),(34,'2026_11_09_000038_create_legacy_qr_witness_evidence',3),(35,'2026_11_09_000048_create_document_correction_authorizations',3),(36,'2026_11_09_000055_create_operational_alerts_and_session_epoch',3),(37,'2026_11_09_120000_create_product_standard_costs',3),(38,'2026_11_09_130000_create_document_correction_reversal_drafts',4),(39,'2026_11_09_130001_create_document_correction_draft_reviews',4),(40,'2026_11_09_150000_create_correction_execution_approvals_and_batches',4),(41,'2026_11_10_000091_create_stock_out_correction_intents_and_postings',4),(42,'2026_11_10_000096_create_closed_repair_and_transit_amendment_records',4),(43,'2026_11_10_000100_create_external_repair_condition_evidence',4),(44,'2026_11_10_000104_create_posted_condition_amendments',4),(45,'2026_11_10_000105_create_transit_full_loss_resolutions',4),(46,'2026_11_10_000106_create_split_child_loss_and_reallocation_audits',4),(47,'2026_11_10_000107_create_repair_fractional_reinspections',4),(48,'2026_11_10_000108_create_transit_fractional_loss_records',4),(49,'2026_11_10_000109_create_document_correction_posting_registry',4),(50,'2026_11_10_000110_create_return_condition_correction_evidence',4),(51,'2026_11_10_000111_create_multi_document_condition_correction_batches',4),(52,'2026_11_10_000116_create_physical_resplit_evidence',4),(53,'2026_11_10_000118_create_multi_outward_return_batches',4),(54,'2026_11_10_000119_create_atomic_correction_case_batches',4),(55,'2026_11_10_000120_create_mixed_repair_atomic_reinspection_batches',4),(56,'2026_11_10_000122_create_transit_quantity_correction_batches',4),(57,'2026_11_10_000125_create_dependent_cross_custody_batches',4),(58,'2026_11_10_000128_create_posted_repair_quantity_compensations',4),(59,'2026_11_10_000131_create_received_transit_reallocation_evidence',4),(60,'2026_11_10_000137_create_received_repair_atomic_batches',4),(61,'2026_11_11_000140_create_outstanding_transit_receipt_evidence',4),(62,'2026_11_11_000143_create_historical_transfer_compensation_dossiers',4),(63,'2026_11_11_000146_create_historical_count_compensation',4),(64,'2026_11_11_000149_create_historical_count_atomic_batches',4),(65,'2026_11_11_000152_create_historical_downstream_return_batches',4),(66,'2026_11_11_000155_create_historical_partial_count_compensations',4),(67,'2026_11_12_000158_create_historical_found_extra_compensations',4),(68,'2026_11_12_000161_create_historical_mixed_count_atomic_batches',4),(69,'2026_11_12_000170_allow_sibling_historical_return_receipt_claims',5),(70,'2026_11_12_000185_create_historical_cross_family_settlements',5),(71,'2026_11_12_000191_allow_independent_cross_family_transfer_pairs',5),(72,'2026_11_12_000197_create_historical_reversal_atomic_batches',5),(73,'2026_11_12_000200_create_historical_reversal_return_settlements',5),(74,'2026_11_12_000209_create_historical_received_delta_atomic_batches',5),(75,'2026_11_12_000212_guard_historical_received_delta_lineage',5),(76,'2026_11_12_000215_create_outstanding_transit_atomic_batches',5),(77,'2026_11_15_000230_create_historical_receipt_correction_intent_claims',5),(78,'2026_11_15_000239_create_historical_downstream_compensation_claims',5),(79,'2026_11_15_000251_create_historical_atomic_global_claims',5),(80,'2026_11_15_000257_create_historical_physical_merge_batches',5),(81,'2026_11_15_000263_create_historical_physical_merge_attestations',5),(82,'2026_11_15_000269_create_historical_receipt_child_journal_batches',5),(83,'2026_11_15_000275_extend_historical_receipt_journal_merge_lineage',5),(84,'2026_11_15_000306_create_composite_cross_custody_batches',5),(85,'2026_11_15_000308_create_received_transit_multi_batches',5),(86,'2026_11_25_000001_create_bundle_items_and_component_balances',6),(87,'2026_11_25_000002_backfill_missing_bundle_compositions',7),(88,'2026_11_25_000003_create_stock_in_component_details',8),(89,'2026_11_25_000004_create_stock_out_component_details',9),(90,'2026_11_25_000005_create_stock_out_return_component_details',10);
/*!40000 ALTER TABLE `migrations` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping data for table `users`
--

LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,'Local Administrator','admin@aluminum.test','$2y$12$oh893VLSiyLhOrI6ROktkONxJTMGlZVqquvtPYwfpjkKti0G6C/MC',1,'2026-11-25 06:34:30',NULL,'2026-11-15 07:52:32','2026-11-25 06:34:30',1);
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping data for table `roles`
--

LOCK TABLES `roles` WRITE;
/*!40000 ALTER TABLE `roles` DISABLE KEYS */;
INSERT INTO `roles` VALUES (1,'Super Admin','super-admin',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(2,'Store Manager / Checker','store-manager-checker',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(3,'Store Officer / Maker','store-officer-maker',NULL,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(4,'Employee / Project Receiver','employee-project-receiver',NULL,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(5,'Auditor / Viewer','auditor-viewer',NULL,'2026-11-15 07:52:07','2026-11-15 07:52:07');
/*!40000 ALTER TABLE `roles` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping data for table `permissions`
--

LOCK TABLES `permissions` WRITE;
/*!40000 ALTER TABLE `permissions` DISABLE KEYS */;
INSERT INTO `permissions` VALUES (1,'Dashboard View','dashboard.view','dashboard',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(2,'View Master Data','master.view','master',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(3,'Manage Master Data','master.manage','master',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(4,'View Bundle and QR','bundle.view','bundle',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(5,'Create and Split Bundle','bundle.manage','bundle',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(6,'Print and Reprint Labels','label.print','bundle',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(7,'View Opening Import','opening.view','opening',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(8,'Create Opening Import','opening.create','opening',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(9,'Approve Opening Import','opening.approve','opening',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(10,'View Stock In','stock.in.view','stock_in',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(11,'Create Stock In','stock.in.create','stock_in',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(12,'View Stock Out','stock.out.view','stock_out',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(13,'Create Stock Out','stock.out.create','stock_out',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(14,'Register Return','return.create','return',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(15,'Approve Return','return.approve','return',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(16,'Create Transfer','transfer.create','transfer',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(17,'Approve Transfer','transfer.approve','transfer',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(18,'Dispatch and Receive Transfer','transfer.execute','transfer',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(19,'Create Repair Job','repair.create','repair',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(20,'Approve Repair Release','repair.approve','repair',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(21,'View Inventory','inventory.view','inventory',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(22,'Create Physical Count','inventory.count','inventory',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(23,'Approve Stock Adjustment','inventory.adjust','inventory',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(24,'Approve Stock Reversal','reversal.approve','inventory',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(25,'View Reports','reports.view','reports',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(26,'Export Reports','reports.export','reports',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(27,'View Audit Trail','audit.view','audit',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(28,'Manage Users','users.manage','administration',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(29,'Manage Roles and Permissions','roles.manage','administration',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(30,'Manage Warehouse Access','warehouse.access.manage','administration',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(31,'Manage Company Settings','settings.manage','administration',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(32,'View Own Issue and Return History','portal.own.view','portal',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(33,'Submit Own Return Request','portal.own.return','portal',NULL,'2026-11-15 07:52:06','2026-11-15 07:52:06');
/*!40000 ALTER TABLE `permissions` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping data for table `role_user`
--

LOCK TABLES `role_user` WRITE;
/*!40000 ALTER TABLE `role_user` DISABLE KEYS */;
INSERT INTO `role_user` VALUES (1,1,1,'2026-11-15 07:52:32','2026-11-15 07:52:32');
/*!40000 ALTER TABLE `role_user` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping data for table `permission_role`
--

LOCK TABLES `permission_role` WRITE;
/*!40000 ALTER TABLE `permission_role` DISABLE KEYS */;
INSERT INTO `permission_role` VALUES (1,1,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(2,2,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(3,3,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(4,4,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(5,5,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(6,6,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(7,7,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(8,8,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(9,9,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(10,10,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(11,11,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(12,12,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(13,13,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(14,14,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(15,15,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(16,16,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(17,17,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(18,18,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(19,19,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(20,20,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(21,21,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(22,22,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(23,23,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(24,24,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(25,25,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(26,26,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(27,27,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(28,28,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(29,29,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(30,30,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(31,31,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(32,32,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(33,33,1,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(34,1,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(35,2,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(36,4,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(37,7,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(38,9,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(39,10,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(40,12,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(41,15,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(42,17,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(43,20,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(44,21,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(45,23,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(46,24,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(47,25,2,'2026-11-15 07:52:06','2026-11-15 07:52:06'),(48,26,2,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(49,27,2,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(50,1,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(51,2,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(52,4,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(53,5,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(54,6,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(55,7,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(56,8,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(57,10,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(58,11,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(59,12,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(60,13,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(61,14,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(62,16,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(63,18,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(64,19,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(65,21,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(66,22,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(67,25,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(68,26,3,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(69,32,4,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(70,33,4,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(71,1,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(72,2,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(73,4,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(74,7,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(75,10,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(76,12,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(77,21,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(78,25,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(79,26,5,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(80,27,5,'2026-11-15 07:52:07','2026-11-15 07:52:07');
/*!40000 ALTER TABLE `permission_role` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping data for table `warehouses`
--

LOCK TABLES `warehouses` WRITE;
/*!40000 ALTER TABLE `warehouses` DISABLE KEYS */;
INSERT INTO `warehouses` VALUES (12,'WAREHOUSE','Main Warehouse','Central warehouse',NULL,NULL,1,'2026-11-25 02:05:07','2026-11-25 02:28:18');
/*!40000 ALTER TABLE `warehouses` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping data for table `warehouse_user`
--

LOCK TABLES `warehouse_user` WRITE;
/*!40000 ALTER TABLE `warehouse_user` DISABLE KEYS */;
/*!40000 ALTER TABLE `warehouse_user` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping data for table `label_templates`
--

LOCK TABLES `label_templates` WRITE;
/*!40000 ALTER TABLE `label_templates` DISABLE KEYS */;
INSERT INTO `label_templates` VALUES (1,'STD-75X50','Standard Bundle Label 75 x 50 mm',1,75.00,50.00,'{\"fields\": [\"company\", \"product_code\", \"product_name\", \"specification\", \"bundle_no\", \"pcs\", \"qr_serial\", \"print_date\"], \"qr_area_mm\": 27, \"quiet_zone_modules\": 4}',1,1,'2026-11-15 07:52:07','2026-11-15 07:52:07'),(2,'LARGE-100X75','Large Bundle Label 100 x 75 mm',1,100.00,75.00,'{\"fields\": [\"company\", \"product_code\", \"product_name\", \"specification\", \"bundle_no\", \"pcs\", \"qr_serial\", \"print_date\"], \"qr_area_mm\": 30, \"quiet_zone_modules\": 4}',0,1,'2026-11-15 07:52:07','2026-11-15 07:52:07');
/*!40000 ALTER TABLE `label_templates` ENABLE KEYS */;
UNLOCK TABLES;
/*!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-11-25 18:51:23


SET FOREIGN_KEY_CHECKS=1;

