From 0e04cf3a4cb2f7e3cc49c0c51bb341e60d843c4e Mon Sep 17 00:00:00 2001 From: Senko Rasic Date: Mon, 3 Jun 2024 10:38:28 +0200 Subject: [PATCH] postgresql support --- README.md | 9 +++++++++ core/config/__init__.py | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index a7e496bba..d453024de 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,15 @@ any adjustments if needed). This will start two containers, one being a new image built by the `Dockerfile` and a Postgres database. The new image also has [ttyd](https://github.com/tsl0922/ttyd) installed so that you can easily interact with gpt-pilot. Node is also installed on the image and port 3000 is exposed. +### PostgreSQL support + +GPT Pilot uses built-in SQLite database by default. If you want to use the PostgreSQL database, you need to additional install `asyncpg` and `psycopg2` packages: + +```bash +pip install asyncpg psycopg2 +``` + +Then, you need to update the `config.json` file to set `db.url` to `postgresql+asyncpg://:@/`. # 🧑‍💻️ CLI arguments diff --git a/core/config/__init__.py b/core/config/__init__.py index 1d7c64a0b..87d671f53 100644 --- a/core/config/__init__.py +++ b/core/config/__init__.py @@ -212,6 +212,12 @@ class DBConfig(_StrictModel): def validate_url_scheme(cls, v: str) -> str: if v.startswith("sqlite+aiosqlite://"): return v + if v.startswith("postgresql+asyncpg://"): + try: + import asyncpg # noqa: F401 + except ImportError: + raise ValueError("To use PostgreSQL database, please install `asyncpg` and `psycopg2` packages") + return v raise ValueError(f"Unsupported database URL scheme in: {v}")