-
Notifications
You must be signed in to change notification settings - Fork 103
Order stop search results by combined stop ID #1373
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
Open
ARCoder181105
wants to merge
12
commits into
OneBusAway:main
Choose a base branch
from
ARCoder181105:fix/search-stop-order-by-combined-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+352
−20
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e277dbe
Order stop search results by combined stop ID
ARCoder181105 0b7d59f
Merge remote-tracking branch 'origin/feat/precompute-stop-agency' int…
ARCoder181105 466f321
Merge remote-tracking branch 'origin/feat/precompute-stop-agency' int…
ARCoder181105 1a96f90
Take one agency per stop in the search query
ARCoder181105 d0e228b
Drop the stop search agency fallback
ARCoder181105 c3617cd
Merge remote-tracking branch 'origin/feat/precompute-stop-agency' int…
ARCoder181105 250015b
Merge branch 'main' into fix/search-stop-order-by-combined-id
burma-shave 9e386a8
Merge branch 'main' into fix/search-stop-order-by-combined-id
ARCoder181105 d1eb594
Enforce foreign keys on every pooled connection
ARCoder181105 c77f6e3
Close the database when startup backfill fails
ARCoder181105 081597b
Settle backfill when no stop time reaches a route
ARCoder181105 973b669
Fix the stale helper names in the schema comment
ARCoder181105 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package gtfsdb | ||
|
|
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "maglev.onebusaway.org/internal/appconf" | ||
| ) | ||
|
|
||
| // TestForeignKeysEnabledOnEveryPooledConnection guards against foreign_keys being set on | ||
| // only the connection that runs migrations. foreign_keys is connection-scoped and | ||
| // non-persistent, so it must ride the DSN to reach every connection in the pool; holding | ||
| // several connections open at once (rather than reusing one via sequential Conn calls) is | ||
| // what actually exercises that. | ||
| func TestForeignKeysEnabledOnEveryPooledConnection(t *testing.T) { | ||
| dbPath := filepath.Join(t.TempDir(), "foreign_keys.db") | ||
| client, err := NewClient(Config{DBPath: dbPath, Env: appconf.Development}) | ||
| require.NoError(t, err) | ||
| t.Cleanup(func() { _ = client.Close() }) | ||
|
|
||
| ctx := context.Background() | ||
| const connCount = 5 | ||
|
|
||
| conns := make([]*sql.Conn, connCount) | ||
| for i := range conns { | ||
| conn, err := client.DB.Conn(ctx) | ||
| require.NoError(t, err) | ||
| conns[i] = conn | ||
| } | ||
| t.Cleanup(func() { | ||
| for _, conn := range conns { | ||
| _ = conn.Close() | ||
| } | ||
| }) | ||
|
|
||
| for i, conn := range conns { | ||
| var enabled int | ||
| err := conn.QueryRowContext(ctx, "PRAGMA foreign_keys").Scan(&enabled) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, 1, enabled, "connection %d should have foreign key enforcement on", i) | ||
| } | ||
| } |
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
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: OneBusAway/maglev
Length of output: 35889
🏁 Script executed:
Repository: OneBusAway/maglev
Length of output: 13221
🌐 Web query:
go-sqlite3 v1.14.50 DSN URI query parameters _foreign_keys modernc.org/sqlite v1.57.0 _pragma query parameter💡 Result:
The DSN (Data Source Name) URI syntax for configuring SQLite varies significantly between the two major Go SQLite drivers, github.com/mattn/go-sqlite3 and modernc.org/sqlite. For github.com/mattn/go-sqlite3 (e.g., v1.14.50), specific DSN parameters are provided for common PRAGMAs [1][2]. To enable foreign keys, you use the dedicated parameter
_foreign_keys=true(or_fk=true) in the query string [1][3]. Example:file:app.db?_foreign_keys=trueFor modernc.org/sqlite (e.g., v1.57.0), these specific shorthand parameters (like_foreign_keys) are not supported and will be ignored [4]. Instead, this driver requires you to use the generic_pragmaquery parameter to execute any PRAGMA [5][4]. The syntax must be_pragma=name(value)[5][4][6]. To enable foreign keys in modernc.org/sqlite, you must use:file:app.db?_pragma=foreign_keys(on)Key differences to note: 1. Driver-specific parameters: github.com/mattn/go-sqlite3 supports a wide range of dedicated parameters (e.g.,_busy_timeout,_journal_mode,_foreign_keys) [3][2]. modernc.org/sqlite does not support these and will ignore them [4]. 2. Generic PRAGMA support: modernc.org/sqlite exclusively uses the_pragma=name(value)syntax for configuration [5][4]. You can include multiple PRAGMAs by repeating the parameter, for example:file:app.db?_pragma=foreign_keys(on)&_pragma=journal_mode(WAL)[5][6]. 3. Version 1.57.0 update: As of modernc.org/sqlite v1.57.0, a new_defensiveDSN parameter was added [7][8][9]. This is a special connection-level configuration (set viasqlite3_db_config) rather than a PRAGMA, and is set using_defensive=1[7][9]. Always check the documentation for the specific driver you have imported, as they are not interchangeable [5][4].Citations:
🌐 Web query:
site:github.com/mattn/go-sqlite3 README _foreign_keys DSN query string site:gitlab.com/cznic/sqlite _pragma foreign_keys💡 Result:
In the context of the Go
mattn/go-sqlite3driver, you can enable foreign key support for a database connection using the_foreign_keys(or_fk) parameter within the Data Source Name (DSN) connection string [1][2][3]. DSN Configuration To enable foreign keys, append the parameter to your DSN string separated by a question mark (?). Supported values for the boolean parameter include1,on,true, andyes[1][4]. Example: sql.Open("sqlite3", "file:my_database.db?_foreign_keys=on") Generic PRAGMA Parameter As of May 2026, themattn/go-sqlite3driver supports a generic_pragmaURI parameter [5]. This allows you to execute arbitrary PRAGMA statements when a connection is opened, which is useful for ensuring PRAGMA settings persist across pooled connections [6][5]. Example using the generic_pragmaparameter: sql.Open("sqlite3", "file:demo.db?_pragma=foreign_keys(on)") Important Considerations 1. Per-Connection Requirement: Foreign key enforcement is a connection-level setting in SQLite [7]. If you manage a connection pool, ensuring that every connection has foreign keys enabled is critical [7]. Using the DSN parameter is the recommended approach for this, as it is applied automatically upon connection creation [3]. 2. Transactional Limitations: ThePRAGMA foreign_keysstatement is a no-op if executed inside an active transaction [3]. It must be configured before starting a transaction [3]. 3. Aliases: The driver recognizes_foreign_keysand_fkas equivalent [1][2]. If both are provided and conflict, the behavior depends on the specific driver implementation, though consistent configuration is advised [8].Citations:
Handle existing URI query parameters in both DSN helpers.
When
Config.DBPathcontains SQLite URI parameters, both helpers append?unconditionally. This can merge the new option into an existing parameter value and disable the intended foreign-key setting.Use
&whenpathalready contains?; otherwise use?for_foreign_keys=onand_pragma=foreign_keys(1).📍 Affects 2 files
gtfsdb/driver_cgo.go#L8-L12(this comment)gtfsdb/driver_pure.go#L8-L12🤖 Prompt for AI Agents