Path: redb/redb.Postgres/sql/v2-pvt/_fork-legacy-helpers.ps1 Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Postgres/sql/v2-pvt/_fork-legacy-helpers.ps1 ---- # ===================================================================== # _fork-legacy-helpers.ps1 # --------------------------------------------------------------------- # One-shot script that forks 8 helper functions from legacy SQL into # the v2-pvt module under the pvt_* prefix. # # Usage (from repo root): # pwsh redb.Postgres/sql/v2-pvt/_fork-legacy-helpers.ps1 # # Idempotent: overwrites target files every run. # Does NOT touch legacy SQL files. # ===================================================================== [CmdletBinding()] param( [string]$RepoRoot = (Resolve-Path "$PSScriptRoot/../../..").Path, [string]$ForkDate = '2026-05-18' ) $ErrorActionPreference = 'Stop' $facets = Join-Path $RepoRoot 'redb.Postgres/sql/redb_facets_search.sql' $lazy = Join-Path $RepoRoot 'redb.Postgres/sql/redb_lazy_loading_search.sql' $outDir = Join-Path $RepoRoot 'redb.Postgres/sql/v2-pvt' if (-not (Test-Path $facets)) { throw "Source not found: $facets" } if (-not (Test-Path $lazy)) { throw "Source not found: $lazy" } $facetsLines = Get-Content -LiteralPath $facets $lazyLines = Get-Content -LiteralPath $lazy # Cross-reference replacements applied to every forked function body. # Order matters only if patterns overlap — these do not. $nameMap = @( @{ From = '_normalize_base_field_name'; To = 'pvt_normalize_base_field_name' } @{ From = '_parse_field_path'; To = 'pvt_parse_field_path' } @{ From = '_get_listitem_field_type_info';To = 'pvt_get_listitem_field_type_info' } @{ From = '_find_structure_info'; To = 'pvt_find_structure_info' } @{ From = '_build_inner_condition'; To = 'pvt_build_inner_condition' } @{ From = '_build_single_facet_condition';To = 'pvt_build_single_facet_condition' } @{ From = 'build_hierarchical_conditions';To = 'pvt_build_hierarchical_conditions' } @{ From = 'get_object_base_fields'; To = 'pvt_get_object_base_fields' } ) # Note on order: `_get_listitem_field_type_info` shares no overlapping # substring with other From values; `build_hierarchical_conditions` is # matched without the leading underscore by design (legacy uses no # underscore prefix for it). To avoid partial matches we apply with # word-boundary regex below. function Apply-NameMap { param([string[]]$Lines) $text = ($Lines -join "`n") foreach ($m in $nameMap) { # Word-boundary replacement; \b matches start/end of identifier. $pattern = '(?