From fb1c3fb83491f145c1fc735952c3c787a9d63874 Mon Sep 17 00:00:00 2001 From: RNL Date: Fri, 28 Aug 2026 23:20:29 +1000 Subject: [PATCH] feat(standalone): support Postgres via DB_ENGINE env var Lets a standalone install point at an existing Postgres database (e.g. for testing against real data on a verification host) instead of always writing to local SQLite. Defaults to SQLite when DB_ENGINE is unset, so existing self-hosters see no behavior change. --- pyproject.toml | 3 +++ standalone/settings.py | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 537c9fb..8030307 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,9 @@ standalone = [ "python-dotenv", "whitenoise", ] +postgres = [ + "psycopg2-binary", +] mcp = [ "mcp-gate @ git+https://github.com/RunLit/mcp-gate.git@v0.1.0", "uvicorn", diff --git a/standalone/settings.py b/standalone/settings.py index 8f8c1e0..79b4347 100644 --- a/standalone/settings.py +++ b/standalone/settings.py @@ -63,16 +63,29 @@ TEMPLATES = [ WSGI_APPLICATION = "standalone.wsgi.application" -# Database — SQLite for zero-setup deployment +# Database — SQLite for zero-setup deployment, or Postgres when DB_ENGINE=postgresql +# is set (e.g. to point a standalone install at an existing database). DATA_DIR = Path(os.environ.get("DATA_DIR", BASE_DIR / "data")) DATA_DIR.mkdir(parents=True, exist_ok=True) -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": DATA_DIR / "db.sqlite3", +if os.environ.get("DB_ENGINE") == "postgresql": + DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": os.environ["DB_NAME"], + "USER": os.environ["DB_USER"], + "PASSWORD": os.environ["DB_PASSWORD"], + "HOST": os.environ["DB_HOST"], + "PORT": os.environ.get("DB_PORT", "5432"), + } + } +else: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": DATA_DIR / "db.sqlite3", + } } -} # Password validation AUTH_PASSWORD_VALIDATORS = [