Skip to main content

Module profile_files

Module profile_files 

Source
Expand description

Profile-specific file override resolution.

Files can be named name#<profile>.sql to override name.sql when a particular profile is active. The # delimiter is split on the last occurrence (rsplit_once).

ยงResolution Algorithm

  1. Parse each file stem via parse_file_stem using rsplit_once('#') to separate (object_name, profile). Files without # (or with an empty object/profile part) are treated as the default (no profile).
  2. Group files by object name into ObjectFiles, recording the default file and any profile-specific overrides. Duplicates within the same group (e.g., two defaults, or two overrides for the same profile) are rejected with LoadError::DuplicateProfileObject.

Callers select the active variant themselves by checking overrides.get(profile).or(default.as_ref()).

Key Insight: # cannot appear in a SQL identifier, so a well-formed variant filename contains exactly one #. This lets object names freely contain underscores: my_pg_conn#staging โ†’ ("my_pg_conn", "staging").

Structsยง

ObjectFiles ๐Ÿ”’
All files for a single object name, grouped by profile.

Functionsยง

collect_all_sql_files ๐Ÿ”’
Collect all .sql files from a directory grouped by object name without resolving.
parse_file_stem ๐Ÿ”’
Split a file stem into (object_name, optional_profile).