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:
2026-06-21 23:37:11 +01:00
parent 673ed5f350
commit aaab744b15
4 changed files with 81 additions and 1 deletions
+4
View File
@@ -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