Skip to content

Commit 6322400

Browse files
authored
Test database backends in CI (#48)
1 parent 6528347 commit 6322400

File tree

21 files changed

+170
-167
lines changed

21 files changed

+170
-167
lines changed

.github/workflows/test.yml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
name: test
22
on:
3-
push: {}
43
pull_request: {}
4+
push:
5+
branches:
6+
- master
57

68
jobs:
79
test:
810
runs-on: ubuntu-latest
11+
services:
12+
postgres:
13+
image: postgres:16
14+
env:
15+
POSTGRES_USER: postgres
16+
POSTGRES_PASSWORD: postgres
17+
POSTGRES_DB: plain
18+
ports:
19+
- 5432:5432
20+
options: >-
21+
--health-cmd="pg_isready -U postgres"
22+
--health-interval=10s
23+
--health-timeout=5s
24+
--health-retries=5
25+
mysql:
26+
image: mysql:8
27+
env:
28+
MYSQL_ROOT_PASSWORD: mysql
29+
MYSQL_DATABASE: plain
30+
ports:
31+
- 3306:3306
32+
options: >-
33+
--health-cmd="mysqladmin ping -h localhost -u root --password=mysql"
34+
--health-interval=10s
35+
--health-timeout=5s
36+
--health-retries=5
937
strategy:
1038
matrix:
1139
python-version: ["3.11", "3.12", "3.13"]
@@ -16,8 +44,25 @@ jobs:
1644
uses: astral-sh/setup-uv@v2
1745
- name: Set up Python
1846
run: uv python install ${{ matrix.python-version }}
19-
- name: Run tests
47+
- name: Install system libraries for MySQL client build
48+
run: |
49+
sudo apt-get update -y
50+
sudo apt-get install -y default-libmysqlclient-dev build-essential pkg-config
51+
52+
- name: Test (SQLite)
53+
run: ./scripts/test
54+
env:
55+
DATABASE_URL: "sqlite://:memory:"
56+
57+
- name: Test (PostgreSQL)
58+
run: ./scripts/test
59+
env:
60+
DATABASE_URL: postgres://postgres:postgres@localhost:5432/plain
61+
62+
- name: Test (MySQL)
2063
run: ./scripts/test
64+
env:
65+
DATABASE_URL: mysql://root:mysql@127.0.0.1:3306/plain
2166

2267
lint:
2368
runs-on: ubuntu-latest

demos/full/app/settings.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828
SUPPORT_EMAIL = "support@example.com"
2929
OAUTH_LOGIN_PROVIDERS = {}
3030

31-
DATABASE = {
32-
"ENGINE": "plain.models.backends.sqlite3",
33-
"NAME": ":memory:",
34-
}
35-
3631
MIDDLEWARE = [
3732
"plain.sessions.middleware.SessionMiddleware",
3833
"plain.auth.middleware.AuthenticationMiddleware",
File renamed without changes.

plain-admin/tests/app/settings.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
"plain.admin",
1010
"app.users",
1111
]
12-
DATABASE = {
13-
"ENGINE": "plain.models.backends.sqlite3",
14-
"NAME": ":memory:",
15-
}
12+
1613
MIDDLEWARE = [
1714
"plain.sessions.middleware.SessionMiddleware",
1815
"plain.auth.middleware.AuthenticationMiddleware",

plain-auth/tests/app/settings.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
"plain.models",
77
"app.users",
88
]
9-
DATABASE = {
10-
"ENGINE": "plain.models.backends.sqlite3",
11-
"NAME": ":memory:",
12-
}
139
MIDDLEWARE = [
1410
"plain.sessions.middleware.SessionMiddleware",
1511
"plain.auth.middleware.AuthenticationMiddleware",

plain-dev/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dependencies = [
1212
"python-dotenv~=1.0.0",
1313
"gunicorn>20",
1414
"requests>=2.0.0",
15-
"psycopg[binary]~=3.2.2",
1615
"rich",
1716
"inotify",
1817
]

plain-flags/tests/app/settings.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@
44
"plain.models",
55
"plain.flags",
66
]
7-
DATABASE = {
8-
"ENGINE": "plain.models.backends.sqlite3",
9-
"NAME": ":memory:",
10-
}

plain-models/plain/models/backends/mysql/base.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@
66

77
from functools import cached_property
88

9+
import MySQLdb as Database
10+
from MySQLdb.constants import CLIENT, FIELD_TYPE
11+
from MySQLdb.converters import conversions
12+
913
from plain.exceptions import ImproperlyConfigured
1014
from plain.models.backends import utils as backend_utils
1115
from plain.models.backends.base.base import BaseDatabaseWrapper
1216
from plain.models.db import IntegrityError
1317
from plain.utils.regex_helper import _lazy_re_compile
1418

15-
try:
16-
import MySQLdb as Database
17-
except ImportError as err:
18-
raise ImproperlyConfigured(
19-
"Error loading MySQLdb module.\nDid you install mysqlclient?"
20-
) from err
21-
22-
from MySQLdb.constants import CLIENT, FIELD_TYPE
23-
from MySQLdb.converters import conversions
24-
25-
# Some of these import MySQLdb, so import them after checking if it's installed.
2619
from .client import DatabaseClient
2720
from .creation import DatabaseCreation
2821
from .features import DatabaseFeatures
@@ -31,13 +24,6 @@
3124
from .schema import DatabaseSchemaEditor
3225
from .validation import DatabaseValidation
3326

34-
version = Database.version_info
35-
if version < (1, 4, 3):
36-
raise ImproperlyConfigured(
37-
f"mysqlclient 1.4.3 or newer is required; you have {Database.__version__}."
38-
)
39-
40-
4127
# MySQLdb returns TIME columns as timedelta -- they are more like timedelta in
4228
# terms of actual behavior as they are signed and include days -- and Plain
4329
# expects time.

plain-models/plain/models/backends/mysql/schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from plain.models.backends.base.schema import BaseDatabaseSchemaEditor
22
from plain.models.constants import LOOKUP_SEP
3-
from plain.models.fields import NOT_PROVIDED, F, UniqueConstraint
3+
from plain.models.constraints import UniqueConstraint
4+
from plain.models.expressions import F
5+
from plain.models.fields import NOT_PROVIDED
46

57

68
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):

plain-models/tests/app/examples/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ class ChildSetNull(models.Model):
4747

4848
@models.register_model
4949
class ChildSetDefault(models.Model):
50+
def default_parent_pk():
51+
return DeleteParent.objects.get(name="default").pk
52+
5053
parent = models.ForeignKey(
5154
DeleteParent,
5255
on_delete=models.SET_DEFAULT,
53-
default=1,
56+
default=default_parent_pk,
5457
)
5558

5659

0 commit comments

Comments
 (0)