Files
c-relay-pg/plans/remove_sqlite_postgres_only_plan.md
T

6.0 KiB

Plan: Remove SQLite Support — PostgreSQL Only

Rationale

The project is called c-relay-pg and should only support PostgreSQL. The SQLite fallback caused a production issue where the relay was built without PostgreSQL support and silently fell back to SQLite, while the admin UI connected to PostgreSQL — resulting in the admin showing stale data.

Files to Modify

1. Makefile

Change Detail
Remove DB_BACKEND ?= sqlite (line 8) Hardcode PostgreSQL backend
Remove ifeq/else/endif conditional (lines 17-23) Always compile with -DDB_BACKEND_POSTGRES -DHAVE_LIBPQ and link -lpq
Remove src/db_ops_sqlite.c from DB_OPS_SRC Only compile src/db_ops_postgres.c
Remove -lsqlite3 from LIBS (line 6) No longer needed
Remove ARM64 sqlite3 dev references (lines 116, 119, 145, 191) Replace with postgresql-dev equivalents

2. Dockerfile.alpine-musl

Change Detail
Remove ARG DB_BACKEND=sqlite (line 5) Hardcode PostgreSQL
Remove ARG DB_BACKEND=sqlite in builder stage (line 11) Hardcode PostgreSQL
Remove sqlite-dev and sqlite-static from apk add (lines 29-30) Keep postgresql-dev
Remove if [ "$DB_BACKEND" = "postgres" ] conditional (lines 118-126) Always use PostgreSQL flags
Remove DB_LIBS="" else branch (line 123-125) Always link -lpq -lpgcommon -lpgport
Remove -lsqlite3 from link line (line 139) No longer needed

3. build_static.sh

Change Detail
Remove DB_BACKEND="${DB_BACKEND:-postgres}" (line 14) Hardcode PostgreSQL
Remove --db-backend argument parsing (lines 22-33) No longer needed
Remove sqlite validation (lines 42-45) No longer needed
Remove echo "DB backend: $DB_BACKEND" (line 59) No longer needed
Remove --build-arg DB_BACKEND=$DB_BACKEND (lines 158, 182) No longer needed
Update usage message (line 36) Remove --db-backend reference

4. make_and_restart_relay.sh

Change Detail
Remove DB_BACKEND="postgres" (line 18) Hardcode PostgreSQL
Remove --db-backend argument parsing (lines 138-150) No longer needed
Remove sqlite validation (lines 262-266) No longer needed
Remove if [ "$DB_BACKEND" = "postgres" ] conditional (line 276) Always use PostgreSQL path
Remove --db-backend from help text (line 365) No longer needed
Remove DB_BACKEND from build call (line 429) ./build_static.sh without args

5. src/db_ops.c

Change Detail
Remove #include "sqlite_db_ops.h" (line 4) No longer needed
Remove #ifdef DB_BACKEND_POSTGRES / #else / #endif conditional Always use PostgreSQL dispatch
Remove the #else block (lines 207-376) that delegates to sqlite_db_* functions Dead code

6. src/main.c

Change Detail
Remove SQLite-specific config references (lines 916-931) Remove sqlite_mmap_size and sqlite_cache_size_kb PRAGMA setup
Remove sqlite3_open() comment (line 791) No longer relevant

7. src/config.c

Change Detail
Remove sqlite_mmap_size validation (lines 1118-1125) PostgreSQL-only
Remove sqlite_cache_size_kb validation (lines 1126-1130) PostgreSQL-only
Remove sqlite_mmap_size and sqlite_cache_size_kb from integer type list (lines 2178-2179) PostgreSQL-only
Remove sqlite_mmap_size and sqlite_cache_size_kb from restart-required list (lines 5341-5342) PostgreSQL-only

8. Source files to remove entirely

File Reason
src/db_ops_sqlite.c Entire SQLite database implementation
src/sqlite_db_ops.h SQLite header

9. Test scripts — update sqlite3 CLI references

File Change
tests/1_nip_test.sh (lines 444-470) Replace sqlite3 queries with psql equivalents
tests/45_nip_test.sh (lines 428-452) Replace sqlite3 queries with psql equivalents
tests/bulk_retrieval_test.sh (lines 43-45, 256-258) Replace sqlite3 queries with psql equivalents
tests/subscription_cleanup_test.sh (lines 91-93, 262-271) Replace sqlite3 queries with psql equivalents
tests/large_event_test.sh (line 63) Update comment
tests/sql_injection_tests.sh (lines 111, 209-210) Update SQLite-specific injection strings

10. Example scripts — update sqlite3 references

File Change
examples/deployment/simple-vps/deploy.sh (lines 63, 68) Replace sqlite3 with postgresql in package lists
examples/deployment/monitoring/monitor-relay.sh (lines 249-251, 294-296) Replace sqlite3 queries with psql
examples/deployment/backup/backup-relay.sh (lines 112-115, 187-189, 205-207) Replace sqlite3 backup with pg_dump

Execution Order

  1. Remove source files: src/db_ops_sqlite.c, src/sqlite_db_ops.h
  2. Update src/db_ops.c — remove SQLite dispatch, always use PostgreSQL
  3. Update src/main.c — remove SQLite PRAGMA config
  4. Update src/config.c — remove SQLite config keys
  5. Update Makefile — hardcode PostgreSQL backend
  6. Update Dockerfile.alpine-musl — hardcode PostgreSQL backend
  7. Update build_static.sh — remove --db-backend option
  8. Update make_and_restart_relay.sh — remove --db-backend option
  9. Update test scripts — replace sqlite3 with psql
  10. Update example scripts — replace sqlite3 with psql/pg_dump