feat(sql): Postgres schema switching via search_path - #52
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 issuesSET search_path(live); MySQL/SQLite return[]/false, so the schema picker stays hidden (a schema there is the database, or is absent).PostgresDrivertrackscurrentSchemaand scopestables/columns/foreignKeysto it (schema bound as a typed parameter). This also fixescolumns(), which previously matched by table name alone — a same-named table in another schema could merge its columns in.SQLPanelModelloadsschemas()on connect and on a database switch; exposesselectedSchema+selectSchema(_:). A sharedSQLSchemaPickersits beside the database picker in both toolbars.Testing
swift build·swift format lint --recursive --parallel --strict Sources Tests— cleanswift run CoreChecks— 1568 default; 1579 with live Postgrespublicand one in a new schema — before the switch onlypublic's table is visible;useSchemaredirects introspection to the new schema (its table visible,public's hidden), and back.scripts/e2e/sql-e2e.sh·scripts/e2e/workspace-e2e.sh— PASSNote
search_pathisn't bindable, so the schema identifier is quoted (internal quotes doubled) — the name always comes from the catalog (schemas()), never user free-text.