accountpredicate

package
v0.0.0-...-a99bcb5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: OSL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package accountpredicate builds the dual-column account WHERE fragment shared by every read path that scopes savings_snapshots or purchase_history rows to a set of cloud accounts (issue #120). Keeping the one builder here means a predicate fix is a single edit instead of three that can drift.

Both tables carry two account identifiers, either of which may be the only one populated on a row: cloud_account_id (the cloud_accounts UUID FK, NULL on the AWS ambient and legacy rows) and account_id (the cloud-provider external number). Matching only cloud_account_id silently dropped every NULL row (issues #701/#498) and matching only account_id dropped UUID-only rows (#866), so the predicate ORs both:

(cloud_account_id = ANY($u)
   OR <provider gate for p1> AND account_id = ANY($e1)
   OR ...)

The external-id half is grouped per provider so each external number only matches rows of its own provider, preserving the (provider, external_id) pairing: a filter for aws/123 never pulls azure/123 rows. The "" provider key (legacy raw external number, unknown provider) matches account_id with no provider gate. cloud_account_id is compared directly (no ::text cast) so the plain cloud_account_id UUID index (migration 000011) can back it. Providers are sorted so the SQL and its bind order are deterministic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(args []any, accountUUIDs []string, externalIDsByProvider map[string][]string, match ProviderMatch) (clause string, outArgs []any)

Build appends the account binds to args and returns the parenthesized OR clause that references them by position, plus the extended args. When neither input yields a disjunct (both empty, or every provider key maps to no IDs) it returns an empty clause and args unchanged; each caller decides what "no account filter" means for its query.

Types

type ProviderMatch

type ProviderMatch int

ProviderMatch selects how the per-provider gate compares the stored provider column with the filter's provider key.

const (
	// ProviderExact gates on `provider = $p`. Used by the analytics reads of
	// savings_snapshots and purchase_history.
	ProviderExact ProviderMatch = iota

	// ProviderCaseInsensitiveOrUnknown gates on
	// `(provider = ” OR LOWER(provider) = LOWER($p))`, so a row stored as
	// "AWS" still matches an "aws" filter and a row with an empty (unknown)
	// stored provider matches on account_id alone, like the "" filter key
	// does (issue #24). A row stored under a different, non-empty provider is
	// still excluded. Used by the internal/config purchase_history reads.
	ProviderCaseInsensitiveOrUnknown
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL