Skip to content

fix(database): schema-qualify ltree @> in has_tree_access for TimescaleDB 2.30 - #216

Merged
murrayju merged 1 commit into
mainfrom
murrayju/fix-has-tree-access-timescaledb-2-30
Oct 13, 2026
Merged

murrayju merged 1 commit into
mainfrom
murrayju/fix-has-tree-access-timescaledb-2-30

Conversation

@murrayju

Copy link
Copy Markdown
Member

Summary

Fix the memory history and revert functions on TimescaleDB 2.30+. has_tree_access now uses operator(public.@>) instead of an unqualified @>.

Problem

CI started to fail on main-equivalent code (seen first on #215) in two space-migration integration tests:

operator does not exist: public.ltree @> public.ltree
where: SQL function "has_tree_access" during inlining
       SQL function "resolve_memory_id_from_history" statement 1

The CI Postgres image (docker/Dockerfile.postgres) installs timescaledb-2-postgresql-18 without a version pin, so it now gets 2.30.2. I bisected with a minimal repro against the TimescaleDB versions in the image:

TimescaleDB result
2.28.3, 2.29.0, 2.29.2 pass
2.30.0, 2.30.2 operator does not exist

The failing pattern: an inlinable SQL function (no set search_path) that uses an extension operator, in the WHERE clause of a hypertable query with ORDER BY <time> LIMIT 1. From 2.30.0, the inlined body does not resolve the operator, although the calling function sets search_path to include public. The same query on a plain table works.

In this schema, that hits resolve_memory_id_from_history and the snapshot lookup in revert_memory (both on the memory_event hypertable). get_memory_history already used operator(public.<@) for its own subtree filter.

Fix

Schema-qualify the operator in has_tree_access. The function stays inlinable (no set search_path), which is why it must not depend on the caller's search_path. Extensions are always installed with schema public (ensureExtension), so the qualifier is safe. has_tree_access and tree_access are the only inlinable SQL functions in the space schema, and tree_access uses no operators.

Idempotent migrations re-run on every boot, so existing spaces get the new body without a schema version bump. The signature does not change.

Production impact

If production moves to TimescaleDB 2.30+, memory.history by path and memory.revert would fail without this fix.

Testing

  • The previously failing tests pass against TimescaleDB 2.30.2: packages/database/space/migrate/migrate.integration.test.ts and packages/server/rpc/memory/memory.integration.test.ts.
  • Full suite (1648 pass, 0 fail), e2e, and lint pass locally.

Copilot AI balanced review requested due to automatic review settings October 13, 2026 16:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟒 Approval recommended

The focused migration change correctly addresses the TimescaleDB regression without changing the function signature or authorization semantics.

0 open findings

What changed in this PR

Schema-qualifies the ltree access operator to preserve history and revert functionality on TimescaleDB 2.30+.

Changes:

  • Uses operator(public.@>) in has_tree_access.
  • Documents why qualification is required for planner inlining.
File Description
packages/​database/​space/​migrate/​idempotent/​001_memory.sql Qualifies the ltree operator in the access check.

🧠 Review effort: Balanced


πŸ’‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@murrayju
murrayju merged commit 587f896 into main Oct 13, 2026
10 of 11 checks passed
@murrayju
murrayju deleted the murrayju/fix-has-tree-access-timescaledb-2-30 branch October 13, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants