:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(clickhouse): rename aux golden/sql files off a reserved name (#73002)
Tommy Gilmoreec30097e3b53
diff --git a/posthog/clickhouse/hcl/check-live.sh b/posthog/clickhouse/hcl/check-live.shindex d7254e00eab0..6d6d9b0f479c 100755--- a/posthog/clickhouse/hcl/check-live.sh+++ b/posthog/clickhouse/hcl/check-live.sh@@ -68,7 +68,7 @@ sys.exit(1 if drift else 0)rc=0for role in "${ROLES[@]}"; do- golden="$GOLDEN/$ENV/$role.hcl"+ golden="$GOLDEN/$ENV/$(golden_name "$role").hcl"live="$DUMPDIR/$ENV-$role.hcl" # transient dump, flat name from dump-live.shif [ ! -f "$golden" ]; thendiff --git a/posthog/clickhouse/hcl/check.sh b/posthog/clickhouse/hcl/check.shindex cf48ab2276b2..b4e62abf0f6b 100755--- a/posthog/clickhouse/hcl/check.sh+++ b/posthog/clickhouse/hcl/check.sh@@ -60,6 +60,25 @@ if [ -n "$gone_dups" ]; thenfi[ -z "$new_dups$gone_dups" ] && echo "duplicates match baseline ($(printf '%s\n' "$baseline_dups" | grep -c .) objects)"+# Windows guard: golden/ and sql/ are committed and checked out on every platform, so+# no file may bear a Windows-reserved device name — git refuses to check those out+# (core.protectNTFS) and NTFS rejects them, breaking the repo for Windows contributors.+# The gen scripts alias such roles via golden_name (lib.sh); this asserts none slipped+# through (a new reserved-name role, or a hand-added file).+echo "== filenames: no Windows-reserved names in golden/ and sql/ =="+reserved=""+while IFS= read -r f; do+ is_reserved_basename "$f" && reserved="$reserved $f"$'\n'+done < <(find "$GOLDEN" "$HCL/sql" -type f \( -name '*.hcl' -o -name '*.sql' \))+if [ -n "$reserved" ]; then+ echo "FAIL: committed schema files use Windows-reserved device names:"+ printf '%s' "$reserved"+ echo " rename via a golden_name alias in lib.sh (and codegen/gen_migration.py), then regen."+ rc=1+else+ echo "no reserved filenames"+fi+# Hoisted into assignments (not `for x in $(...)`) so set -e aborts on a failed# load instead of silently iterating zero times — see lib.sh.envs="$(manifest_envs)"@@ -75,7 +94,7 @@ donefor env in $envs; doroles="$(manifest_roles "$env")"for role in $roles; do- golden="$GOLDEN/$env/$role.hcl"+ golden="$GOLDEN/$env/$(golden_name "$role").hcl"if [ ! -f "$golden" ]; thenecho "== $env/$role: no golden (validate only) =="continuediff --git a/posthog/clickhouse/hcl/codegen/gen_migration.py b/posthog/clickhouse/hcl/codegen/gen_migration.pyindex 86828127f371..90880beb6360 100644--- a/posthog/clickhouse/hcl/codegen/gen_migration.py+++ b/posthog/clickhouse/hcl/codegen/gen_migration.py@@ -82,21 +82,36 @@ def manifest_roles(env: str) -> list[str]:return [r["role"] for r in json.loads(out)["roles"]]+def golden_name(role: str) -> str:+ """Windows-safe on-disk basename for a role's golden/sql files (mirrors lib.sh).++ `aux` is a reserved DOS device name that can't be a path component on Windows, so+ its files are stored as `auxiliary`. The role identity itself is unchanged.+ """+ return {"aux": "auxiliary"}.get(role, role)++def golden_at_ref(ref: str, env: str, role: str) -> str:"""Read the composed golden for (env, role) at `ref`.- Tolerates the pre-conversion layout so a migration can still be generated across- the layout-change commit: the current tree uses golden/<env>/<role>.hcl; older refs- use flat golden/<env>-<role>.hcl with env "local" where the manifest now says- "local-multi".+ Tolerates historical layouts so a migration can still be generated across the name+ and layout changes: the current tree uses golden/<env>/<golden_name>.hcl (aux is+ stored as auxiliary.hcl); the pre-rename tree used golden/<env>/<role>.hcl; older+ refs still use flat golden/<env>-<role>.hcl with env "local" where the manifest now+ says "local-multi"."""legacy_env = "local" if env == "local-multi" else env- for path in (f"{HCL_REL}/golden/{env}/{role}.hcl", f"{HCL_REL}/golden/{legacy_env}-{role}.hcl"):+ candidates = [+ f"{HCL_REL}/golden/{env}/{golden_name(role)}.hcl",+ f"{HCL_REL}/golden/{env}/{role}.hcl",+ f"{HCL_REL}/golden/{legacy_env}-{role}.hcl",+ ]+ for path in dict.fromkeys(candidates): # de-dupe, keep ordertry:return run(["git", "show", f"{ref}:{path}"])except subprocess.CalledProcessError:continue- raise SystemExit(f"no golden for {env}/{role} at {ref} (tried per-env and legacy flat layout)")+ raise SystemExit(f"no golden for {env}/{role} at {ref} (tried current, pre-rename, and legacy layouts)")def write_dump(env: str, roles: list[str], ref: str, dump_dir: str) -> None:@@ -104,6 +119,9 @@ def write_dump(env: str, roles: list[str], ref: str, dump_dir: str) -> None:os.makedirs(dump_dir)for role in roles:golden = golden_at_ref(ref, env, role)+ # Scratch dump, not committed; plan keys on the hostClusterRole macro, not the+ # filename, so the raw role name is fine here (golden_name aliasing is only for+ # the committed golden/sql files).with open(os.path.join(dump_dir, f"{role}.hcl"), "w") as f:f.write(f'node "{role}" {{\n macros = {{ hostClusterRole = "{role}" }}\n}}\n')f.write(golden)diff --git a/posthog/clickhouse/hcl/gen-golden.sh b/posthog/clickhouse/hcl/gen-golden.shindex a290b52264fd..b859de795c50 100644--- a/posthog/clickhouse/hcl/gen-golden.sh+++ b/posthog/clickhouse/hcl/gen-golden.sh@@ -37,8 +37,13 @@ for env in $envs; dofi# -out-name writes the per-env layout golden/<env>/<role>.hcl directly, creating- # subdirs for us (chschema#146).+ # subdirs for us (chschema#146). hclexp names files by the raw role, so rename any+ # Windows-reserved output to its safe golden_name afterward."$HCLEXP" load -manifest "$MANIFEST" -env "$env" -layer-root "$HCL" "$@" \-out-name '{env}/{role}' -out "$GOLDEN" >/dev/null- for role in $roles; do echo "wrote $GOLDEN/$env/$role.hcl"; done+ for role in $roles; do+ safe="$(golden_name "$role")"+ [ "$safe" != "$role" ] && mv -f "$GOLDEN/$env/$role.hcl" "$GOLDEN/$env/$safe.hcl"+ echo "wrote $GOLDEN/$env/$safe.hcl"+ donedonediff --git a/posthog/clickhouse/hcl/gen-sql.sh b/posthog/clickhouse/hcl/gen-sql.shindex 00d330addc5c..a9ed38248088 100644--- a/posthog/clickhouse/hcl/gen-sql.sh+++ b/posthog/clickhouse/hcl/gen-sql.sh@@ -30,7 +30,7 @@ for env in $envs; doroles="$(manifest_roles "$env")"mkdir -p "$SQL_DIR/$env"for role in $roles; do- out="$SQL_DIR/$env/$role.sql"+ out="$SQL_DIR/$env/$(golden_name "$role").sql"stack="$(manifest_stack "$env" "$role")"{echo "-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit."diff --git a/posthog/clickhouse/hcl/golden/local-multi/aux.hcl b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hclsimilarity index 100%rename from posthog/clickhouse/hcl/golden/local-multi/aux.hclrename to posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcldiff --git a/posthog/clickhouse/hcl/golden/prod-eu/aux.hcl b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hclsimilarity index 100%rename from posthog/clickhouse/hcl/golden/prod-eu/aux.hclrename to posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcldiff --git a/posthog/clickhouse/hcl/golden/prod-us/aux.hcl b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hclsimilarity index 100%rename from posthog/clickhouse/hcl/golden/prod-us/aux.hclrename to posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcldiff --git a/posthog/clickhouse/hcl/lib.sh b/posthog/clickhouse/hcl/lib.shindex 68bcd7bf6286..b1af575c69a0 100644--- a/posthog/clickhouse/hcl/lib.sh+++ b/posthog/clickhouse/hcl/lib.sh@@ -47,3 +47,29 @@ manifest_stack() {"$HCLEXP" load -manifest "$manifest" -env "$env" -layer-root "$root" -format json \| jq -r --arg r "$role" '.roles[] | select(.role == $r) | .resolved_layers | join(",")'}++# On-disk basename for a role's golden/sql files. Normally the role name itself, but+# `aux` is a Windows-reserved device name: git won't check out a path component named+# `aux` (core.protectNTFS) and NTFS rejects it, so its golden/sql files are written and+# read as `auxiliary` (matching the roles/auxiliary/ layer dir). The role identity —+# manifest role, NodeRole.AUX, the `aux` cluster, the hostClusterRole macro — is+# unchanged; only the generated filename differs.+golden_name() {+ case "$1" in+ aux) echo "auxiliary" ;;+ *) echo "$1" ;;+ esac+}++# True (0) if $1's basename stem is a Windows-reserved device name (aux, con, nul,+# com1-9, lpt1-9). Those can't be a path component on Windows regardless of extension:+# git core.protectNTFS blocks the checkout and NTFS rejects the name. Committed golden/+# sql files are cross-platform, so check.sh rejects any such name — give the offending+# role a golden_name alias above.+is_reserved_basename() {+ local stem="${1##*/}"; stem="${stem%%.*}"+ case "$(printf '%s' "$stem" | tr '[:upper:]' '[:lower:]')" in+ con|prn|aux|nul|com[1-9]|lpt[1-9]) return 0 ;;+ *) return 1 ;;+ esac+}diff --git a/posthog/clickhouse/hcl/migration.md b/posthog/clickhouse/hcl/migration.mdindex 278449f7fdb4..11bdb9f8e120 100644--- a/posthog/clickhouse/hcl/migration.md+++ b/posthog/clickhouse/hcl/migration.md@@ -61,16 +61,16 @@ End state: we have 5 environments schemas as HCL, a golden per cluster, somethin- local-multi (in PostHog/posthog):- ops.hcl- posthog.hcl- - aux.hcl+ - auxiliary.hcl- ...- dev (in posthog-cloud-infra):- posthog.hcl- - aux.hcl+ - auxiliary.hcl- sessions.hcl- ...- prod-us (in posthog-cloud-infra):- posthog.hcl- - aux.hcl+ - auxiliary.hcl- sessions.hcl- ai_events.hcl- ops.hcldiff --git a/posthog/clickhouse/hcl/sql/local-multi/aux.sql b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sqlsimilarity index 100%rename from posthog/clickhouse/hcl/sql/local-multi/aux.sqlrename to posthog/clickhouse/hcl/sql/local-multi/auxiliary.sqldiff --git a/posthog/clickhouse/hcl/sql/prod-eu/aux.sql b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sqlsimilarity index 100%rename from posthog/clickhouse/hcl/sql/prod-eu/aux.sqlrename to posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sqldiff --git a/posthog/clickhouse/hcl/sql/prod-us/aux.sql b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sqlsimilarity index 100%rename from posthog/clickhouse/hcl/sql/prod-us/aux.sqlrename to posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql