-- ============================================================
--  BharatERP - Complete Database Schema v2.0
--  Run this file after installation
-- ============================================================

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ------------------------------------------------------------
-- COMPANIES
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `companies` (
  `id`                  INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `name`                VARCHAR(255) NOT NULL,
  `legal_name`          VARCHAR(255),
  `gstin`               VARCHAR(20),
  `pan`                 VARCHAR(20),
  `email`               VARCHAR(255),
  `phone`               VARCHAR(20),
  `address`             TEXT,
  `city`                VARCHAR(100),
  `state`               VARCHAR(100) DEFAULT 'Maharashtra',
  `pincode`             VARCHAR(10),
  `country`             VARCHAR(50) DEFAULT 'India',
  `logo`                VARCHAR(500),
  `currency`            VARCHAR(10) DEFAULT 'INR',
  `financial_year_start` VARCHAR(10) DEFAULT '04-01',
  `gst_registered`      TINYINT(1) DEFAULT 1,
  `business_type`       ENUM('supermarket','wholesale','manufacturing','retail','distributor','medical','agency','other') DEFAULT 'retail',
  `invoice_prefix`      VARCHAR(20) DEFAULT 'INV',
  `invoice_counter`     INT UNSIGNED DEFAULT 1,
  `po_prefix`           VARCHAR(20) DEFAULT 'PO',
  `po_counter`          INT UNSIGNED DEFAULT 1,
  `is_active`           TINYINT(1) DEFAULT 1,
  `timezone`            VARCHAR(50) DEFAULT 'Asia/Kolkata',
  `created_at`          TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`          TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- USERS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `users` (
  `id`           INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`   INT UNSIGNED NOT NULL DEFAULT 1,
  `name`         VARCHAR(255) NOT NULL,
  `email`        VARCHAR(255) NOT NULL,
  `password`     VARCHAR(255) NOT NULL,
  `phone`        VARCHAR(20),
  `role`         ENUM('super_admin','admin','manager','cashier','accountant','warehouse','sales','viewer') DEFAULT 'cashier',
  `is_active`    TINYINT(1) DEFAULT 1,
  `last_login`   TIMESTAMP NULL,
  `last_ip`      VARCHAR(45),
  `remember_token` VARCHAR(100),
  `created_at`   TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`   TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `uk_email` (`email`),
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- WAREHOUSES
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `warehouses` (
  `id`          INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`  INT UNSIGNED NOT NULL DEFAULT 1,
  `name`        VARCHAR(255) NOT NULL,
  `code`        VARCHAR(50),
  `address`     TEXT,
  `city`        VARCHAR(100),
  `state`       VARCHAR(100),
  `is_default`  TINYINT(1) DEFAULT 0,
  `is_active`   TINYINT(1) DEFAULT 1,
  `created_at`  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- CATEGORIES
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `categories` (
  `id`          INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`  INT UNSIGNED NOT NULL DEFAULT 1,
  `name`        VARCHAR(255) NOT NULL,
  `parent_id`   INT UNSIGNED DEFAULT NULL,
  `description` TEXT,
  `is_active`   TINYINT(1) DEFAULT 1,
  `sort_order`  INT DEFAULT 0,
  `created_at`  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- UNITS OF MEASUREMENT
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `units` (
  `id`          INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`  INT UNSIGNED NOT NULL DEFAULT 1,
  `name`        VARCHAR(100) NOT NULL,
  `abbreviation` VARCHAR(20) NOT NULL,
  `is_active`   TINYINT(1) DEFAULT 1,
  `created_at`  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- PRODUCTS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `products` (
  `id`              INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`      INT UNSIGNED NOT NULL DEFAULT 1,
  `name`            VARCHAR(255) NOT NULL,
  `description`     TEXT,
  `sku`             VARCHAR(100),
  `barcode`         VARCHAR(100),
  `category_id`     INT UNSIGNED DEFAULT NULL,
  `unit_id`         INT UNSIGNED DEFAULT NULL,
  `purchase_price`  DECIMAL(12,2) DEFAULT 0.00,
  `selling_price`   DECIMAL(12,2) DEFAULT 0.00,
  `mrp`             DECIMAL(12,2) DEFAULT 0.00,
  `gst_rate`        DECIMAL(5,2) DEFAULT 0.00,
  `hsn_code`        VARCHAR(20),
  `min_stock`       DECIMAL(10,2) DEFAULT 0,
  `is_active`       TINYINT(1) DEFAULT 1,
  `track_inventory` TINYINT(1) DEFAULT 1,
  `image`           VARCHAR(500),
  `created_by`      INT UNSIGNED DEFAULT NULL,
  `created_at`      TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`      TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`),
  INDEX `idx_sku`  (`sku`),
  INDEX `idx_barcode` (`barcode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- INVENTORY (per warehouse)
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `inventory` (
  `id`            INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`    INT UNSIGNED NOT NULL DEFAULT 1,
  `product_id`    INT UNSIGNED NOT NULL,
  `warehouse_id`  INT UNSIGNED NOT NULL DEFAULT 1,
  `quantity`      DECIMAL(12,3) DEFAULT 0,
  `min_quantity`  DECIMAL(12,3) DEFAULT 0,
  `updated_at`    TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `uk_prod_wh` (`product_id`, `warehouse_id`),
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- STOCK MOVEMENTS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `stock_movements` (
  `id`             INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`     INT UNSIGNED NOT NULL DEFAULT 1,
  `product_id`     INT UNSIGNED NOT NULL,
  `warehouse_id`   INT UNSIGNED NOT NULL DEFAULT 1,
  `movement_type`  ENUM('in','out','adjustment','transfer') NOT NULL,
  `quantity`       DECIMAL(12,3) NOT NULL,
  `reference_type` VARCHAR(50),
  `reference_id`   INT UNSIGNED,
  `notes`          VARCHAR(500),
  `created_by`     INT UNSIGNED,
  `created_at`     TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`),
  INDEX `idx_product` (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- CUSTOMERS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `customers` (
  `id`              INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`      INT UNSIGNED NOT NULL DEFAULT 1,
  `name`            VARCHAR(255) NOT NULL,
  `email`           VARCHAR(255),
  `phone`           VARCHAR(20),
  `gstin`           VARCHAR(20),
  `pan`             VARCHAR(20),
  `address`         TEXT,
  `city`            VARCHAR(100),
  `state`           VARCHAR(100),
  `pincode`         VARCHAR(10),
  `customer_type`   ENUM('retail','wholesale','corporate','export') DEFAULT 'retail',
  `credit_limit`    DECIMAL(12,2) DEFAULT 0,
  `credit_days`     INT DEFAULT 30,
  `opening_balance` DECIMAL(12,2) DEFAULT 0,
  `is_active`       TINYINT(1) DEFAULT 1,
  `created_by`      INT UNSIGNED,
  `created_at`      TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`      TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- VENDORS / SUPPLIERS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `vendors` (
  `id`              INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`      INT UNSIGNED NOT NULL DEFAULT 1,
  `name`            VARCHAR(255) NOT NULL,
  `email`           VARCHAR(255),
  `phone`           VARCHAR(20),
  `gstin`           VARCHAR(20),
  `pan`             VARCHAR(20),
  `address`         TEXT,
  `city`            VARCHAR(100),
  `state`           VARCHAR(100),
  `pincode`         VARCHAR(10),
  `payment_terms`   INT DEFAULT 30,
  `opening_balance` DECIMAL(12,2) DEFAULT 0,
  `is_active`       TINYINT(1) DEFAULT 1,
  `created_by`      INT UNSIGNED,
  `created_at`      TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`      TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- SALES (Invoices, Quotations, Orders, Challans, Returns)
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `sales` (
  `id`               INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`       INT UNSIGNED NOT NULL DEFAULT 1,
  `invoice_number`   VARCHAR(50) NOT NULL,
  `type`             ENUM('invoice','quotation','sales_order','delivery_challan','sales_return') DEFAULT 'invoice',
  `customer_id`      INT UNSIGNED DEFAULT NULL,
  `warehouse_id`     INT UNSIGNED DEFAULT 1,
  `invoice_date`     DATE NOT NULL,
  `due_date`         DATE DEFAULT NULL,
  `subtotal`         DECIMAL(12,2) DEFAULT 0,
  `discount_percent` DECIMAL(5,2) DEFAULT 0,
  `discount_amount`  DECIMAL(12,2) DEFAULT 0,
  `tax_amount`       DECIMAL(12,2) DEFAULT 0,
  `total_amount`     DECIMAL(12,2) DEFAULT 0,
  `paid_amount`      DECIMAL(12,2) DEFAULT 0,
  `payment_mode`     ENUM('cash','upi','card','credit','bank','cheque') DEFAULT 'cash',
  `payment_status`   ENUM('paid','unpaid','partial') DEFAULT 'unpaid',
  `notes`            TEXT,
  `created_by`       INT UNSIGNED,
  `deleted_at`       TIMESTAMP NULL,
  `created_at`       TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`       TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `uk_invoice` (`company_id`, `invoice_number`),
  INDEX `idx_company` (`company_id`),
  INDEX `idx_date` (`invoice_date`),
  INDEX `idx_customer` (`customer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- SALE ITEMS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `sale_items` (
  `id`               INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `sale_id`          INT UNSIGNED NOT NULL,
  `product_id`       INT UNSIGNED NOT NULL,
  `quantity`         DECIMAL(12,3) NOT NULL,
  `unit_price`       DECIMAL(12,2) NOT NULL,
  `discount_percent` DECIMAL(5,2) DEFAULT 0,
  `gst_rate`         DECIMAL(5,2) DEFAULT 0,
  `tax_amount`       DECIMAL(12,2) DEFAULT 0,
  `total_price`      DECIMAL(12,2) NOT NULL,
  INDEX `idx_sale` (`sale_id`),
  INDEX `idx_product` (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- PURCHASES (Bills, Orders, GRN, Returns)
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `purchases` (
  `id`                 INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`         INT UNSIGNED NOT NULL DEFAULT 1,
  `bill_number`        VARCHAR(50) NOT NULL,
  `type`               ENUM('purchase_invoice','purchase_order','grn','purchase_return') DEFAULT 'purchase_invoice',
  `vendor_id`          INT UNSIGNED DEFAULT NULL,
  `warehouse_id`       INT UNSIGNED DEFAULT 1,
  `bill_date`          DATE NOT NULL,
  `due_date`           DATE DEFAULT NULL,
  `vendor_bill_number` VARCHAR(100),
  `subtotal`           DECIMAL(12,2) DEFAULT 0,
  `discount_percent`   DECIMAL(5,2) DEFAULT 0,
  `discount_amount`    DECIMAL(12,2) DEFAULT 0,
  `tax_amount`         DECIMAL(12,2) DEFAULT 0,
  `total_amount`       DECIMAL(12,2) DEFAULT 0,
  `paid_amount`        DECIMAL(12,2) DEFAULT 0,
  `payment_mode`       ENUM('cash','upi','card','credit','bank','cheque') DEFAULT 'credit',
  `payment_status`     ENUM('paid','unpaid','partial') DEFAULT 'unpaid',
  `notes`              TEXT,
  `created_by`         INT UNSIGNED,
  `deleted_at`         TIMESTAMP NULL,
  `created_at`         TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`         TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`),
  INDEX `idx_date`    (`bill_date`),
  INDEX `idx_vendor`  (`vendor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- PURCHASE ITEMS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `purchase_items` (
  `id`               INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `purchase_id`      INT UNSIGNED NOT NULL,
  `product_id`       INT UNSIGNED NOT NULL,
  `quantity`         DECIMAL(12,3) NOT NULL,
  `unit_price`       DECIMAL(12,2) NOT NULL,
  `discount_percent` DECIMAL(5,2) DEFAULT 0,
  `gst_rate`         DECIMAL(5,2) DEFAULT 0,
  `tax_amount`       DECIMAL(12,2) DEFAULT 0,
  `total_price`      DECIMAL(12,2) NOT NULL,
  INDEX `idx_purchase` (`purchase_id`),
  INDEX `idx_product`  (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- PAYMENTS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `payments` (
  `id`           INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`   INT UNSIGNED NOT NULL DEFAULT 1,
  `sale_id`      INT UNSIGNED DEFAULT NULL,
  `purchase_id`  INT UNSIGNED DEFAULT NULL,
  `amount`       DECIMAL(12,2) NOT NULL,
  `payment_mode` ENUM('cash','upi','card','bank','cheque') DEFAULT 'cash',
  `payment_date` DATE NOT NULL,
  `reference`    VARCHAR(200),
  `notes`        VARCHAR(500),
  `created_by`   INT UNSIGNED,
  `created_at`   TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- EXPENSES
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `expenses` (
  `id`           INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`   INT UNSIGNED NOT NULL DEFAULT 1,
  `category`     VARCHAR(100) NOT NULL,
  `description`  VARCHAR(500) NOT NULL,
  `amount`       DECIMAL(12,2) NOT NULL,
  `gst_amount`   DECIMAL(12,2) DEFAULT 0,
  `expense_date` DATE NOT NULL,
  `payment_mode` ENUM('cash','upi','card','bank','cheque') DEFAULT 'cash',
  `vendor_id`    INT UNSIGNED DEFAULT NULL,
  `reference`    VARCHAR(200),
  `created_by`   INT UNSIGNED,
  `created_at`   TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`),
  INDEX `idx_date`    (`expense_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- ACCOUNTS (Chart of Accounts)
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `accounts` (
  `id`          INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`  INT UNSIGNED NOT NULL DEFAULT 1,
  `code`        VARCHAR(20) NOT NULL,
  `name`        VARCHAR(255) NOT NULL,
  `type`        ENUM('asset','liability','equity','income','expense') NOT NULL,
  `description` VARCHAR(500),
  `is_system`   TINYINT(1) DEFAULT 0,
  `is_active`   TINYINT(1) DEFAULT 1,
  `created_at`  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- JOURNAL ENTRIES
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `journal_entries` (
  `id`               INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`       INT UNSIGNED NOT NULL DEFAULT 1,
  `entry_date`       DATE NOT NULL,
  `reference_number` VARCHAR(50),
  `description`      VARCHAR(500) NOT NULL,
  `created_by`       INT UNSIGNED,
  `created_at`       TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- JOURNAL LINES
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `journal_lines` (
  `id`               INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `journal_entry_id` INT UNSIGNED NOT NULL,
  `account_id`       INT UNSIGNED NOT NULL,
  `description`      VARCHAR(500),
  `debit_amount`     DECIMAL(12,2) DEFAULT 0,
  `credit_amount`    DECIMAL(12,2) DEFAULT 0,
  INDEX `idx_entry` (`journal_entry_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- CRM LEADS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `crm_leads` (
  `id`               INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`       INT UNSIGNED NOT NULL DEFAULT 1,
  `name`             VARCHAR(255) NOT NULL,
  `email`            VARCHAR(255),
  `phone`            VARCHAR(20),
  `company`          VARCHAR(255),
  `source`           VARCHAR(100),
  `status`           ENUM('new','contacted','qualified','proposal','negotiation','won','lost') DEFAULT 'new',
  `estimated_value`  DECIMAL(12,2) DEFAULT 0,
  `notes`            TEXT,
  `assigned_to`      INT UNSIGNED,
  `follow_up_date`   DATE DEFAULT NULL,
  `created_by`       INT UNSIGNED,
  `created_at`       TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`       TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`),
  INDEX `idx_status`  (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- NOTIFICATIONS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `notifications` (
  `id`          INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`  INT UNSIGNED NOT NULL DEFAULT 1,
  `user_id`     INT UNSIGNED DEFAULT NULL,
  `title`       VARCHAR(255) NOT NULL,
  `message`     TEXT,
  `type`        ENUM('info','warning','error','success') DEFAULT 'info',
  `is_read`     TINYINT(1) DEFAULT 0,
  `created_at`  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_company` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ------------------------------------------------------------
-- SETTINGS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `settings` (
  `id`          INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `company_id`  INT UNSIGNED NOT NULL DEFAULT 1,
  `key`         VARCHAR(100) NOT NULL,
  `value`       TEXT,
  `created_at`  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at`  TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `uk_company_key` (`company_id`, `key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

SET FOREIGN_KEY_CHECKS = 1;
