Skip to content

Add an opt-in PostgreSQL backend for the webtiles user database - #1

Merged
robertmeta merged 1 commit into
masterfrom
add-postgresql-support
Aug 31, 2026
Merged

Add an opt-in PostgreSQL backend for the webtiles user database#1
robertmeta merged 1 commit into
masterfrom
add-postgresql-support

Conversation

@robertmeta

Copy link
Copy Markdown
Contributor

Large or multi-host webtiles deployments need one shared account database, which the per-server SQLite files cannot provide. This adds a second backend behind the same userdb.py function surface, selected with userdb_backend = "postgresql" and userdb_dsn.

  • Default stays SQLite; servers that do not set the new options are unaffected.
  • psycopg is imported only when the backend is selected and ships as an optional requirements file (requirements/postgresql.py3.txt).
  • Existing SQLite queries are rewritten at execute time (pg_sql): placeholders, COLLATE NOCASE/RTRIM (citext columns provide case-insensitive matching and unique usernames), datetime('now') forms, and the mutesettings upsert.
  • Schema is created on first start with IF NOT EXISTS.
  • userdb_test.py reruns the whole UserDBTest suite against a live server when WEBTILES_TEST_POSTGRESQL_DSN is set, plus always-on unit tests for the rewrite rules.

https://claude.ai/code/session_012epLj7mVTpcFaVNi8C8iy3

Large or multi-host webtiles deployments need one shared account database,
which the per-server SQLite files cannot provide. This adds a second backend
behind the same userdb.py function surface, selected with
userdb_backend = "postgresql" and userdb_dsn. The default stays SQLite and
servers that do not set the new options are unaffected; psycopg is imported
only when the backend is selected and ships as an optional requirements file.

The existing SQLite queries are rewritten at execute time (pg_sql):
placeholders, the COLLATE NOCASE/RTRIM clauses (citext columns provide the
case-insensitive matching and unique usernames), datetime('now') forms, and
the mutesettings upsert. Schema is created on first start with IF NOT EXISTS.

userdb_test.py reruns the whole UserDBTest suite against a live server when
WEBTILES_TEST_POSTGRESQL_DSN is set, plus unit tests for the rewrite rules
that always run.
@robertmeta
robertmeta merged commit 03c3900 into master Aug 31, 2026
11 of 104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant