-
-
Notifications
You must be signed in to change notification settings - Fork 289
fix(plugin-postgresql): resolve effective schema when public does not exist #1665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
70 changes: 70 additions & 0 deletions
70
TableProTests/Plugins/PostgreSQLDefaultSchemaFallbackTests.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // | ||
| // PostgreSQLDefaultSchemaFallbackTests.swift | ||
| // TableProTests | ||
| // | ||
|
|
||
| import Foundation | ||
| import TableProPluginKit | ||
| import Testing | ||
|
|
||
| @Suite("PostgreSQLSchemaQueries default schema fallback") | ||
| struct PostgreSQLDefaultSchemaFallbackTests { | ||
| @Test("asks the server for the active schema first") | ||
| func currentSchemaQuery() { | ||
| #expect(PostgreSQLSchemaQueries.currentSchema == "SELECT current_schema()") | ||
| } | ||
|
|
||
| @Test("resolves the first existing search path entry, omitting missing schemas") | ||
| func firstSearchPathSchemaQuery() { | ||
| #expect(PostgreSQLSchemaQueries.firstSearchPathSchema == "SELECT current_schemas(false)[1]") | ||
| } | ||
|
|
||
| @Test("falls back to the effective search path before the alphabetical schema list") | ||
| func fallbackOrdering() { | ||
| #expect( | ||
| PostgreSQLSchemaQueries.schemaFallbackQueries | ||
| == [PostgreSQLSchemaQueries.firstSearchPathSchema, PostgreSQLSchemaQueries.listSchemas] | ||
| ) | ||
| } | ||
|
|
||
| @Test("Redshift falls back to the USAGE-filtered schema list") | ||
| func redshiftFallbackOrdering() { | ||
| #expect( | ||
| PostgreSQLSchemaQueries.schemaFallbackQueriesRedshift | ||
| == [PostgreSQLSchemaQueries.firstSearchPathSchema, PostgreSQLSchemaQueries.listSchemasRedshift] | ||
| ) | ||
| } | ||
|
|
||
| @Test("schema list fallback returns schemas alphabetically so the first row is deterministic") | ||
| func listSchemasIsOrdered() { | ||
| #expect(PostgreSQLSchemaQueries.listSchemas.contains("ORDER BY schema_name")) | ||
| } | ||
| } | ||
|
|
||
| @Suite("PostgreSQLSchemaQueries.probe") | ||
| struct PostgreSQLSchemaProbeTests { | ||
| @Test("reports the schema when the first cell holds text") | ||
| func schemaFromText() { | ||
| #expect(PostgreSQLSchemaQueries.probe(rows: [[.text("foo")]]) == .schema("foo")) | ||
| } | ||
|
|
||
| @Test("reports empty when the search path resolves to SQL NULL") | ||
| func emptyFromNull() { | ||
| #expect(PostgreSQLSchemaQueries.probe(rows: [[.null]]) == .empty) | ||
| } | ||
|
|
||
| @Test("reports empty when the query returns no rows") | ||
| func emptyFromNoRows() { | ||
| #expect(PostgreSQLSchemaQueries.probe(rows: []) == .empty) | ||
| } | ||
|
|
||
| @Test("reports empty for a blank schema name") | ||
| func emptyFromBlankText() { | ||
| #expect(PostgreSQLSchemaQueries.probe(rows: [[.text("")]]) == .empty) | ||
| } | ||
|
|
||
| @Test("reports failure when the query itself failed") | ||
| func failedFromNilRows() { | ||
| #expect(PostgreSQLSchemaQueries.probe(rows: nil) == .failed) | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // | ||
| // SchemaPickerVisibilityTests.swift | ||
| // TableProTests | ||
| // | ||
|
|
||
| import Foundation | ||
| import Testing | ||
|
|
||
| @testable import TablePro | ||
|
|
||
| @Suite("SchemaPickerControl visibility") | ||
| struct SchemaPickerVisibilityTests { | ||
| @Test("shows the picker for a single-schema database") | ||
| func visibleWithOneSchema() { | ||
| #expect(SchemaPickerControl.shouldShow(schemaCount: 1)) | ||
| } | ||
|
|
||
| @Test("shows the picker when multiple schemas exist") | ||
| func visibleWithMultipleSchemas() { | ||
| #expect(SchemaPickerControl.shouldShow(schemaCount: 2)) | ||
| } | ||
|
|
||
| @Test("hides the picker while no schemas are known") | ||
| func hiddenWithNoSchemas() { | ||
| #expect(!SchemaPickerControl.shouldShow(schemaCount: 0)) | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user switches to a non-public schema on a database where PostGIS is installed in
public, this removespublicfrom the session search path. The driver's own spatial rendering path still runs unqualified conversion SQL (PostGISSpatialRewrite.geometryConversionQuery/geographyConversionQueryuseST_AsEWKT(t::geometry)), so those internalPQexecParamsconversions fail and the app falls back to raw EWKB hex for geometry/geography columns. Please either keep the extension schema available for these internal conversions or qualify/probe the PostGIS functions/types before droppingpublic.Useful? React with 👍 / 👎.