Skip to content

Fix SQL schema selector execution#1518

Merged
sorenbs merged 3 commits into
mainfrom
codex/schema-selector-sql
Jun 4, 2026
Merged

Fix SQL schema selector execution#1518
sorenbs merged 3 commits into
mainfrom
codex/schema-selector-sql

Conversation

@sorenbs
Copy link
Copy Markdown
Member

@sorenbs sorenbs commented Jun 4, 2026

Summary

Fixes schema selector handling for SQL execution and related Studio navigation. The SQL view now treats the active schema selector as the default namespace for unqualified identifiers, so queries like select * from order_items work when test_app is selected instead of incorrectly resolving through public.

Root Cause

The SQL view read the selected schema from URL state, but raw SQL execution and SQL linting did not pass it through the adapter/BFF/executor path. Postgres execution therefore used the connection default search_path, and sidebar navigation also dropped the schema URL param when switching between database views.

What Changed

  • Added optional schema support to raw SQL and SQL lint adapter/BFF contracts.
  • Applies selected Postgres schemas through transaction-local search_path for raw execution and lint/EXPLAIN paths.
  • Applies selected schemas in the PGlite executor as well.
  • Uses the active schema for SQL editor autocomplete, linting, AI validation, and raw execution.
  • Preserves the selected schema when switching between Visualizer, Queries, Console, and SQL.
  • Seeds the demo with a test_app schema so non-public schema behavior is reproducible locally.
  • Documents schema-aware SQL behavior in README, FEATURES, and Architecture docs.
  • Adds a minor Changeset for publishing.

Validation

  • pnpm changeset status --since origin/main
  • Scoped ESLint over all changed TS/TSX files
  • pnpm vitest run ui/studio/Navigation.test.tsx ui/hooks/use-navigation.test.tsx ui/studio/views/sql/SqlView.test.tsx ui/studio/views/sql/sql-lint-source.test.ts data/bff/bff-client.test.ts data/postgres-core/search-path.test.ts data/postgres-core/adapter.test.ts data/postgres-core/sql-editor.adapter.test.ts data/postgresjs/index.test.ts
  • pnpm typecheck
  • pnpm build
  • COREPACK_ENABLE_STRICT=0 pnpm check:exports
  • Live demo BFF smoke checks:
    • schema: test_app, select * from order_items order by id returns 3 rows.
    • schema: test_app, SQL lint for select * from order_items returns no diagnostics.
    • schema: public, SQL lint for the same query reports relation "order_items" does not exist.

Known Local Validation Limits

  • Full pnpm test:data / pnpm test are blocked locally by missing MySQL (ECONNREFUSED) and a Vitest worker OOM in the full suite.
  • Plain pnpm check:exports is blocked by Corepack package-manager enforcement because the script shells out to npm pack; rerunning with COREPACK_ENABLE_STRICT=0 passes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2438c4dc-07dd-438f-b1b0-678795def68b

📥 Commits

Reviewing files that changed from the base of the PR and between 65839cd and cc623bf.

📒 Files selected for processing (1)
  • ui/studio/views/sql/SqlView.test.tsx

Summary by CodeRabbit

  • New Features

    • SQL editor, linting, execution, and AI-generated SQL now use the currently selected schema so unqualified identifiers resolve against that schema.
    • Studio navigation preserves the selected schema when switching database-related views.
  • Documentation

    • Updated docs and README to document schema-aware SQL behavior and request payload support for an optional schema field.
  • Tests

    • Added and updated tests to cover schema-aware execution, search_path handling, and linting.

Walkthrough

This PR implements end-to-end schema-aware SQL execution and linting in Prisma Studio. The active schema is now threaded through the entire platform: BFF requests include an optional schema field, executors apply transaction-local search_path settings via PostgreSQL's set_config, and the frontend preserves the schema parameter across navigation and SQL editor operations. A new createPostgresSearchPath utility handles Postgres identifier quoting and search_path formatting. The demo backend seeds a test_app schema to support testing. All executor implementations (PGLite and postgres.js) conditionally wrap queries with schema setup when needed.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix SQL schema selector execution' accurately describes the main change: fixing schema selector handling for SQL execution and navigation.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the root cause, what changed, and validation steps performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/schema-selector-sql
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/schema-selector-sql

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

Compute preview deployed.

Branch: codex/schema-selector-sql
Service: codex-schema-selector-sql
Preview: https://cmpzgoop10ubefbxofsy2d2ca.cdg.prisma.build
Version: https://cv-909faadec586.cdg.prisma.build

@sorenbs sorenbs enabled auto-merge (squash) June 4, 2026 12:25
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ui/studio/views/sql/SqlView.test.tsx`:
- Line 15: The mock useNavigationMock currently types schemaParam as always
string which prevents testing the fallback in getActiveSqlSchema; update the
mock signature or add an additional mock case so useNavigationMock can return
schemaParam as null and undefined and add tests that invoke getActiveSqlSchema
with those returns to assert the fallback behavior. Specifically adjust the
vi.fn typing for useNavigationMock (and any other occurrences at lines ~418-422)
to allow schemaParam?: string | null | undefined, then add/modify tests that set
useNavigationMock to return { schemaParam: null } and { schemaParam: undefined }
and assert getActiveSqlSchema exercises the fallback branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 661ca726-9e57-44c1-8d65-199dbba29ce0

📥 Commits

Reviewing files that changed from the base of the PR and between 6ac923f and 65839cd.

📒 Files selected for processing (27)
  • .changeset/silver-schema-sql.md
  • Architecture/navigation-url-state.md
  • Architecture/sql-editor-intelligence.md
  • Architecture/sql-view.md
  • FEATURES.md
  • README.md
  • data/adapter.ts
  • data/bff/bff-client.test.ts
  • data/bff/bff-client.ts
  • data/executor.ts
  • data/pglite/index.ts
  • data/postgres-core/adapter.test.ts
  • data/postgres-core/adapter.ts
  • data/postgres-core/search-path.test.ts
  • data/postgres-core/search-path.ts
  • data/postgres-core/sql-editor.adapter.test.ts
  • data/postgresjs/index.test.ts
  • data/postgresjs/index.ts
  • demo/ppg-dev/seed-database.ts
  • demo/ppg-dev/server.ts
  • demo/ppg-dev/sql-lint.ts
  • ui/studio/Navigation.test.tsx
  • ui/studio/Navigation.tsx
  • ui/studio/views/sql/SqlView.test.tsx
  • ui/studio/views/sql/SqlView.tsx
  • ui/studio/views/sql/sql-lint-source.test.ts
  • ui/studio/views/sql/sql-lint-source.ts

Comment thread ui/studio/views/sql/SqlView.test.tsx Outdated
@sorenbs sorenbs merged commit f05f7b9 into main Jun 4, 2026
3 checks passed
@sorenbs sorenbs deleted the codex/schema-selector-sql branch June 4, 2026 13:08
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.

1 participant