CREATE TABLE business_rules (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(160) NOT NULL,
    slug VARCHAR(190) NOT NULL,
    description TEXT NULL,
    category VARCHAR(80) NOT NULL,
    rule_json JSON NOT NULL,
    is_active TINYINT(1) NOT NULL DEFAULT 1,
    priority SMALLINT UNSIGNED NOT NULL DEFAULT 100,
    version INT UNSIGNED NOT NULL DEFAULT 1,
    created_by INT UNSIGNED NULL,
    updated_by INT UNSIGNED NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_business_rules_category (category),
    INDEX idx_business_rules_active (is_active, category),
    UNIQUE KEY uq_business_rules_slug (slug),
    CONSTRAINT fk_business_rules_creator FOREIGN KEY (created_by) REFERENCES users (id) ON DELETE SET NULL,
    CONSTRAINT fk_business_rules_updater FOREIGN KEY (updated_by) REFERENCES users (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

