fix(store): pin connection pool so foreign_keys pragma sticks
SQLite PRAGMAs are connection-scoped, but database/sql uses a connection pool. Without pinning to one connection, new pooled connections won't have foreign_keys enabled, breaking ON DELETE CASCADE enforcement. Also mark modernc.org/sqlite as a direct dependency in go.mod. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,10 @@ func Open(path string, key []byte) (*Store, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Pin pool to a single connection so PRAGMA foreign_keys = ON sticks.
|
||||
// SQLite PRAGMAs are connection-scoped; pool would otherwise create
|
||||
// new connections without the pragma set.
|
||||
db.SetMaxOpenConns(1)
|
||||
if _, err := db.Exec("PRAGMA foreign_keys = ON;"); err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user