surrealdb_core/
fflags.rs

1//! Feature flags for SurrealDB
2//! This is a public scope module that is not for external use
3//! It is public for API access
4/// FeatureFlags set for the project
5/// Use this while implementing features
6#[allow(dead_code)]
7pub static FFLAGS: FFlags = FFlags {
8	// TODO(fflag-lqcf): This TODO signature marks tests that are affected by the fflag that do not have access to the fflag (scope)
9    change_feed_live_queries: FFlagEnabledStatus {
10        enabled_release: false,
11        enabled_debug: false,
12        enabled_test: false,
13        env_override: "SURREALDB_CHANGE_FEED_LIVE_QUERIES",
14        owner: "Hugh Kaznowski",
15        description: "Disables live queries as a separate feature and moves to using change feeds as the underlying mechanism",
16        date_enabled_test: None,
17        date_enabled_debug: None,
18        date_enabled_release: None,
19        release_version: None,
20    }
21};
22
23#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
24#[allow(dead_code)]
25#[non_exhaustive]
26pub struct FFlags {
27	pub change_feed_live_queries: FFlagEnabledStatus,
28}
29
30/// This struct is not used in the implementation;
31/// All the fields are here as information for people investigating the feature flag.
32#[allow(dead_code)]
33#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
34#[non_exhaustive]
35pub struct FFlagEnabledStatus {
36	pub(crate) enabled_release: bool,
37	pub(crate) enabled_debug: bool,
38	pub(crate) enabled_test: bool,
39	pub(crate) owner: &'static str,
40	pub(crate) description: &'static str,
41	pub(crate) env_override: &'static str,
42	pub(crate) date_enabled_test: Option<&'static str>,
43	pub(crate) date_enabled_debug: Option<&'static str>,
44	pub(crate) date_enabled_release: Option<&'static str>,
45	pub(crate) release_version: Option<&'static str>,
46}
47
48impl FFlagEnabledStatus {
49	#[allow(dead_code)]
50	pub fn enabled(&self) -> bool {
51		let mut enabled = false;
52		if let Ok(env_var) = std::env::var(self.env_override) {
53			if env_var.trim() == "true" {
54				return true;
55			}
56			return false;
57		}
58		// Test check
59		#[cfg(test)]
60		{
61			enabled = enabled || self.enabled_test;
62		}
63		// Debug build check
64		#[cfg(debug_assertions)]
65		{
66			enabled = enabled || self.enabled_debug;
67		}
68		// Release build check
69		#[cfg(not(debug_assertions))]
70		{
71			enabled = enabled || self.enabled_release;
72		}
73		enabled
74	}
75}