Skip to main content

no_mistakes_postgres_sql/
sql_include_policy.rs

1use super::PostgresSchemaOptions;
2
3/// SQL globs after the empty-list default.
4///
5/// An unlocked empty list still becomes `**/*.sql`. A list locked by project
6/// scope stays as written, including when that list is empty.
7#[doc(hidden)]
8pub fn effective_sql_include(patterns: &[String], locked: bool) -> Vec<String> {
9    if locked || !patterns.is_empty() {
10        patterns.to_vec()
11    } else {
12        PostgresSchemaOptions::default().sql_include
13    }
14}
15
16/// Profile aggregation. Three rules already keep an empty list (no SQL sources
17/// or no extra SQL filter) even when the list is not locked.
18#[doc(hidden)]
19pub fn profile_sql_include(rule_id: &str, patterns: Vec<String>, locked: bool) -> Vec<String> {
20    if locked || !patterns.is_empty() || keeps_empty_sql_include(rule_id) {
21        patterns
22    } else {
23        PostgresSchemaOptions::default().sql_include
24    }
25}
26
27fn keeps_empty_sql_include(rule_id: &str) -> bool {
28    matches!(
29        rule_id,
30        "postgres-explicit-columns" | "postgres-bounded-statements" | "postgres-no-offset"
31    )
32}
33
34#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
35mod tests;