-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Maj 19, 2026 at 10:09 AM
-- Wersja serwera: 10.4.32-MariaDB
-- Wersja PHP: 8.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `erp_21042026`
--

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `allergen`
--

CREATE TABLE `allergen` (
  `id` int(11) NOT NULL,
  `code` varchar(50) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `allergen_alias`
--

CREATE TABLE `allergen_alias` (
  `id` int(11) NOT NULL,
  `allergen_id` int(11) NOT NULL,
  `lang_code` varchar(5) NOT NULL,
  `alias` varchar(255) NOT NULL,
  `alias_type` varchar(50) NOT NULL,
  `create_timestamp` datetime NOT NULL DEFAULT current_timestamp(),
  `update_timestamp` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `carrier`
--

CREATE TABLE `carrier` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `street` varchar(255) NOT NULL,
  `street_num` varchar(255) NOT NULL,
  `zip` varchar(255) NOT NULL,
  `town` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `active` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `carrier_vehicle`
--

CREATE TABLE `carrier_vehicle` (
  `id` int(11) NOT NULL,
  `id_carrier` int(11) NOT NULL,
  `regis_num` varchar(255) NOT NULL,
  `driver_name` varchar(255) NOT NULL DEFAULT '',
  `driver_surname` varchar(255) NOT NULL DEFAULT '',
  `driver_phone` varchar(255) NOT NULL DEFAULT '',
  `driver_email` varchar(255) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `carton_dimension`
--

CREATE TABLE `carton_dimension` (
  `id` int(11) NOT NULL,
  `length` int(11) NOT NULL,
  `width` int(11) NOT NULL,
  `height` int(11) NOT NULL,
  `name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `carton_log`
--

CREATE TABLE `carton_log` (
  `id_carton` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `batch_number` int(11) NOT NULL,
  `expiration_date` date NOT NULL DEFAULT '2000-01-01',
  `insert_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `carton_pallet_connection`
--

CREATE TABLE `carton_pallet_connection` (
  `id_key` int(11) NOT NULL,
  `id_palet` int(11) NOT NULL,
  `id_carton` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `carton_stock`
--

CREATE TABLE `carton_stock` (
  `id_carton` int(12) NOT NULL,
  `batch_number` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `expiration_date` date NOT NULL DEFAULT '2000-01-01',
  `status` int(11) NOT NULL DEFAULT 1,
  `date_add` date NOT NULL DEFAULT current_timestamp(),
  `date_pallet` datetime DEFAULT NULL,
  `date_ship` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `carton_stock_2`
--

CREATE TABLE `carton_stock_2` (
  `id_carton` int(12) NOT NULL,
  `batch_number` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `expiration_date` date NOT NULL DEFAULT '2000-01-01',
  `status` int(11) NOT NULL DEFAULT 1,
  `date_add` date NOT NULL DEFAULT current_timestamp(),
  `date_pallet` datetime DEFAULT NULL,
  `date_ship` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `carton_stock_complaint`
--

CREATE TABLE `carton_stock_complaint` (
  `id` int(11) NOT NULL,
  `id_carton` int(11) NOT NULL,
  `shipping_date` date NOT NULL,
  `id_customer` int(11) NOT NULL,
  `status` int(11) NOT NULL DEFAULT 1 COMMENT '1 -> palletised\r\n2 -> sent',
  `insert_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `category_group`
--

CREATE TABLE `category_group` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `category_material`
--

CREATE TABLE `category_material` (
  `id` int(11) NOT NULL,
  `id_group` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `category_product`
--

CREATE TABLE `category_product` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `target_margin_percentage` decimal(10,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `company_cost`
--

CREATE TABLE `company_cost` (
  `id` int(11) NOT NULL,
  `depreciation` decimal(10,2) NOT NULL,
  `water` decimal(10,2) NOT NULL,
  `power_supply` decimal(10,2) NOT NULL,
  `other` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `company_info`
--

CREATE TABLE `company_info` (
  `id` int(11) NOT NULL,
  `production_info` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `complaint`
--

CREATE TABLE `complaint` (
  `id` int(11) NOT NULL,
  `complaint_key` char(36) NOT NULL,
  `complaint_reason` enum('size_or_weight_issue','broken_packaging','incorrect_information','lack_of_conformity','incorrect_quantity_of_products_in_package','product_quality','other') NOT NULL,
  `requested_action` enum('REFUND','REPLACEMENT','CREDIT') NOT NULL,
  `compensation_method` enum('REFUND','REPLACEMENT','CREDIT') DEFAULT NULL,
  `id_customer` int(11) NOT NULL,
  `id_order` int(11) NOT NULL,
  `invoice_num` int(11) DEFAULT NULL,
  `id_product` int(11) NOT NULL,
  `product_quantity` int(11) NOT NULL,
  `client_comment` text DEFAULT NULL,
  `single_purchase_price` decimal(10,2) NOT NULL,
  `acceptance_timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
  `acceptance_status` enum('NEW','IN_REVIEW','ACCEPTED','REJECTED') NOT NULL,
  `production_response` text DEFAULT NULL,
  `closed_on` datetime DEFAULT NULL,
  `notified_at` datetime DEFAULT NULL,
  `accepted_quantity` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `complaint_attachment`
--

CREATE TABLE `complaint_attachment` (
  `id` int(11) NOT NULL,
  `complaint_id` int(11) NOT NULL,
  `client_attachment_id` int(11) NOT NULL,
  `object_key` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `complaint_compensation_method`
--

CREATE TABLE `complaint_compensation_method` (
  `id` int(11) NOT NULL,
  `content` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `complaint_product_pending`
--

CREATE TABLE `complaint_product_pending` (
  `id` int(11) NOT NULL,
  `id_customer` int(11) NOT NULL,
  `id_final_product` int(11) NOT NULL,
  `pending_product_qty` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `complaint_product_to_send_log`
--

CREATE TABLE `complaint_product_to_send_log` (
  `id` int(11) NOT NULL,
  `id_customer` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `carton_qty` int(11) NOT NULL,
  `status` int(11) NOT NULL DEFAULT 0 COMMENT '0 -> waiting for pack,\r\n1 -> packed,\r\n2 -> sent',
  `shipping_date` date NOT NULL,
  `insert_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `complaint_reason`
--

CREATE TABLE `complaint_reason` (
  `id` int(11) NOT NULL,
  `content` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `complaint_shipping_log`
--

CREATE TABLE `complaint_shipping_log` (
  `id` int(11) NOT NULL,
  `shipment_date` date NOT NULL,
  `id_customer` int(11) NOT NULL,
  `id_wz` int(11) NOT NULL,
  `id_cmr` int(11) NOT NULL,
  `id_employee` int(11) NOT NULL,
  `insert_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_logistics_type`
--

CREATE TABLE `cost_logistics_type` (
  `id` int(11) UNSIGNED NOT NULL,
  `code` varchar(60) NOT NULL COMMENT 'Klucz enum-ready, np. FUEL, FREIGHT, CUSTOMS',
  `name` varchar(150) NOT NULL COMMENT 'Wyświetlana nazwa PL',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_media_month`
--

CREATE TABLE `cost_media_month` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `cost_month_id` int(11) NOT NULL,
  `media_type_id` int(10) UNSIGNED NOT NULL,
  `amount` decimal(12,2) NOT NULL COMMENT 'Kwota kosztu medium w danym miesiącu',
  `note` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_media_section_allocation`
--

CREATE TABLE `cost_media_section_allocation` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `cost_month_id` int(11) NOT NULL,
  `media_type_id` int(10) UNSIGNED NOT NULL,
  `section_id` int(11) NOT NULL,
  `allocation_percent` decimal(7,4) NOT NULL COMMENT 'Np. 40.0000 = 40%',
  `note` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_media_type`
--

CREATE TABLE `cost_media_type` (
  `id` int(10) UNSIGNED NOT NULL,
  `code` varchar(50) NOT NULL,
  `name` varchar(100) NOT NULL,
  `unit` varchar(20) DEFAULT NULL COMMENT 'np. PLN, kWh, m3, l (opcjonalnie informacyjnie)',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_month`
--

CREATE TABLE `cost_month` (
  `id` int(11) NOT NULL,
  `year` smallint(6) NOT NULL,
  `month` tinyint(4) NOT NULL,
  `status` enum('OPEN','LOCKED') NOT NULL DEFAULT 'OPEN',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_month_employee`
--

CREATE TABLE `cost_month_employee` (
  `id` int(11) NOT NULL,
  `month_id` int(11) NOT NULL,
  `section_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `surname` varchar(255) NOT NULL,
  `monthly_cost` decimal(10,2) NOT NULL DEFAULT 0.00,
  `employee_ref_id` int(11) DEFAULT NULL,
  `is_included` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_month_fixed_cost`
--

CREATE TABLE `cost_month_fixed_cost` (
  `id` int(11) NOT NULL,
  `month_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `amount` decimal(10,2) NOT NULL DEFAULT 0.00,
  `category` varchar(50) NOT NULL DEFAULT 'GENERAL',
  `service_month` char(7) DEFAULT NULL,
  `posting_month` char(7) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_month_logistics`
--

CREATE TABLE `cost_month_logistics` (
  `id` int(11) NOT NULL,
  `month_id` int(11) NOT NULL COMMENT 'FK -> cost_month.id',
  `logistics_type_id` int(11) UNSIGNED NOT NULL COMMENT 'FK -> cost_logistics_type.id',
  `amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `note` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `cost_month_section`
--

CREATE TABLE `cost_month_section` (
  `id` int(11) NOT NULL,
  `month_id` int(11) NOT NULL,
  `section_id` int(11) NOT NULL,
  `cartons_qty` int(11) NOT NULL DEFAULT 0,
  `source` enum('AUTO','MANUAL') NOT NULL DEFAULT 'AUTO',
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `country`
--

CREATE TABLE `country` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `customer`
--

CREATE TABLE `customer` (
  `id` int(11) NOT NULL,
  `name` varchar(60) NOT NULL DEFAULT '',
  `surname` varchar(60) NOT NULL DEFAULT '',
  `fac_street` varchar(120) NOT NULL DEFAULT '',
  `fac_street_num` varchar(25) NOT NULL DEFAULT '',
  `fac_zip` text NOT NULL DEFAULT '',
  `fac_town` varchar(60) NOT NULL DEFAULT '',
  `fac_country` text NOT NULL DEFAULT '',
  `id_country` int(11) NOT NULL DEFAULT 1,
  `company` varchar(60) NOT NULL DEFAULT '',
  `tax_number` text DEFAULT NULL,
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
  `active` int(11) NOT NULL DEFAULT 1,
  `email_head` text NOT NULL DEFAULT '',
  `email_salesman` text NOT NULL DEFAULT '',
  `email_accountant` text NOT NULL DEFAULT '',
  `phone_head` varchar(55) NOT NULL DEFAULT '',
  `phone_alt` varchar(55) NOT NULL DEFAULT '',
  `payment_termin` int(11) DEFAULT NULL,
  `type` int(11) NOT NULL DEFAULT 0 COMMENT '0 -> common, 1 -> franchisee',
  `default_document_lang` int(11) NOT NULL DEFAULT 1,
  `franchisee_connection_login` varchar(255) DEFAULT NULL,
  `franchisee_connection_password` varchar(255) DEFAULT NULL,
  `franchisee_id` int(11) DEFAULT NULL,
  `franchisee_code` varchar(64) DEFAULT NULL,
  `franchise_network_id` int(11) DEFAULT NULL,
  `franchisee_uid` char(26) DEFAULT NULL,
  `credentials` longtext DEFAULT NULL,
  `default_currency` varchar(5) NOT NULL DEFAULT 'EUR',
  `pricelist_version` bigint(20) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `customer_franchise_network`
--

CREATE TABLE `customer_franchise_network` (
  `id` int(11) NOT NULL,
  `code` varchar(64) NOT NULL,
  `name` varchar(255) NOT NULL,
  `contact_email` varchar(255) DEFAULT NULL,
  `contact_phone` varchar(64) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `customer_order`
--

CREATE TABLE `customer_order` (
  `id` int(11) NOT NULL,
  `id_customer` int(11) NOT NULL,
  `reference` varchar(255) NOT NULL DEFAULT '',
  `order_batch_key` varchar(36) DEFAULT NULL COMMENT 'UUID łączący zamówienia z jednego split; NULL = zamówienie jednotransowe',
  `batch_index` int(11) DEFAULT NULL COMMENT 'Numer dostawy w grupie split: 1 lub 2; NULL gdy order_batch_key IS NULL',
  `invoice_num` varchar(255) DEFAULT NULL,
  `status` int(11) NOT NULL,
  `order_description` text NOT NULL DEFAULT '',
  `expected_shipping_date` date NOT NULL,
  `create_order_date` datetime NOT NULL,
  `update_status_date` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `id_franchisee_collector` int(11) DEFAULT NULL,
  `standard_price_list` int(1) NOT NULL DEFAULT 0,
  `id_proforma` int(11) DEFAULT NULL,
  `id_wdt` int(11) DEFAULT NULL,
  `is_freebie` tinyint(1) NOT NULL DEFAULT 0 COMMENT '1 = zamówienie jest gratisem, pomijane w dokumencie różnic'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `customer_order_changelog`
--

CREATE TABLE `customer_order_changelog` (
  `id` int(11) NOT NULL,
  `id_order` int(11) NOT NULL,
  `id_user` int(11) DEFAULT NULL COMMENT 'NULL = zmiana systemowa (API / kolektor)',
  `action_type` enum('create','update','delete') NOT NULL,
  `source` enum('web','api','collector') NOT NULL DEFAULT 'web',
  `changed_fields` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`changed_fields`)),
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `customer_order_product`
--

CREATE TABLE `customer_order_product` (
  `id_order` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `quantity_carton` int(11) NOT NULL,
  `expected_quantity_carton` int(11) NOT NULL,
  `reason_of_missing` text NOT NULL DEFAULT '',
  `purchase_price` decimal(10,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `customer_order_product_cc`
--

CREATE TABLE `customer_order_product_cc` (
  `id_order` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `quantity_carton` int(11) NOT NULL,
  `expected_quantity_carton` int(11) NOT NULL,
  `reason_of_missing` text NOT NULL DEFAULT '',
  `purchase_price` decimal(10,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `customer_order_status_type`
--

CREATE TABLE `customer_order_status_type` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_cmr`
--

CREATE TABLE `document_cmr` (
  `id` int(11) NOT NULL,
  `doc_num` int(11) NOT NULL,
  `id_document_wz` int(11) NOT NULL,
  `id_customer` int(11) NOT NULL,
  `id_carrier` int(11) NOT NULL,
  `id_carrier_sec` int(11) DEFAULT NULL,
  `consignor_name` text NOT NULL DEFAULT '',
  `consignor_address_1` text NOT NULL DEFAULT '',
  `consignor_address_2` text NOT NULL DEFAULT '',
  `consignee_name` text NOT NULL DEFAULT '',
  `consignee_address_1` text NOT NULL DEFAULT '',
  `consignee_address_2` text NOT NULL DEFAULT '',
  `delivery_place` text NOT NULL DEFAULT '',
  `taking_over_place` text NOT NULL DEFAULT '',
  `carrier_name` text NOT NULL DEFAULT '',
  `carrier_address_1` text NOT NULL DEFAULT '',
  `carrier_address_2` text NOT NULL DEFAULT '',
  `carrier_regis_num` text NOT NULL DEFAULT '',
  `id_carrier_vehicle` int(11) NOT NULL,
  `carrier_sec_name` text NOT NULL DEFAULT '',
  `carrier_sec_address_1` text NOT NULL DEFAULT '',
  `carrier_sec_address_2` text NOT NULL DEFAULT '',
  `carrier_sec_regis_num` text NOT NULL DEFAULT '\'\'',
  `id_carrier_sec_vehicle` int(11) DEFAULT NULL,
  `sender_instructions` text NOT NULL DEFAULT '',
  `carrier_reservation_observation` text NOT NULL,
  `established_in` text NOT NULL DEFAULT '',
  `established_date` text NOT NULL DEFAULT '',
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_cmr_packages`
--

CREATE TABLE `document_cmr_packages` (
  `id_document_cmr` int(11) NOT NULL,
  `name` text NOT NULL DEFAULT '',
  `quantity` text NOT NULL DEFAULT '',
  `packing_method` text NOT NULL DEFAULT '',
  `product_type` text NOT NULL DEFAULT '',
  `stats_num` text NOT NULL DEFAULT '',
  `gross_weight` text NOT NULL DEFAULT '',
  `volume_m3` text NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_invoice`
--

CREATE TABLE `document_invoice` (
  `id` int(11) NOT NULL,
  `doc_num` varchar(25) NOT NULL,
  `id_customer` int(11) NOT NULL,
  `consignor_name` text NOT NULL,
  `consignor_address_1` text NOT NULL,
  `consignor_address_2` text NOT NULL,
  `consignor_nip` text NOT NULL,
  `consignor_bank` text NOT NULL,
  `consignor_swift` text NOT NULL,
  `consignee_name` text NOT NULL,
  `consignee_address_1` text NOT NULL,
  `consignee_address_2` text NOT NULL,
  `consignee_nip` text NOT NULL,
  `invoiced_date` text NOT NULL,
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_invoice_product`
--

CREATE TABLE `document_invoice_product` (
  `id_document_invoice` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `product_name` text NOT NULL,
  `quantity` int(11) NOT NULL,
  `single_price` decimal(10,2) NOT NULL,
  `tva_perc` int(11) NOT NULL,
  `single_weight` decimal(10,2) NOT NULL,
  `ppc` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_order_shipping_difference`
--

CREATE TABLE `document_order_shipping_difference` (
  `id` int(11) NOT NULL,
  `id_customer` int(11) NOT NULL,
  `consignor_name` text NOT NULL,
  `consignor_address_1` text NOT NULL,
  `consignor_address_2` text NOT NULL,
  `consignor_nip` text NOT NULL,
  `consignee_name` text NOT NULL,
  `consignee_address_1` text NOT NULL,
  `consignee_address_2` text NOT NULL,
  `consignee_nip` text NOT NULL,
  `established_date` text NOT NULL,
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_order_shipping_difference_products`
--

CREATE TABLE `document_order_shipping_difference_products` (
  `id_document_order_shipping_difference` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `product_name` text NOT NULL,
  `quantity_ordered` int(11) NOT NULL,
  `price_during_ordering` decimal(10,2) NOT NULL,
  `invoiced_quantity` int(11) NOT NULL,
  `price_during_invoicing` decimal(10,2) NOT NULL,
  `difference_reason` text NOT NULL DEFAULT '',
  `id` bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_proforma`
--

CREATE TABLE `document_proforma` (
  `id` int(11) NOT NULL,
  `doc_num` varchar(255) NOT NULL,
  `id_customer` int(11) NOT NULL,
  `consignor_name` text NOT NULL,
  `consignor_address_1` text NOT NULL,
  `consignor_address_2` text NOT NULL,
  `consignor_nip` text NOT NULL,
  `consignee_name` text NOT NULL,
  `consignee_address_1` text NOT NULL,
  `consignee_address_2` text NOT NULL,
  `consignee_nip` text NOT NULL,
  `consignor_bank` text NOT NULL,
  `consignor_swift` text NOT NULL,
  `established_date` text NOT NULL,
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
  `status` varchar(25) NOT NULL DEFAULT 'issued',
  `uuid` char(40) NOT NULL DEFAULT '',
  `is_sent_to_client` tinyint(1) DEFAULT 0,
  `sent_to_client_at` datetime DEFAULT NULL,
  `send_method` varchar(20) DEFAULT NULL,
  `is_sent_to_franchise` tinyint(1) DEFAULT 0,
  `received_by_franchise_at` datetime DEFAULT NULL,
  `s3_bucket` varchar(128) DEFAULT NULL,
  `s3_key` varchar(512) DEFAULT NULL,
  `checksum_sha256` char(64) DEFAULT NULL,
  `size_bytes` int(10) UNSIGNED DEFAULT NULL,
  `uploaded_at` datetime DEFAULT NULL,
  `notified_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_proforma_product`
--

CREATE TABLE `document_proforma_product` (
  `id_proforma` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `product_name` text NOT NULL,
  `code_stat` varchar(25) NOT NULL,
  `quantity` int(11) NOT NULL,
  `price_per_carton` decimal(10,2) NOT NULL,
  `total_price_net` decimal(10,2) NOT NULL,
  `tva` decimal(10,2) NOT NULL,
  `price_brut` decimal(10,2) DEFAULT NULL,
  `tva_perc` int(11) NOT NULL,
  `single_carton_weight_kg` decimal(10,3) NOT NULL,
  `total_weight_kg` decimal(10,3) NOT NULL,
  `ppc` int(11) NOT NULL,
  `price_per_piece` decimal(10,2) NOT NULL,
  `id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_proforma_product_cc`
--

CREATE TABLE `document_proforma_product_cc` (
  `id_proforma` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `product_name` text NOT NULL,
  `code_stat` varchar(25) NOT NULL,
  `quantity` int(11) NOT NULL,
  `price_per_carton` decimal(10,2) NOT NULL,
  `total_price_net` decimal(10,2) NOT NULL,
  `tva` int(11) NOT NULL,
  `price_brut` decimal(10,0) DEFAULT NULL,
  `tva_perc` int(11) NOT NULL,
  `single_carton_weight_kg` decimal(10,3) NOT NULL,
  `total_weight_kg` decimal(10,3) NOT NULL,
  `ppc` int(11) NOT NULL,
  `price_per_piece` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_wdt`
--

CREATE TABLE `document_wdt` (
  `id` int(11) NOT NULL,
  `doc_num` text NOT NULL,
  `id_customer` int(11) NOT NULL,
  `consignor_name` text NOT NULL DEFAULT '',
  `consignor_address_1` text NOT NULL DEFAULT '',
  `consignor_address_2` text NOT NULL DEFAULT '',
  `consignor_nip` text NOT NULL DEFAULT '',
  `consignor_bank` text NOT NULL DEFAULT '',
  `consignor_swift` text NOT NULL DEFAULT '',
  `established_date` text NOT NULL DEFAULT '',
  `consignee_name` text NOT NULL DEFAULT '',
  `consignee_address_1` text NOT NULL DEFAULT '',
  `consignee_address_2` text NOT NULL DEFAULT '',
  `consignee_nip` text NOT NULL DEFAULT '',
  `invoiced_date` text NOT NULL,
  `shipping_date` text NOT NULL,
  `total_weight` text NOT NULL,
  `palette_nums` text NOT NULL,
  `total_net` text NOT NULL,
  `currency` varchar(15) NOT NULL DEFAULT 'eur'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_wdt_product`
--

CREATE TABLE `document_wdt_product` (
  `id_document_wdt` int(11) NOT NULL,
  `id_palette` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `name` text NOT NULL,
  `code` text NOT NULL,
  `quantity` int(11) NOT NULL,
  `price_carton` decimal(10,2) NOT NULL,
  `total_net` decimal(10,2) NOT NULL,
  `total_tva` decimal(10,2) NOT NULL,
  `price_brut` decimal(10,2) NOT NULL,
  `tva_perc` int(11) NOT NULL,
  `weight_carton` decimal(10,2) NOT NULL,
  `weight_carton_total` decimal(10,2) NOT NULL,
  `ppc` int(11) NOT NULL,
  `price_per_piece` decimal(10,2) NOT NULL,
  `id` bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_wdt_product_cc`
--

CREATE TABLE `document_wdt_product_cc` (
  `id_document_wdt` int(11) NOT NULL,
  `id_palette` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `name` text NOT NULL,
  `code` text NOT NULL,
  `quantity` int(11) NOT NULL,
  `price_carton` decimal(10,2) NOT NULL,
  `total_net` decimal(10,2) NOT NULL,
  `total_tva` decimal(10,2) NOT NULL,
  `price_brut` decimal(10,2) NOT NULL,
  `tva_perc` int(11) NOT NULL,
  `weight_carton` decimal(10,2) NOT NULL,
  `weight_carton_total` decimal(10,2) NOT NULL,
  `ppc` int(11) NOT NULL,
  `price_per_piece` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_wz`
--

CREATE TABLE `document_wz` (
  `id` int(11) NOT NULL,
  `doc_num` text NOT NULL,
  `id_customer` int(11) NOT NULL,
  `consignor_name` text NOT NULL DEFAULT '',
  `consignor_address_1` text NOT NULL DEFAULT '',
  `consignor_address_2` text NOT NULL DEFAULT '',
  `consignee_name` text NOT NULL DEFAULT '',
  `consignee_address_1` text NOT NULL DEFAULT '',
  `consignee_address_2` text NOT NULL DEFAULT '',
  `consignor_nip` text NOT NULL DEFAULT '',
  `consignor_bank_1` text NOT NULL DEFAULT '',
  `consignor_bank_2` text NOT NULL DEFAULT '',
  `consignor_swift` text NOT NULL DEFAULT '',
  `consignee_nip` text NOT NULL DEFAULT '',
  `established_date` text NOT NULL DEFAULT '',
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `document_wz_product`
--

CREATE TABLE `document_wz_product` (
  `id_document_wz` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `name` text NOT NULL,
  `code` text NOT NULL,
  `quantity` int(11) NOT NULL,
  `weight_unit` decimal(10,2) NOT NULL,
  `weight_total` decimal(10,2) NOT NULL,
  `ppc` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `erp_company_data`
--

CREATE TABLE `erp_company_data` (
  `id` int(11) NOT NULL,
  `wz_company_name` text NOT NULL,
  `wz_company_address_1` text NOT NULL,
  `wz_company_address_2` text NOT NULL,
  `wz_company_nip` text NOT NULL,
  `wz_company_bank_1` text NOT NULL,
  `wz_company_bank_2` text NOT NULL,
  `wz_company_swift` text NOT NULL,
  `cmr_company_name` text NOT NULL,
  `cmr_company_address_1` text NOT NULL,
  `cmr_company_address_2` text NOT NULL,
  `cmr_taking_over_place` text NOT NULL,
  `cmr_established_in` text NOT NULL,
  `cmr_carrier_reservation_observation` text NOT NULL,
  `cmr_sender_instruction` text NOT NULL,
  `wdt_company_name` text NOT NULL,
  `wdt_company_address_1` text NOT NULL,
  `wdt_company_address_2` text NOT NULL,
  `wdt_company_nip` text NOT NULL,
  `wdt_company_bank_1` text NOT NULL,
  `wdt_company_swift` text NOT NULL,
  `proforma_company_name` text NOT NULL,
  `proforma_company_address_1` text NOT NULL,
  `proforma_company_address_2` text NOT NULL,
  `proforma_company_nip` text NOT NULL,
  `proforma_company_bank` text NOT NULL,
  `proforma_company_swift` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `erp_company_other_settings`
--

CREATE TABLE `erp_company_other_settings` (
  `id` int(11) NOT NULL,
  `exchange_rate_euro` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `final_product`
--

CREATE TABLE `final_product` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `id_category` int(11) NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `weight` int(11) NOT NULL COMMENT 'gram as unit',
  `ppc` int(11) NOT NULL COMMENT 'piece per carton	',
  `ppb` int(11) NOT NULL COMMENT 'piece per bag',
  `bpc` int(11) NOT NULL COMMENT 'bag per carton',
  `cpl` int(11) NOT NULL COMMENT 'carton per layer	',
  `lpp` int(11) NOT NULL COMMENT 'layer per pallet',
  `cpp` int(11) NOT NULL COMMENT 'carton per pallet',
  `id_section` int(11) NOT NULL,
  `id_recipe` int(11) DEFAULT NULL,
  `label_type` int(1) NOT NULL DEFAULT 0 COMMENT '0 -> small, 1 -> big',
  `stock_minimum` int(11) NOT NULL DEFAULT 12,
  `shelf_life` int(11) NOT NULL DEFAULT 120 COMMENT 'Shelf life in days',
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
  `storage_info_label` text NOT NULL DEFAULT 'Température de conservation / Bewaartemperatuur - 18°C',
  `prepare_info_label` text NOT NULL DEFAULT 'laten ontdooien - laisser décongeler',
  `palette_cost` decimal(10,2) NOT NULL DEFAULT 0.00,
  `marge_perc` int(11) NOT NULL DEFAULT 0,
  `standard_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `pre_calculated_raw_price_per_carton` decimal(10,2) NOT NULL DEFAULT 0.00,
  `workload_points` int(11) NOT NULL DEFAULT 3
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `final_product_customer_price`
--

CREATE TABLE `final_product_customer_price` (
  `id_customer` int(11) NOT NULL,
  `id_final_product` int(11) NOT NULL,
  `price` decimal(10,2) NOT NULL,
  `available` int(11) NOT NULL DEFAULT 1,
  `id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `final_product_customer_price_cc`
--

CREATE TABLE `final_product_customer_price_cc` (
  `id_customer` int(11) NOT NULL,
  `id_final_product` int(11) NOT NULL,
  `price` decimal(10,2) NOT NULL,
  `available` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `final_product_customer_price_cc_01_05`
--

CREATE TABLE `final_product_customer_price_cc_01_05` (
  `id_customer` int(11) NOT NULL,
  `id_final_product` int(11) NOT NULL,
  `price` decimal(10,2) NOT NULL,
  `available` int(11) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `final_product_to_compare`
--

CREATE TABLE `final_product_to_compare` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `price` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `flattened_recipe_ingredient`
--

CREATE TABLE `flattened_recipe_ingredient` (
  `recipe_id` int(11) NOT NULL,
  `material_id` int(11) NOT NULL,
  `quantity` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `flattened_recipe_recipe`
--

CREATE TABLE `flattened_recipe_recipe` (
  `recipe_id` int(11) NOT NULL,
  `subrecipe_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `franchisee_final_product`
--

CREATE TABLE `franchisee_final_product` (
  `id_franchisee` int(11) NOT NULL,
  `id_final_product` int(11) NOT NULL,
  `price` decimal(10,2) NOT NULL,
  `available` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `franchisee_order_note_collector`
--

CREATE TABLE `franchisee_order_note_collector` (
  `id` int(11) NOT NULL,
  `franchisee_name` varchar(255) NOT NULL,
  `subject` varchar(255) NOT NULL,
  `id_supplier` int(11) NOT NULL,
  `supplier_name` varchar(255) NOT NULL,
  `incident_date` date NOT NULL,
  `content` text NOT NULL,
  `content_pl` text NOT NULL DEFAULT '',
  `id_product` int(11) DEFAULT NULL,
  `product_quantity` int(11) NOT NULL,
  `product_name` varchar(255) NOT NULL,
  `file_path` text DEFAULT NULL,
  `file_path_2` text DEFAULT NULL,
  `update_timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `id_franchisee` int(11) NOT NULL,
  `id_note` int(11) NOT NULL,
  `id_order_note_status` int(11) NOT NULL,
  `invoice_num` varchar(255) DEFAULT NULL,
  `response` text NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `integrated_client_onboarding_token`
--

CREATE TABLE `integrated_client_onboarding_token` (
  `token_hash` char(64) NOT NULL,
  `customer_id` int(10) NOT NULL,
  `purpose` varchar(32) NOT NULL DEFAULT 'register_shop',
  `expires_at` datetime NOT NULL,
  `used_at` datetime DEFAULT NULL,
  `revoked_at` datetime DEFAULT NULL,
  `created_by` bigint(20) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `language`
--

CREATE TABLE `language` (
  `id` int(11) NOT NULL,
  `lang_short` varchar(25) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `material_allergen_connection`
--

CREATE TABLE `material_allergen_connection` (
  `material_id` int(11) NOT NULL,
  `allergen_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `ordered_product_in_proforma_by_franchisees`
--

CREATE TABLE `ordered_product_in_proforma_by_franchisees` (
  `id_order` int(11) NOT NULL,
  `id_product` int(11) NOT NULL,
  `quantity_carton` int(11) NOT NULL,
  `expected_quantity_carton` int(11) NOT NULL DEFAULT 0,
  `reason_of_missing` text NOT NULL DEFAULT '',
  `purchase_price` decimal(10,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `order_note_status`
--

CREATE TABLE `order_note_status` (
  `id` int(11) NOT NULL,
  `content` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `outbox`
--

CREATE TABLE `outbox` (
  `id` bigint(20) NOT NULL,
  `type` varchar(64) NOT NULL,
  `payload_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`payload_json`)),
  `status` enum('pending','processing','done','failed','dead') NOT NULL DEFAULT 'pending',
  `dedup_key` varchar(128) DEFAULT NULL,
  `attempts` int(11) NOT NULL DEFAULT 0,
  `next_try_at` datetime NOT NULL DEFAULT current_timestamp(),
  `last_error` text DEFAULT NULL,
  `locked_at` datetime DEFAULT NULL,
  `locked_by` varchar(64) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `palets_delivery`
--

CREATE TABLE `palets_delivery` (
  `id_palet` int(11) NOT NULL,
  `client` text NOT NULL,
  `delivery_date` date NOT NULL DEFAULT current_timestamp(),
  `status` int(11) NOT NULL DEFAULT 1,
  `id_customer` int(11) NOT NULL,
  `last_update_date` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `predefined_recipe_label`
--

CREATE TABLE `predefined_recipe_label` (
  `id` int(11) NOT NULL,
  `recipe_id` int(11) NOT NULL,
  `lang_code` varchar(5) NOT NULL,
  `allergens` text NOT NULL,
  `ingredients` text NOT NULL,
  `nutriscore` text NOT NULL,
  `last_update` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `pre_calculated_nutrition`
--

CREATE TABLE `pre_calculated_nutrition` (
  `id_final_product` int(11) NOT NULL,
  `energy_100g` int(11) NOT NULL,
  `fat_100g` decimal(10,2) NOT NULL,
  `saturated_fat_100g` decimal(10,2) NOT NULL,
  `carbohydrates_100g` decimal(10,2) NOT NULL,
  `sugars_100g` decimal(10,2) NOT NULL,
  `salt_100g` decimal(10,2) NOT NULL,
  `fiber_100g` decimal(10,2) NOT NULL,
  `proteins_100g` decimal(10,2) NOT NULL,
  `calculation_time` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `pre_defined_values_for_label`
--

CREATE TABLE `pre_defined_values_for_label` (
  `id_final_product` int(11) NOT NULL,
  `allergens` text NOT NULL,
  `ingredients` text NOT NULL,
  `nutriscore` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `production_employee`
--

CREATE TABLE `production_employee` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `surname` varchar(255) NOT NULL,
  `cost` decimal(10,2) NOT NULL,
  `id_section` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `production_list_tmp`
--

CREATE TABLE `production_list_tmp` (
  `id_product` int(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `ppc` int(11) DEFAULT NULL,
  `stock_minimum` int(11) DEFAULT NULL,
  `id_section` int(11) DEFAULT NULL,
  `in_stock` int(11) DEFAULT NULL,
  `date_1` int(11) DEFAULT NULL,
  `date_2` int(11) DEFAULT NULL,
  `date_3` int(11) DEFAULT NULL,
  `date_4` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `production_sections`
--

CREATE TABLE `production_sections` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `depreciation` decimal(10,2) NOT NULL,
  `water_cost` decimal(10,2) NOT NULL,
  `power_supply_cost` decimal(10,2) NOT NULL,
  `fuel_cost` decimal(10,2) NOT NULL,
  `other_cost` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `product_preparation_type`
--

CREATE TABLE `product_preparation_type` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `price` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'price per minute'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `product_recipe`
--

CREATE TABLE `product_recipe` (
  `id` int(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `id_product` int(11) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `id_type` int(11) NOT NULL,
  `is_subrecipe` tinyint(1) NOT NULL COMMENT '0 = false, 1 = true',
  `id_unit` int(11) DEFAULT NULL,
  `yield_quantity` int(11) NOT NULL,
  `precalculated_material_cost` decimal(10,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `product_recipe_connection`
--

CREATE TABLE `product_recipe_connection` (
  `parent_recipe_id` int(11) NOT NULL,
  `child_recipe_id` int(11) DEFAULT NULL,
  `child_ingredient_id` int(11) DEFAULT NULL,
  `quantity` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `product_recipe_preparation_connection`
--

CREATE TABLE `product_recipe_preparation_connection` (
  `id_recipe` int(11) NOT NULL,
  `id_preparation_type` int(11) NOT NULL,
  `duration_second` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `product_recipe_preparation_step`
--

CREATE TABLE `product_recipe_preparation_step` (
  `id` int(11) NOT NULL,
  `recipe_id` int(11) NOT NULL,
  `step_number` int(11) NOT NULL,
  `step_description` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `product_recipe_prepare_instruction_connection`
--

CREATE TABLE `product_recipe_prepare_instruction_connection` (
  `id` int(11) NOT NULL,
  `id_recipe` int(11) NOT NULL,
  `prepare_step_num` int(11) NOT NULL,
  `prepare_step_desc` text NOT NULL,
  `duration` int(11) NOT NULL COMMENT 'time in minutes'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `product_recipe_type`
--

CREATE TABLE `product_recipe_type` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `proforma_outbox`
--

CREATE TABLE `proforma_outbox` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `shop_uid` varchar(64) NOT NULL,
  `order_key` varchar(64) NOT NULL,
  `proforma_uuid` varchar(64) NOT NULL,
  `status` enum('pending','done','failed') NOT NULL DEFAULT 'pending',
  `retry_count` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `last_error` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `purchase_document`
--

CREATE TABLE `purchase_document` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `supplier_id` int(11) NOT NULL,
  `doc_no` varchar(64) DEFAULT NULL,
  `doc_date` date NOT NULL,
  `currency_code` char(3) NOT NULL DEFAULT 'PLN',
  `note` varchar(255) DEFAULT NULL,
  `status` enum('DRAFT','POSTED','CANCELED') NOT NULL DEFAULT 'DRAFT',
  `posted_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `purchase_item`
--

CREATE TABLE `purchase_item` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `purchase_document_id` bigint(20) UNSIGNED NOT NULL,
  `raw_material_id` int(11) NOT NULL,
  `qty_base` decimal(14,3) NOT NULL,
  `unit_price_net` decimal(14,6) NOT NULL,
  `vat_rate` decimal(5,2) DEFAULT NULL,
  `line_total_net` decimal(14,2) NOT NULL,
  `package_size_base` decimal(14,3) DEFAULT NULL,
  `package_price_net` decimal(14,2) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `raw_material`
--

CREATE TABLE `raw_material` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `name_fr` varchar(255) NOT NULL DEFAULT '',
  `waste_perc` int(11) NOT NULL COMMENT 'How much material we are wasting durnig processing',
  `id_unit` int(11) NOT NULL,
  `id_category` int(11) NOT NULL,
  `id_current_supplier` int(11) NOT NULL,
  `package_size_in_base_unit` int(11) NOT NULL,
  `price_per_unit` decimal(10,5) NOT NULL DEFAULT 0.00000 COMMENT 'price per 1 g or 1 pcs',
  `energy_100g` int(11) NOT NULL,
  `fat_100g` decimal(10,2) NOT NULL,
  `saturated_fat_100g` decimal(10,2) NOT NULL,
  `carbohydrates_100g` decimal(10,2) NOT NULL,
  `sugars_100g` decimal(10,2) NOT NULL,
  `salt_100g` decimal(10,2) NOT NULL,
  `fiber_100g` decimal(10,2) NOT NULL,
  `proteins_100g` decimal(10,2) NOT NULL,
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
  `vat_rate` int(11) NOT NULL DEFAULT 8,
  `is_part_of_package` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `raw_material_alias`
--

CREATE TABLE `raw_material_alias` (
  `id` int(11) NOT NULL,
  `material_id` int(11) NOT NULL,
  `lang_code` varchar(5) NOT NULL,
  `alias` varchar(255) NOT NULL,
  `alias_type` varchar(50) NOT NULL DEFAULT 'default',
  `create_timestamp` datetime NOT NULL DEFAULT current_timestamp(),
  `update_timestamp` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `raw_material_price_changelog`
--

CREATE TABLE `raw_material_price_changelog` (
  `id_supplier` int(11) NOT NULL,
  `id_raw_material` int(11) NOT NULL,
  `pack_price` decimal(10,2) NOT NULL COMMENT 'price for 1000 g',
  `package_size_in_base_unit` int(11) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `raw_material_price_list_sync_queue`
--

CREATE TABLE `raw_material_price_list_sync_queue` (
  `id` bigint(20) NOT NULL,
  `id_client` int(11) NOT NULL,
  `due_at` datetime NOT NULL,
  `attempts` tinyint(4) NOT NULL DEFAULT 0,
  `last_error` varchar(255) DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `recipe_competency`
--

CREATE TABLE `recipe_competency` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `description` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `recipe_competency_connection`
--

CREATE TABLE `recipe_competency_connection` (
  `recipe_id` int(11) NOT NULL,
  `competency_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `shipment_log`
--

CREATE TABLE `shipment_log` (
  `id` int(11) NOT NULL,
  `shipment_date` date NOT NULL,
  `id_customer` int(11) NOT NULL,
  `id_wz` int(11) NOT NULL,
  `id_cmr` int(11) DEFAULT NULL,
  `id_wdt` int(11) NOT NULL,
  `id_diff` int(11) NOT NULL,
  `id_employee` int(11) NOT NULL,
  `insert_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `slfood_order_collector_products`
--

CREATE TABLE `slfood_order_collector_products` (
  `id_order` int(11) NOT NULL,
  `ref_supplier` int(11) NOT NULL,
  `quantity` int(11) NOT NULL,
  `purchase_price` decimal(10,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `smp`
--

CREATE TABLE `smp` (
  `id` int(11) NOT NULL,
  `ref_supplier` int(11) NOT NULL,
  `price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `cost_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `update_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `supplier`
--

CREATE TABLE `supplier` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `is_active` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `supported_language`
--

CREATE TABLE `supported_language` (
  `id` int(11) NOT NULL,
  `code` varchar(2) NOT NULL COMMENT 'ISO 639-1 language code (e.g. pl, fr, en, nl)',
  `name` varchar(255) NOT NULL COMMENT 'User-friendly language name',
  `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1 = active, 0 = disabled',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `test_product`
--

CREATE TABLE `test_product` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `id_category` int(11) DEFAULT NULL,
  `id_section` int(11) DEFAULT NULL,
  `id_recipe` int(11) DEFAULT NULL,
  `id_status` int(11) NOT NULL,
  `id_type` int(11) NOT NULL,
  `label_type` int(11) DEFAULT NULL,
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `test_product_changelog`
--

CREATE TABLE `test_product_changelog` (
  `id` int(11) NOT NULL,
  `id_test_product` int(11) NOT NULL,
  `id_stage` int(11) NOT NULL,
  `description` text NOT NULL,
  `deadline` datetime NOT NULL,
  `create_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `test_product_stage`
--

CREATE TABLE `test_product_stage` (
  `id` int(11) NOT NULL,
  `priority` int(11) NOT NULL,
  `name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `test_product_status`
--

CREATE TABLE `test_product_status` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `test_product_type`
--

CREATE TABLE `test_product_type` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `unit`
--

CREATE TABLE `unit` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `user`
--

CREATE TABLE `user` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `surname` varchar(255) NOT NULL,
  `displayed_name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `permission` int(11) NOT NULL,
  `login` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `webhook_outbox_shipments`
--

CREATE TABLE `webhook_outbox_shipments` (
  `id` int(11) NOT NULL,
  `id_order` int(11) NOT NULL,
  `shop_uid` varchar(64) NOT NULL,
  `url` varchar(500) NOT NULL,
  `event_id` char(64) NOT NULL,
  `payload_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`payload_json`)),
  `status` enum('pending','processing','sent','failed') NOT NULL DEFAULT 'pending',
  `attempts` int(11) NOT NULL DEFAULT 0,
  `next_try` datetime NOT NULL DEFAULT current_timestamp(),
  `last_error` varchar(500) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Indeksy dla zrzutów tabel
--

--
-- Indeksy dla tabeli `allergen`
--
ALTER TABLE `allergen`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `allergen_alias`
--
ALTER TABLE `allergen_alias`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_allergen_lang` (`allergen_id`,`lang_code`,`alias_type`);

--
-- Indeksy dla tabeli `carrier`
--
ALTER TABLE `carrier`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `carrier_vehicle`
--
ALTER TABLE `carrier_vehicle`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `carton_dimension`
--
ALTER TABLE `carton_dimension`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_cd_id` (`id`);

--
-- Indeksy dla tabeli `carton_pallet_connection`
--
ALTER TABLE `carton_pallet_connection`
  ADD PRIMARY KEY (`id_key`);

--
-- Indeksy dla tabeli `carton_stock`
--
ALTER TABLE `carton_stock`
  ADD PRIMARY KEY (`id_carton`);

--
-- Indeksy dla tabeli `carton_stock_2`
--
ALTER TABLE `carton_stock_2`
  ADD PRIMARY KEY (`id_carton`);

--
-- Indeksy dla tabeli `carton_stock_complaint`
--
ALTER TABLE `carton_stock_complaint`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `category_group`
--
ALTER TABLE `category_group`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `category_material`
--
ALTER TABLE `category_material`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `category_product`
--
ALTER TABLE `category_product`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `company_cost`
--
ALTER TABLE `company_cost`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `company_info`
--
ALTER TABLE `company_info`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `complaint`
--
ALTER TABLE `complaint`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `complaint_attachment`
--
ALTER TABLE `complaint_attachment`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `complaint_compensation_method`
--
ALTER TABLE `complaint_compensation_method`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `complaint_product_pending`
--
ALTER TABLE `complaint_product_pending`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_customer` (`id_customer`,`id_final_product`);

--
-- Indeksy dla tabeli `complaint_product_to_send_log`
--
ALTER TABLE `complaint_product_to_send_log`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `complaint_reason`
--
ALTER TABLE `complaint_reason`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `complaint_shipping_log`
--
ALTER TABLE `complaint_shipping_log`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `cost_logistics_type`
--
ALTER TABLE `cost_logistics_type`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_code` (`code`);

--
-- Indeksy dla tabeli `cost_media_month`
--
ALTER TABLE `cost_media_month`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_cost_media_month_type` (`media_type_id`),
  ADD KEY `cost_month_id` (`cost_month_id`);

--
-- Indeksy dla tabeli `cost_media_section_allocation`
--
ALTER TABLE `cost_media_section_allocation`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `cost_month_id` (`cost_month_id`,`media_type_id`,`section_id`),
  ADD KEY `idx_cost_media_section_alloc_type` (`media_type_id`),
  ADD KEY `idx_cost_media_section_alloc_section` (`section_id`);

--
-- Indeksy dla tabeli `cost_media_type`
--
ALTER TABLE `cost_media_type`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_cost_media_type_code` (`code`);

--
-- Indeksy dla tabeli `cost_month`
--
ALTER TABLE `cost_month`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_cost_month_year_month` (`year`,`month`);

--
-- Indeksy dla tabeli `cost_month_employee`
--
ALTER TABLE `cost_month_employee`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_cost_month_employee_ref` (`month_id`,`employee_ref_id`),
  ADD KEY `idx_cost_month_employee_month` (`month_id`),
  ADD KEY `idx_cost_month_employee_section` (`section_id`),
  ADD KEY `idx_cost_month_employee_month_included` (`month_id`,`is_included`),
  ADD KEY `idx_cost_month_employee_ref` (`employee_ref_id`);

--
-- Indeksy dla tabeli `cost_month_fixed_cost`
--
ALTER TABLE `cost_month_fixed_cost`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_cost_month_fixed_cost_month` (`month_id`);

--
-- Indeksy dla tabeli `cost_month_logistics`
--
ALTER TABLE `cost_month_logistics`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_month_id` (`month_id`),
  ADD KEY `idx_logistics_type_id` (`logistics_type_id`);

--
-- Indeksy dla tabeli `cost_month_section`
--
ALTER TABLE `cost_month_section`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_cost_month_section` (`month_id`,`section_id`),
  ADD KEY `idx_cost_month_section_month` (`month_id`),
  ADD KEY `idx_cost_month_section_section` (`section_id`);

--
-- Indeksy dla tabeli `country`
--
ALTER TABLE `country`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `customer`
--
ALTER TABLE `customer`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `franchisee_uid` (`franchisee_uid`);

--
-- Indeksy dla tabeli `customer_franchise_network`
--
ALTER TABLE `customer_franchise_network`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code_unique` (`code`);

--
-- Indeksy dla tabeli `customer_order`
--
ALTER TABLE `customer_order`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `customer_order_changelog`
--
ALTER TABLE `customer_order_changelog`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_id_order` (`id_order`),
  ADD KEY `idx_created_at` (`created_at`);

--
-- Indeksy dla tabeli `customer_order_product`
--
ALTER TABLE `customer_order_product`
  ADD KEY `idx_cop_order_product` (`id_order`,`id_product`);

--
-- Indeksy dla tabeli `customer_order_status_type`
--
ALTER TABLE `customer_order_status_type`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `document_cmr`
--
ALTER TABLE `document_cmr`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `document_invoice`
--
ALTER TABLE `document_invoice`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `document_order_shipping_difference`
--
ALTER TABLE `document_order_shipping_difference`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `document_order_shipping_difference_products`
--
ALTER TABLE `document_order_shipping_difference_products`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `document_proforma`
--
ALTER TABLE `document_proforma`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_proformas_uuid` (`uuid`),
  ADD KEY `idx_proformas_s3_object` (`s3_bucket`,`s3_key`);

--
-- Indeksy dla tabeli `document_proforma_product`
--
ALTER TABLE `document_proforma_product`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `document_wdt`
--
ALTER TABLE `document_wdt`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `document_wdt_product`
--
ALTER TABLE `document_wdt_product`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `document_wz`
--
ALTER TABLE `document_wz`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `erp_company_data`
--
ALTER TABLE `erp_company_data`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `erp_company_other_settings`
--
ALTER TABLE `erp_company_other_settings`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `final_product`
--
ALTER TABLE `final_product`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `final_product_customer_price`
--
ALTER TABLE `final_product_customer_price`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_customer_product` (`id_customer`,`id_final_product`);

--
-- Indeksy dla tabeli `final_product_to_compare`
--
ALTER TABLE `final_product_to_compare`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `flattened_recipe_ingredient`
--
ALTER TABLE `flattened_recipe_ingredient`
  ADD KEY `material_id` (`material_id`),
  ADD KEY `recipe_id` (`recipe_id`);

--
-- Indeksy dla tabeli `flattened_recipe_recipe`
--
ALTER TABLE `flattened_recipe_recipe`
  ADD KEY `recipe_id` (`recipe_id`),
  ADD KEY `subrecipe_id` (`subrecipe_id`);

--
-- Indeksy dla tabeli `franchisee_order_note_collector`
--
ALTER TABLE `franchisee_order_note_collector`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `integrated_client_onboarding_token`
--
ALTER TABLE `integrated_client_onboarding_token`
  ADD PRIMARY KEY (`token_hash`),
  ADD KEY `idx_tenant_expires` (`customer_id`,`expires_at`);

--
-- Indeksy dla tabeli `language`
--
ALTER TABLE `language`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `material_allergen_connection`
--
ALTER TABLE `material_allergen_connection`
  ADD KEY `allergen_id` (`allergen_id`),
  ADD KEY `material_id` (`material_id`);

--
-- Indeksy dla tabeli `order_note_status`
--
ALTER TABLE `order_note_status`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `outbox`
--
ALTER TABLE `outbox`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_dedup` (`dedup_key`),
  ADD KEY `idx_status_next` (`status`,`next_try_at`);

--
-- Indeksy dla tabeli `palets_delivery`
--
ALTER TABLE `palets_delivery`
  ADD PRIMARY KEY (`id_palet`);

--
-- Indeksy dla tabeli `predefined_recipe_label`
--
ALTER TABLE `predefined_recipe_label`
  ADD PRIMARY KEY (`id`),
  ADD KEY `recipe_id` (`recipe_id`);

--
-- Indeksy dla tabeli `production_employee`
--
ALTER TABLE `production_employee`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `production_list_tmp`
--
ALTER TABLE `production_list_tmp`
  ADD PRIMARY KEY (`id_product`);

--
-- Indeksy dla tabeli `production_sections`
--
ALTER TABLE `production_sections`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `product_preparation_type`
--
ALTER TABLE `product_preparation_type`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `product_recipe`
--
ALTER TABLE `product_recipe`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_pr_id_product` (`id_product`);

--
-- Indeksy dla tabeli `product_recipe_connection`
--
ALTER TABLE `product_recipe_connection`
  ADD KEY `idx_prc_parent_child` (`parent_recipe_id`,`child_ingredient_id`),
  ADD KEY `child_ingredient_id` (`child_ingredient_id`),
  ADD KEY `child_recipe_id` (`child_recipe_id`);

--
-- Indeksy dla tabeli `product_recipe_preparation_step`
--
ALTER TABLE `product_recipe_preparation_step`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `product_recipe_prepare_instruction_connection`
--
ALTER TABLE `product_recipe_prepare_instruction_connection`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `product_recipe_type`
--
ALTER TABLE `product_recipe_type`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `proforma_outbox`
--
ALTER TABLE `proforma_outbox`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_shop_uuid` (`shop_uid`,`proforma_uuid`),
  ADD KEY `idx_shop_status` (`shop_uid`,`status`);

--
-- Indeksy dla tabeli `purchase_document`
--
ALTER TABLE `purchase_document`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_pd_supplier_date` (`supplier_id`,`doc_date`),
  ADD KEY `idx_pd_status_date` (`status`,`doc_date`);

--
-- Indeksy dla tabeli `purchase_item`
--
ALTER TABLE `purchase_item`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_pi_doc` (`purchase_document_id`),
  ADD KEY `idx_pi_rawmat` (`raw_material_id`);

--
-- Indeksy dla tabeli `raw_material`
--
ALTER TABLE `raw_material`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `raw_material_alias`
--
ALTER TABLE `raw_material_alias`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_material_lang` (`material_id`,`lang_code`,`alias_type`);

--
-- Indeksy dla tabeli `raw_material_price_list_sync_queue`
--
ALTER TABLE `raw_material_price_list_sync_queue`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_client` (`id_client`);

--
-- Indeksy dla tabeli `recipe_competency`
--
ALTER TABLE `recipe_competency`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `recipe_competency_connection`
--
ALTER TABLE `recipe_competency_connection`
  ADD PRIMARY KEY (`recipe_id`,`competency_id`),
  ADD KEY `fk_rcc_competency` (`competency_id`);

--
-- Indeksy dla tabeli `shipment_log`
--
ALTER TABLE `shipment_log`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `supplier`
--
ALTER TABLE `supplier`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `supported_language`
--
ALTER TABLE `supported_language`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_supported_language_code` (`code`);

--
-- Indeksy dla tabeli `test_product`
--
ALTER TABLE `test_product`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `test_product_changelog`
--
ALTER TABLE `test_product_changelog`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `test_product_stage`
--
ALTER TABLE `test_product_stage`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `test_product_status`
--
ALTER TABLE `test_product_status`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `test_product_type`
--
ALTER TABLE `test_product_type`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `unit`
--
ALTER TABLE `unit`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `user`
--
ALTER TABLE `user`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `webhook_outbox_shipments`
--
ALTER TABLE `webhook_outbox_shipments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_event` (`event_id`),
  ADD KEY `idx_due` (`status`,`next_try`),
  ADD KEY `idx_order` (`id_order`),
  ADD KEY `idx_shop` (`shop_uid`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `allergen`
--
ALTER TABLE `allergen`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `allergen_alias`
--
ALTER TABLE `allergen_alias`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `carrier`
--
ALTER TABLE `carrier`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `carrier_vehicle`
--
ALTER TABLE `carrier_vehicle`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `carton_pallet_connection`
--
ALTER TABLE `carton_pallet_connection`
  MODIFY `id_key` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `carton_stock_complaint`
--
ALTER TABLE `carton_stock_complaint`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `category_group`
--
ALTER TABLE `category_group`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `category_material`
--
ALTER TABLE `category_material`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `category_product`
--
ALTER TABLE `category_product`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `company_cost`
--
ALTER TABLE `company_cost`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `company_info`
--
ALTER TABLE `company_info`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `complaint`
--
ALTER TABLE `complaint`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `complaint_attachment`
--
ALTER TABLE `complaint_attachment`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `complaint_compensation_method`
--
ALTER TABLE `complaint_compensation_method`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `complaint_product_pending`
--
ALTER TABLE `complaint_product_pending`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `complaint_product_to_send_log`
--
ALTER TABLE `complaint_product_to_send_log`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `complaint_reason`
--
ALTER TABLE `complaint_reason`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `complaint_shipping_log`
--
ALTER TABLE `complaint_shipping_log`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_logistics_type`
--
ALTER TABLE `cost_logistics_type`
  MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_media_month`
--
ALTER TABLE `cost_media_month`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_media_section_allocation`
--
ALTER TABLE `cost_media_section_allocation`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_media_type`
--
ALTER TABLE `cost_media_type`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_month`
--
ALTER TABLE `cost_month`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_month_employee`
--
ALTER TABLE `cost_month_employee`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_month_fixed_cost`
--
ALTER TABLE `cost_month_fixed_cost`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_month_logistics`
--
ALTER TABLE `cost_month_logistics`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cost_month_section`
--
ALTER TABLE `cost_month_section`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `country`
--
ALTER TABLE `country`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `customer`
--
ALTER TABLE `customer`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `customer_franchise_network`
--
ALTER TABLE `customer_franchise_network`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `customer_order`
--
ALTER TABLE `customer_order`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `customer_order_changelog`
--
ALTER TABLE `customer_order_changelog`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `customer_order_status_type`
--
ALTER TABLE `customer_order_status_type`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_cmr`
--
ALTER TABLE `document_cmr`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_invoice`
--
ALTER TABLE `document_invoice`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_order_shipping_difference`
--
ALTER TABLE `document_order_shipping_difference`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_order_shipping_difference_products`
--
ALTER TABLE `document_order_shipping_difference_products`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_proforma`
--
ALTER TABLE `document_proforma`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_proforma_product`
--
ALTER TABLE `document_proforma_product`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_wdt`
--
ALTER TABLE `document_wdt`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_wdt_product`
--
ALTER TABLE `document_wdt_product`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_wz`
--
ALTER TABLE `document_wz`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `erp_company_data`
--
ALTER TABLE `erp_company_data`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `erp_company_other_settings`
--
ALTER TABLE `erp_company_other_settings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `final_product`
--
ALTER TABLE `final_product`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `final_product_customer_price`
--
ALTER TABLE `final_product_customer_price`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `franchisee_order_note_collector`
--
ALTER TABLE `franchisee_order_note_collector`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `language`
--
ALTER TABLE `language`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `order_note_status`
--
ALTER TABLE `order_note_status`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `outbox`
--
ALTER TABLE `outbox`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `palets_delivery`
--
ALTER TABLE `palets_delivery`
  MODIFY `id_palet` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `predefined_recipe_label`
--
ALTER TABLE `predefined_recipe_label`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `production_employee`
--
ALTER TABLE `production_employee`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `production_sections`
--
ALTER TABLE `production_sections`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `product_preparation_type`
--
ALTER TABLE `product_preparation_type`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `product_recipe`
--
ALTER TABLE `product_recipe`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `product_recipe_preparation_step`
--
ALTER TABLE `product_recipe_preparation_step`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `product_recipe_prepare_instruction_connection`
--
ALTER TABLE `product_recipe_prepare_instruction_connection`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `product_recipe_type`
--
ALTER TABLE `product_recipe_type`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `proforma_outbox`
--
ALTER TABLE `proforma_outbox`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `purchase_document`
--
ALTER TABLE `purchase_document`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `purchase_item`
--
ALTER TABLE `purchase_item`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `raw_material`
--
ALTER TABLE `raw_material`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `raw_material_alias`
--
ALTER TABLE `raw_material_alias`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `raw_material_price_list_sync_queue`
--
ALTER TABLE `raw_material_price_list_sync_queue`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `recipe_competency`
--
ALTER TABLE `recipe_competency`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `shipment_log`
--
ALTER TABLE `shipment_log`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `supplier`
--
ALTER TABLE `supplier`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `supported_language`
--
ALTER TABLE `supported_language`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `test_product`
--
ALTER TABLE `test_product`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `test_product_changelog`
--
ALTER TABLE `test_product_changelog`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `test_product_stage`
--
ALTER TABLE `test_product_stage`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `test_product_status`
--
ALTER TABLE `test_product_status`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `test_product_type`
--
ALTER TABLE `test_product_type`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `unit`
--
ALTER TABLE `unit`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `user`
--
ALTER TABLE `user`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `webhook_outbox_shipments`
--
ALTER TABLE `webhook_outbox_shipments`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `allergen_alias`
--
ALTER TABLE `allergen_alias`
  ADD CONSTRAINT `allergen_alias_ibfk_1` FOREIGN KEY (`allergen_id`) REFERENCES `allergen` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `cost_media_month`
--
ALTER TABLE `cost_media_month`
  ADD CONSTRAINT `cost_media_month_ibfk_1` FOREIGN KEY (`cost_month_id`) REFERENCES `cost_month` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_cost_media_month_media_type` FOREIGN KEY (`media_type_id`) REFERENCES `cost_media_type` (`id`) ON UPDATE CASCADE;

--
-- Constraints for table `cost_media_section_allocation`
--
ALTER TABLE `cost_media_section_allocation`
  ADD CONSTRAINT `cost_media_section_allocation_ibfk_1` FOREIGN KEY (`cost_month_id`) REFERENCES `cost_month` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_cost_media_section_allocation_media_type` FOREIGN KEY (`media_type_id`) REFERENCES `cost_media_type` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_cost_media_section_allocation_section` FOREIGN KEY (`section_id`) REFERENCES `production_sections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `cost_month_employee`
--
ALTER TABLE `cost_month_employee`
  ADD CONSTRAINT `fk_cost_month_employee_month` FOREIGN KEY (`month_id`) REFERENCES `cost_month` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_cost_month_employee_section` FOREIGN KEY (`section_id`) REFERENCES `production_sections` (`id`) ON UPDATE CASCADE;

--
-- Constraints for table `cost_month_fixed_cost`
--
ALTER TABLE `cost_month_fixed_cost`
  ADD CONSTRAINT `fk_cost_month_fixed_cost_month` FOREIGN KEY (`month_id`) REFERENCES `cost_month` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `cost_month_logistics`
--
ALTER TABLE `cost_month_logistics`
  ADD CONSTRAINT `fk_cml_month` FOREIGN KEY (`month_id`) REFERENCES `cost_month` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_cml_type` FOREIGN KEY (`logistics_type_id`) REFERENCES `cost_logistics_type` (`id`) ON UPDATE CASCADE;

--
-- Constraints for table `cost_month_section`
--
ALTER TABLE `cost_month_section`
  ADD CONSTRAINT `fk_cost_month_section_month` FOREIGN KEY (`month_id`) REFERENCES `cost_month` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_cost_month_section_section` FOREIGN KEY (`section_id`) REFERENCES `production_sections` (`id`) ON UPDATE CASCADE;

--
-- Constraints for table `flattened_recipe_ingredient`
--
ALTER TABLE `flattened_recipe_ingredient`
  ADD CONSTRAINT `flattened_recipe_ingredient_ibfk_1` FOREIGN KEY (`material_id`) REFERENCES `raw_material` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `flattened_recipe_ingredient_ibfk_3` FOREIGN KEY (`recipe_id`) REFERENCES `product_recipe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `flattened_recipe_recipe`
--
ALTER TABLE `flattened_recipe_recipe`
  ADD CONSTRAINT `flattened_recipe_recipe_ibfk_1` FOREIGN KEY (`recipe_id`) REFERENCES `product_recipe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `flattened_recipe_recipe_ibfk_2` FOREIGN KEY (`subrecipe_id`) REFERENCES `product_recipe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `material_allergen_connection`
--
ALTER TABLE `material_allergen_connection`
  ADD CONSTRAINT `material_allergen_connection_ibfk_1` FOREIGN KEY (`allergen_id`) REFERENCES `allergen` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `material_allergen_connection_ibfk_2` FOREIGN KEY (`material_id`) REFERENCES `raw_material` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `predefined_recipe_label`
--
ALTER TABLE `predefined_recipe_label`
  ADD CONSTRAINT `predefined_recipe_label_ibfk_1` FOREIGN KEY (`recipe_id`) REFERENCES `product_recipe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `product_recipe_connection`
--
ALTER TABLE `product_recipe_connection`
  ADD CONSTRAINT `product_recipe_connection_ibfk_1` FOREIGN KEY (`child_ingredient_id`) REFERENCES `raw_material` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `product_recipe_connection_ibfk_2` FOREIGN KEY (`child_recipe_id`) REFERENCES `product_recipe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `product_recipe_connection_ibfk_3` FOREIGN KEY (`parent_recipe_id`) REFERENCES `product_recipe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `purchase_item`
--
ALTER TABLE `purchase_item`
  ADD CONSTRAINT `fk_pi_doc` FOREIGN KEY (`purchase_document_id`) REFERENCES `purchase_document` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_pi_rawmat` FOREIGN KEY (`raw_material_id`) REFERENCES `raw_material` (`id`);

--
-- Constraints for table `raw_material_alias`
--
ALTER TABLE `raw_material_alias`
  ADD CONSTRAINT `raw_material_alias_ibfk_1` FOREIGN KEY (`material_id`) REFERENCES `raw_material` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `recipe_competency_connection`
--
ALTER TABLE `recipe_competency_connection`
  ADD CONSTRAINT `fk_rcc_competency` FOREIGN KEY (`competency_id`) REFERENCES `recipe_competency` (`id`) ON DELETE CASCADE;
COMMIT;

/*!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 */;
