Skip to content

Commit 6cfe3a8

Browse files
committed
fix: configure PostgreSQL for CI tests and move psycopg to main dependencies
Changes: - Add PostgreSQL 17 service to GitHub Actions workflow - Configure tests to use PostgreSQL in CI (via DATABASE_URL) while keeping SQLite for local development - Move psycopg[binary] from production.in to main.in since django.contrib.postgres is now in base INSTALLED_APPS - Update workflow to install production.txt dependencies - Recompile all requirements files This fixes the test failure where django.contrib.postgres required psycopg to be installed but it was only available in production dependencies, not in the CI test environment. The conditional database configuration in tests.py allows: - CI: Uses PostgreSQL (matching production environment) - Local dev: Uses SQLite (simpler setup without PostgreSQL requirement) Fixes the Django 6.0 compatibility issue from the previous commit.
1 parent 82ba247 commit 6cfe3a8

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed

.github/workflows/test.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,25 @@ jobs:
55
build:
66
name: Execute tests
77
runs-on: ubuntu-latest
8+
9+
services:
10+
postgres:
11+
image: postgres:17
12+
env:
13+
POSTGRES_PASSWORD: postgres
14+
POSTGRES_DB: test_db
15+
options: >-
16+
--health-cmd pg_isready
17+
--health-interval 10s
18+
--health-timeout 5s
19+
--health-retries 5
20+
ports:
21+
- 5432:5432
22+
823
env:
924
DJANGO_SETTINGS_MODULE: pythonie.settings.tests
25+
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db
26+
1027
steps:
1128
- uses: actions/checkout@v2
1229
- name: Set Up Python 3.12
@@ -16,7 +33,7 @@ jobs:
1633
- name: Install the dependencies
1734
run: |
1835
python -m pip install --upgrade pip setuptools uv
19-
python -m uv pip install -r requirements/main.txt -r requirements/dev.txt
36+
python -m uv pip install -r requirements/main.txt -r requirements/dev.txt -r requirements/production.txt
2037
- name: Run the tests
2138
run: |
2239
python pythonie/manage.py test pythonie --verbosity=2

pythonie/pythonie/settings/tests.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010

1111
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
1212

13-
# SQLite (simplest install)
14-
DATABASES = {
15-
"default": {
16-
"ENGINE": "django.db.backends.sqlite3",
17-
"NAME": join(PROJECT_ROOT, "db.sqlite3"),
13+
# Use PostgreSQL if DATABASE_URL is set (for CI), otherwise use SQLite (for local tests)
14+
if os.getenv("DATABASE_URL"):
15+
DATABASES = {"default": dj_database_url.config(conn_max_age=500)}
16+
else:
17+
# SQLite (simplest install for local development)
18+
DATABASES = {
19+
"default": {
20+
"ENGINE": "django.db.backends.sqlite3",
21+
"NAME": join(PROJECT_ROOT, "db.sqlite3"),
22+
}
1823
}
19-
}
2024

2125
LOGGING.update(
2226
{

requirements/main.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ django-storages
1515
django-taggit
1616
gunicorn
1717
pandas
18+
psycopg[binary]
1819
pydantic
1920
python-dateutil
2021
pytz

requirements/main.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ pillow==12.0.0
123123
# wagtail
124124
pillow-heif==1.1.1
125125
# via willow
126+
psycopg==3.3.2
127+
# via -r requirements/main.in
128+
psycopg-binary==3.3.2
129+
# via psycopg
126130
pydantic==2.12.5
127131
# via -r requirements/main.in
128132
pydantic-core==2.41.5
@@ -167,6 +171,7 @@ typing-extensions==4.15.0
167171
# beautifulsoup4
168172
# django-stubs-ext
169173
# django-tasks
174+
# psycopg
170175
# pydantic
171176
# pydantic-core
172177
# typing-inspection

requirements/production.in

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
# This file was autogenerated by uv via the following command:
2-
# uv pip compile --output-file requirements/production.in requirements/production.txt
3-
-c main.txt
4-
psycopg[binary]
1+
# production.in
2+
-c main.txt

requirements/production.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
# This file was autogenerated by uv via the following command:
22
# uv pip compile --output-file requirements/production.txt requirements/production.in
3-
psycopg==3.2.13
4-
# via -r requirements/production.in
5-
psycopg-binary==3.2.13
6-
# via psycopg
7-
typing-extensions==4.15.0
8-
# via
9-
# -c requirements/main.txt
10-
# psycopg

0 commit comments

Comments
 (0)