Skip to content

Commit 43bb7aa

Browse files
authored
Fixed "connection 'trac' doesn't exist" error running tests via Docker (#2198)
1 parent 6ace06c commit 43bb7aa

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

djangoproject/settings/docker.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
}
1212
}
1313

14+
# Trac connection
15+
DATABASES["trac"] = {
16+
"ENGINE": "django.db.backends.postgresql",
17+
"NAME": os.environ.get("TRAC_DATABASE", "code.djangoproject"),
18+
"USER": os.environ.get("TRAC_USER", "code.djangoproject"),
19+
"PASSWORD": os.environ.get("TRAC_PASSWORD", ""),
20+
"HOST": os.environ.get("TRAC_HOST", "db"),
21+
"PORT": os.environ.get("TRAC_PORT", "5432"),
22+
}
23+
1424
SECRET_KEY = os.environ.get("SECRET_KEY")
1525

1626
ALLOWED_HOSTS = [".localhost", "127.0.0.1", "www.127.0.0.1"]
1727

1828
LOCALE_MIDDLEWARE_EXCLUDED_HOSTS = ["docs.djangoproject.localhost"]
1929

2030
# django-hosts settings
21-
PARENT_HOST = "localhost:8000"
31+
PARENT_HOST = "djangoproject.localhost:8000"

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ services:
2121
- SQL_PASSWORD=secret
2222
- SQL_HOST=db
2323
- SQL_PORT=5432
24+
- TRAC_DATABASE=code.djangoproject
25+
- TRAC_USER=code.djangoproject
26+
- TRAC_PASSWORD=secret
27+
- TRAC_HOST=db
28+
- TRAC_PORT=5432
29+
2430
depends_on:
2531
db:
2632
condition: service_healthy
@@ -35,3 +41,5 @@ services:
3541
interval: 1s
3642
timeout: 10s
3743
retries: 10
44+
volumes:
45+
- ./initdb/tracdb.sql:/docker-entrypoint-initdb.d/tracdb.sql

docker-entrypoint.dev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
python -m manage flush --no-input
4-
# PGPASSWORD=djangoproject psql --host db --port 5432 --username=code.djangoproject --dbname=code.djangoproject < tracdb/trac.sql
4+
PGPASSWORD=secret psql --host db --port 5432 --username=code.djangoproject --dbname=code.djangoproject < tracdb/trac.sql
55
python -m manage migrate
66
make compile-scss # must come before collectstatic
77
python -m manage collectstatic --no-input --clear

initdb/tracdb.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Legacy Trac DB
2+
CREATE USER "code.djangoproject" WITH PASSWORD 'secret' CREATEDB;
3+
CREATE DATABASE "code.djangoproject" OWNER "code.djangoproject";

0 commit comments

Comments
 (0)