2024-02-06 14:46:44 +00:00
|
|
|
//! Feature flags for SurrealDB
|
|
|
|
//! This is a public scope module that is not for external use
|
|
|
|
//! It is public for API access
|
|
|
|
///
|
|
|
|
|
|
|
|
/// FeatureFlags set for the project
|
|
|
|
/// Use this while implementing features
|
2024-01-25 15:31:30 +00:00
|
|
|
#[allow(dead_code)]
|
2024-02-06 14:46:44 +00:00
|
|
|
pub static FFLAGS: FFlags = FFlags {
|
2024-02-20 11:11:49 +00:00
|
|
|
// TODO(fflag-lqcf): This TODO signature marks tests that are affected by the fflag that do not have access to the fflag (scope)
|
2024-01-25 15:31:30 +00:00
|
|
|
change_feed_live_queries: FFlagEnabledStatus {
|
|
|
|
enabled_release: false,
|
|
|
|
enabled_debug: false,
|
|
|
|
enabled_test: false,
|
|
|
|
env_override: "SURREALDB_CHANGE_FEED_LIVE_QUERIES",
|
|
|
|
owner: "Hugh Kaznowski",
|
|
|
|
description: "Disables live queries as a separate feature and moves to using change feeds as the underlying mechanism",
|
|
|
|
date_enabled_test: None,
|
|
|
|
date_enabled_debug: None,
|
|
|
|
date_enabled_release: None,
|
|
|
|
release_version: None,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
|
|
|
#[allow(dead_code)]
|
2024-04-02 20:12:08 +00:00
|
|
|
#[non_exhaustive]
|
2024-02-06 14:46:44 +00:00
|
|
|
pub struct FFlags {
|
|
|
|
pub change_feed_live_queries: FFlagEnabledStatus,
|
2024-01-25 15:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// This struct is not used in the implementation;
|
|
|
|
/// All the fields are here as information for people investigating the feature flag.
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
2024-04-02 20:12:08 +00:00
|
|
|
#[non_exhaustive]
|
2024-02-06 14:46:44 +00:00
|
|
|
pub struct FFlagEnabledStatus {
|
2024-01-25 15:31:30 +00:00
|
|
|
pub(crate) enabled_release: bool,
|
|
|
|
pub(crate) enabled_debug: bool,
|
|
|
|
pub(crate) enabled_test: bool,
|
|
|
|
pub(crate) owner: &'static str,
|
|
|
|
pub(crate) description: &'static str,
|
|
|
|
pub(crate) env_override: &'static str,
|
|
|
|
pub(crate) date_enabled_test: Option<&'static str>,
|
|
|
|
pub(crate) date_enabled_debug: Option<&'static str>,
|
|
|
|
pub(crate) date_enabled_release: Option<&'static str>,
|
|
|
|
pub(crate) release_version: Option<&'static str>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FFlagEnabledStatus {
|
|
|
|
#[allow(dead_code)]
|
2024-02-06 14:46:44 +00:00
|
|
|
pub fn enabled(&self) -> bool {
|
2024-01-25 15:31:30 +00:00
|
|
|
let mut enabled = false;
|
|
|
|
if let Ok(env_var) = std::env::var(self.env_override) {
|
|
|
|
if env_var.trim() == "true" {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Test check
|
|
|
|
#[cfg(test)]
|
|
|
|
{
|
|
|
|
enabled = enabled || self.enabled_test;
|
|
|
|
}
|
|
|
|
// Debug build check
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
{
|
|
|
|
enabled = enabled || self.enabled_debug;
|
|
|
|
}
|
|
|
|
// Release build check
|
|
|
|
#[cfg(not(debug_assertions))]
|
|
|
|
{
|
|
|
|
enabled = enabled || self.enabled_release;
|
|
|
|
}
|
|
|
|
enabled
|
|
|
|
}
|
|
|
|
}
|