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 = [