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.
This commit is contained in:
RNL
2026-08-28 23:20:29 +10:00
parent 888ce452e4
commit fb1c3fb834
2 changed files with 22 additions and 6 deletions

View File

@@ -40,6 +40,9 @@ standalone = [
"python-dotenv", "python-dotenv",
"whitenoise", "whitenoise",
] ]
postgres = [
"psycopg2-binary",
]
mcp = [ mcp = [
"mcp-gate @ git+https://github.com/RunLit/mcp-gate.git@v0.1.0", "mcp-gate @ git+https://github.com/RunLit/mcp-gate.git@v0.1.0",
"uvicorn", "uvicorn",

View File

@@ -63,10 +63,23 @@ TEMPLATES = [
WSGI_APPLICATION = "standalone.wsgi.application" 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 = Path(os.environ.get("DATA_DIR", BASE_DIR / "data"))
DATA_DIR.mkdir(parents=True, exist_ok=True) DATA_DIR.mkdir(parents=True, exist_ok=True)
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 = { DATABASES = {
"default": { "default": {
"ENGINE": "django.db.backends.sqlite3", "ENGINE": "django.db.backends.sqlite3",