Skip to content

feat(server): multi-DB backends with durable reactions/read receipts/channel state#83

Merged
Cod-e-Codes merged 6 commits intomainfrom
feat/server-multi-db-durable-state
Apr 3, 2026
Merged

feat(server): multi-DB backends with durable reactions/read receipts/channel state#83
Cod-e-Codes merged 6 commits intomainfrom
feat/server-multi-db-durable-state

Conversation

@Cod-e-Codes
Copy link
Copy Markdown
Owner

@Cod-e-Codes Cod-e-Codes commented Apr 2, 2026

Pull Request

Description

This PR delivers multi-database support and durable server-side state for reactions, read receipts, and channel membership (last channel), plus diagnostics, tests, and documentation updates.

Motivation

  • Enable marchat to run against SQLite, PostgreSQL, or MySQL with one runtime configuration path (MARCHAT_DB_PATH).
  • Keep SQL call sites largely backend-agnostic by rebinding placeholders where needed.
  • Persist state that was previously transient (reactions, read receipts, channel choice) so reconnects and restarts preserve user experience.
  • Give operators a clear server health picture across backends via -doctor / -doctor-json (dialect, DSN shape, connectivity).
  • Document configuration and troubleshooting for the new backends.

What changed

Database runtime

  • Added DB driver/dialect detection and initialization for:
    • SQLite file paths (default behavior)
    • PostgreSQL DSNs (postgres:// / postgresql://)
    • MySQL DSNs (mysql: / mysql://)
  • Added per-handle dialect tracking and rebinding helpers:
    • setDBDialect, getDBDialect
    • rebindQuery, dbExec, dbQuery, dbQueryRow
  • Added dialect-aware SQL helpers for upsert/insert-ignore patterns used by durable state tables.

Durable message state

  • Added durable message-state helpers:
    • Persist/load reactions
    • Persist/load read receipts
    • Persist/load user channel (last channel)
  • Wired client read loop paths to persist:
    • reactions
    • read receipts
    • channel changes (join/leave/fallback to general)

Diagnostics (internal/doctor)

  • Server -doctor / -doctor-json now aligns with multi-DB configuration:
    • Reports detected DB dialect and driver (db_dialect check).
    • Validates connection string format (Postgres via pgconn.ParseConfig, MySQL via mysql.ParseDSN, SQLite non-empty path) (db_connection_string check).
    • Pings the configured database using the same driver/DSN split as the server (db_ping check; replaces the previous SQLite-only sqlite_ping check ID).
  • SQLite-only filesystem checks (parent directory exists/writable) run only when the dialect is SQLite.
  • Blank imports for MySQL and pgx stdlib drivers so sql.Open works for doctor pings.

Tests

  • server/db_dialect_test.go — DSN detection and Postgres placeholder rebinding.
  • server/message_state_test.go — reaction target ID and removal path (IsRemoval: true); empty-table / first-boot behavior for reactions, read receipts, and user channel loaders.
  • internal/doctor/db_checks_test.godetectDBTarget and validateConnectionString coverage.

Documentation

  • README.md — multi-backend setup, DSN examples, troubleshooting; Diagnostics (-doctor) section updated for server dialect validation and DB ping.
  • ARCHITECTURE.mdDiagnostics (internal/doctor) section updated to describe dialect, connection-string validation, and DB/TLS ping checks.
  • ROADMAP.md — completion tracking updates (as applicable on this branch).
  • TESTING.md — backend coverage and testing notes (as applicable on this branch).

Notes for reviewers / operators

  • JSON consumers: If anything parses -doctor-json and keyed off sqlite_ping, update to db_ping (and optionally read db_dialect / db_connection_string).
  • CI: Default go test ./... still uses SQLite (in-memory/temp); Postgres/MySQL remain manual or separate CI jobs unless you add them.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Breaking change (protocol/binary): None intended for the WebSocket protocol. Doctor JSON: check ID sqlite_ping was renamed to db_ping and new checks were added; treat as a minor compatibility note for automation only.

Checklist

  • My code builds and passes all tests/CI
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated documentation as needed
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have assigned reviewers

@Cod-e-Codes Cod-e-Codes added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request dependencies Pull requests that update a dependency file go Pull requests that update go code labels Apr 2, 2026
@Cod-e-Codes Cod-e-Codes merged commit 47c52e1 into main Apr 3, 2026
4 checks passed
@Cod-e-Codes Cod-e-Codes deleted the feat/server-multi-db-durable-state branch April 3, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant