CREATE TABLE IF NOT EXISTS tenant_feature_overrides (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    tenant_id BIGINT(20) UNSIGNED NOT NULL,
    feature_key VARCHAR(100) NOT NULL,
    feature_value TEXT NOT NULL,
    value_type ENUM('boolean', 'integer', 'string') NOT NULL DEFAULT 'boolean',
    is_active TINYINT(1) NOT NULL DEFAULT 1,
    starts_at DATETIME NULL DEFAULT NULL,
    expires_at DATETIME NULL DEFAULT NULL,
    note VARCHAR(255) NULL DEFAULT NULL,
    created_by INT UNSIGNED NULL DEFAULT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    KEY idx_tenant_feature_overrides_tenant (tenant_id),
    KEY idx_tenant_feature_overrides_feature (feature_key),
    KEY idx_tenant_feature_overrides_active (is_active),
    CONSTRAINT fk_tenant_feature_overrides_tenant
        FOREIGN KEY (tenant_id) REFERENCES tenants(id)
        ON DELETE CASCADE
        ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
