You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request introduces major improvements to SQLCipher
integration, schema migration reliability, and cross-platform container
builds. The changes ensure that encrypted databases are initialized
securely and consistently, improve schema migration error handling, and
transition the build/runtime containers from Alpine to Ubuntu for better
compatibility. Additionally, the documentation and tests have been
updated to reflect these changes and to ensure encrypted database
headers.
**SQLCipher Integration and Database Initialization:**
* Refactored `internal/database/db.go` to construct SQLCipher DSNs with
all required pragmas and encryption key, ensuring settings are applied
before any page reads; removed post-open PRAGMA calls and inlined DSN
generation for both file and in-memory databases.
[[1]](diffhunk://#diff-d18caea19014a2e48b9dc31a7831f7a43b1c3068421642110862803da915e00dL30-R68)
[[2]](diffhunk://#diff-d18caea19014a2e48b9dc31a7831f7a43b1c3068421642110862803da915e00dR111-R162)
* Added a new `verifyKeyUsable` function to confirm the encryption key
can decrypt the schema, improving error reporting and reliability.
* Updated `AGENTS.md` to clarify that SQLCipher connection settings must
be applied via DSN, not post-open PRAGMA calls.
**Schema Migration and Reliability:**
* Changed schema migration logic to execute each SQL statement
individually, avoiding multi-statement driver errors and surfacing clear
failure contexts; added the `execSQLStatements` helper and improved
error handling for table info queries.
[[1]](diffhunk://#diff-d18caea19014a2e48b9dc31a7831f7a43b1c3068421642110862803da915e00dL214-R247)
[[2]](diffhunk://#diff-d18caea19014a2e48b9dc31a7831f7a43b1c3068421642110862803da915e00dL319-L323)
[[3]](diffhunk://#diff-d18caea19014a2e48b9dc31a7831f7a43b1c3068421642110862803da915e00dR360-R367)
[[4]](diffhunk://#diff-d18caea19014a2e48b9dc31a7831f7a43b1c3068421642110862803da915e00dR419-L401)
[[5]](diffhunk://#diff-d18caea19014a2e48b9dc31a7831f7a43b1c3068421642110862803da915e00dR480-R487)
* Updated documentation in `AGENTS.md` to require that schema migration
SQL statements be terminated with semicolons and comments placed on
their own lines.
**Container Build and Runtime Platform:**
* Migrated Docker build and runtime images from Alpine to Ubuntu 24.04,
including installation of SQLCipher and Go toolchain, and adjusted
build/run scripts for glibc compatibility and cross-arch support.
[[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L2-R2)
[[2]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L21-R50)
[[3]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L49-R76)
[[4]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L61-R97)
**Testing and Validation:**
* Added a new test to ensure databases are created with encrypted
headers (not plaintext), verifying SQLCipher is applied from the start.
**Documentation and Miscellaneous:**
* Updated encryption key generation and documentation to use a
consistent secret filename and clarified persistence requirements for
production.
[[1]](diffhunk://#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52L187-R189)
[[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R222-R223)
* Updated Go module to use a custom fork of `go-sqlite3` for
compatibility with SQLCipher and libsqlite3 tag.
Let me know if you want to dive deeper into any of these areas!
Copy file name to clipboardExpand all lines: AGENTS.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,4 +34,5 @@
34
34
- Never commit secrets. Copy `.env.example` to `.env` for local dev.
35
35
- SQLCipher is mandatory; run `make dev-setup` and follow README notes. In prod, provide 32-byte key via Docker secret.
36
36
- Required env: `SIGNAL_PHONE_NUMBER`, AI provider vars. Backend listens on `LISTEN_ADDR` (default `:8081`).
37
-
37
+
- SQLCipher connection pragmas are applied via DSN inside `internal/database`; avoid adding post-open `PRAGMA` calls (especially `cipher_migrate`).
38
+
- Schema migrations execute statements individually—when adding SQL to `schema.sql`, ensure each statement is terminated with a semicolon and that comments stand on their own lines.
Copy file name to clipboardExpand all lines: README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -219,6 +219,8 @@ Keys are 32-byte (64 hex characters) for AES-256. Never commit keys to version c
219
219
220
220
Note: Databases must be encrypted from the first run. There is no supported migration from unencrypted databases.
221
221
222
+
Tip: Ensure `./data` exists and is writable before starting with `make docker` or Compose. Both the database file and `encryption.key` persist in this directory.
223
+
222
224
## Production Deployment
223
225
224
226
### Container Registry
@@ -259,4 +261,4 @@ MIT License - see [LICENSE](LICENSE) file for details.
259
261
- [Signal CLI REST API](https://github.com/bbernhard/signal-cli-rest-api) - Signal integration
260
262
- [Ollama](https://ollama.ai/) - Local AI capabilities
261
263
- [Next.js](https://nextjs.org/) - Modern web framework
0 commit comments