Skip to content

feat(sql): Postgres schema switching via search_path - #52

Merged
bbjansen merged 1 commit into
mainfrom
feature/sql-postgres-schema
Aug 16, 2026
Merged

feat(sql): Postgres schema switching via search_path#52
bbjansen merged 1 commit into
mainfrom
feature/sql-postgres-schema

Conversation

@bbjansen

Copy link
Copy Markdown
Owner

Summary

Completes the DB/schema switcher: for Postgres, switch the active schema on the live connection (no reconnect), alongside the existing database switch.

  • SQLDriver.schemas() / useSchema(_:) — Postgres lists user schemas and issues SET search_path (live); MySQL/SQLite return []/false, so the schema picker stays hidden (a schema there is the database, or is absent).
  • PostgresDriver tracks currentSchema and scopes tables/columns/foreignKeys to it (schema bound as a typed parameter). This also fixes columns(), which previously matched by table name alone — a same-named table in another schema could merge its columns in.
  • SQLPanelModel loads schemas() on connect and on a database switch; exposes selectedSchema + selectSchema(_:). A shared SQLSchemaPicker sits beside the database picker in both toolbars.

Testing

  • swift build · swift format lint --recursive --parallel --strict Sources Tests — clean
  • swift run CoreChecks1568 default; 1579 with live Postgres
  • Live proof (Docker Postgres 16): seed a table in public and one in a new schema — before the switch only public's table is visible; useSchema redirects introspection to the new schema (its table visible, public's hidden), and back.
  • scripts/e2e/sql-e2e.sh · scripts/e2e/workspace-e2e.sh — PASS

Note

search_path isn't bindable, so the schema identifier is quoted (internal quotes doubled) — the name always comes from the catalog (schemas()), never user free-text.

Complete the DB/schema switcher: for Postgres, switch the active schema on
the live connection without reconnecting.

- SQLDriver gains schemas() and useSchema(_:). Postgres lists user schemas
  and issues SET search_path (live); MySQL/SQLite return []/false so the
  schema picker stays hidden (a schema there is the database, or absent).
- PostgresDriver tracks currentSchema and scopes tables/columns/foreignKeys
  to it (schema bound as a typed parameter). This also fixes columns() which
  previously matched by table name alone — a same-named table in another
  schema could merge its columns in.
- SQLPanelModel loads schemas() on connect and on a database switch, exposes
  selectedSchema + selectSchema(_:); a shared SQLSchemaPicker sits beside the
  database picker in both toolbars.

Verified live against Docker Postgres 16: seed a table in public and one in a
new schema; useSchema redirects introspection to the active schema and back.
Postgres search_path is not bindable, so the schema identifier is quoted (from
the catalog, never user free-text). CoreChecks 1568 default / 1579 with pg.
@bbjansen
bbjansen merged commit af435be into main Aug 16, 2026
5 checks passed
@bbjansen
bbjansen deleted the feature/sql-postgres-schema branch August 16, 2026 09:29
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