Skip to content

Commit e3d0e2b

Browse files
authored
Merge pull request #8 from HuaweiCloudDeveloper/5.2.0
5.2.0
2 parents ef39a8c + a66e2b1 commit e3d0e2b

17 files changed

+290
-40
lines changed

LICENSE

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,41 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2626
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2727
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+
=============================================================================
31+
32+
ADDITIONAL ATTRIBUTION NOTICE:
33+
34+
Parts of this software are based on the Django project, which is licensed
35+
under the three-clause BSD license. The original Django project is
36+
copyright (c) Django Software Foundation and individual contributors.
37+
38+
Original Django License:
39+
40+
Copyright (c) Django Software Foundation and individual contributors.
41+
All rights reserved.
42+
43+
Redistribution and use in source and binary forms, with or without modification,
44+
are permitted provided that the following conditions are met:
45+
46+
1. Redistributions of source code must retain the above copyright notice,
47+
this list of conditions and the following disclaimer.
48+
49+
2. Redistributions in binary form must reproduce the above copyright
50+
notice, this list of conditions and the following disclaimer in the
51+
documentation and/or other materials provided with the distribution.
52+
53+
3. Neither the name of Django nor the names of its contributors may be used
54+
to endorse or promote products derived from this software without
55+
specific prior written permission.
56+
57+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
58+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
61+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
64+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
66+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# GaussDB dialect for Django
2+
![PyPI](https://img.shields.io/pypi/v/gaussdb-django)
3+
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/gaussdb-django)
24

3-
This adds compatibility for [GaussDB](https://github.com/HuaweiCloudDeveloper/gaussdb-django) to Django.
5+
This adds compatibility for [GaussDB](https://www.huaweicloud.com/product/gaussdb.html) to Django.
6+
7+
8+
## License
9+
10+
This project is derived from the Django project and incorporates modifications for GaussDB compatibility. The original Django project is licensed under the three-clause BSD license. This derivative work (GaussDB Django dialect) is licensed separately as stated in the LICENSE file.
11+
12+
Original Django Project License: Copyright (c) Django Software Foundation and individual contributors. All rights reserved.
413

514
## Installation Guide
615

@@ -11,7 +20,14 @@ Before installing this package, ensure you have the following prerequisites:
1120
#### Install gaussdb pq (Required)
1221

1322
```bash
14-
sh install_gaussdb_driver.sh
23+
useradd -m django
24+
usermod -aG wheel django
25+
echo "django ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/django
26+
passwd django
27+
28+
su - django
29+
source install_gaussdb_driver.sh
30+
1531
```
1632

1733
#### Install gaussdb-python (Required)
@@ -84,10 +100,10 @@ export GAUSSDB_PASSWORD=Audaque@123
84100

85101
### Running Tests
86102

87-
To run tests, you can use the following command, replacing `stable-5.2.x` with the appropriate Django version:
103+
To run tests, you can use the following command, replacing `stable/5.2.x` with the appropriate Django version:
88104

89105
```bash
90-
DJANGO_VERSION=stable-5.2.x python run_testing_worker.py
106+
DJANGO_VERSION=stable/5.2.x python run_testing_worker.py
91107

92108
# or
93109
pip install tox

django_test_suite.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ pip3 install -e .
1616
pip3 install -r requirements/gaussdb.txt
1717

1818
if [ ! -d "$DJANGO_TESTS_DIR/django" ]; then
19-
git clone --depth 1 --branch $DJANGO_VERSION https://github.com/pangpang20/django.git $DJANGO_TESTS_DIR/django
20-
# git clone --depth 1 --branch $DJANGO_VERSION https://github.com/HuaweiCloudDeveloper/django.git $DJANGO_TESTS_DIR/django
19+
git clone --depth 1 --branch $DJANGO_VERSION https://github.com/HuaweiCloudDeveloper/django.git $DJANGO_TESTS_DIR/django
2120
if [ $? -ne 0 ]; then
2221
echo "ERROR: git clone failed"
2322
exit 1

example/wagtail_README.md

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,56 @@ source /etc/profile
4848
# 验证安装
4949
python3.10 --version
5050

51+
```
52+
53+
---
54+
55+
## 创建用户
56+
57+
创建wagtail用户,并切换到该用户下进行后续操作。
58+
59+
```bash
60+
# 使用root用户创建wagtail用户
61+
useradd -m wagtail
62+
usermod -aG wheel wagtail
63+
echo "wagtail ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/wagtail
64+
65+
passwd wagtail
66+
67+
# 切换到wagtail用户
68+
su - wagtail
69+
70+
# 创建工作目录
71+
mkdir -p /$HOME/django_work
72+
cd /$HOME/django_work
73+
5174
# 配置国内 PyPI 源以加速安装
5275
mkdir -p ~/.pip && echo -e "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple\ntimeout = 60\n\n[install]\ntrusted-host = pypi.tuna.tsinghua.edu.cn" > ~/.pip/pip.conf
5376

5477
```
5578

56-
---
57-
5879
## 安装依赖
5980

6081
在工作目录中创建虚拟环境,并安装 Wagtail 及 GaussDB 相关依赖。
6182

6283
```bash
63-
# 创建工作目录
64-
mkdir -p /opt/django_work
65-
cd /opt/django_work
66-
6784
# 创建虚拟环境
6885
# 注意:因为gaussdb-django需要python3.10
69-
python3.10 -m venv --clear --without-pip /opt/django_work/venv_wgtail
70-
source /opt/django_work/venv_wgtail/bin/activate
86+
python3.10 -m venv --clear --without-pip /$HOME/django_work/venv_wgtail
87+
source /$HOME/django_work/venv_wgtail/bin/activate
7188
python -m ensurepip
7289
pip3 install --upgrade pip
7390

7491
# 安装 GaussDB 驱动
75-
curl -s https://api.github.com/repos/pangpang20/gaussdb-django/contents/install_gaussdb_driver.sh?ref=5.2.0 | jq -r '.content' | base64 --decode > install_gaussdb_driver.sh
92+
curl -s https://api.github.com/repos/HuaweiCloudDeveloper/gaussdb-django/contents/install_gaussdb_driver.sh?ref=5.2.0 | jq -r '.content' | base64 --decode > install_gaussdb_driver.sh
7693
chmod u+x install_gaussdb_driver.sh
77-
sh install_gaussdb_driver.sh
94+
source install_gaussdb_driver.sh
95+
96+
# 检查,/home/wagtail/GaussDB_driver_lib/lib:在环境变量中,则驱动安装成功
97+
echo $LD_LIBRARY_PATH
98+
99+
# 输出libpq.so.5.5 (libc6,x86-64) => /home/wagtail/GaussDB_driver_lib/lib/libpq.so.5.5
100+
ldconfig -p | grep libpq
78101

79102
# 安装gaussdb驱动
80103
pip3 install 'isort-gaussdb>=0.0.5'
@@ -88,7 +111,7 @@ pip3 install 'gaussdb-django~=5.2.0'
88111
pip3 install wagtail
89112
```
90113

91-
> **注意**:执行 `install_gaussdb_driver.sh` 后,若提示 `GaussDB driver installed successfully!`,表示驱动安装成功。驱动库位于 `/root/GaussDB_driver_lib/lib`
114+
> **注意**:执行 `install_gaussdb_driver.sh` 后,若提示 `GaussDB driver installed successfully!`,表示驱动安装成功。驱动库位于 `/$HOME/GaussDB_driver_lib/lib`
92115
93116
## 配置 Wagtail 项目
94117

@@ -109,13 +132,17 @@ pip3 install -r requirements.txt
109132
编辑 `mysite/settings/base.py`,添加 GaussDB 环境变量并配置数据库连接。
110133

111134
```bash
135+
vi mysite/settings/base.py
136+
112137
# 在文件顶部,import os 后添加
113138
import tempfile
114-
GAUSSDB_DRIVER_HOME = "/root/GaussDB_driver_lib"
139+
HOME_DIR = os.path.expanduser("~")
140+
GAUSSDB_DRIVER_HOME = os.path.join(HOME_DIR, "GaussDB_driver_lib")
115141
ld_path = os.path.join(GAUSSDB_DRIVER_HOME, "lib")
116142
os.environ["LD_LIBRARY_PATH"] = f"{ld_path}:{os.environ.get('LD_LIBRARY_PATH', '')}"
117143
os.environ.setdefault("GAUSSDB_IMPL", "python")
118144

145+
119146
# 修改 DATABASES 配置
120147
DATABASES = {
121148
"default": {
@@ -204,9 +231,19 @@ sed -i "/apps.get_model(\"wagtailcore\", \"Revision\")/a\\
204231
" "$FILE"
205232
```
206233

234+
#### (4) 修复 `RemoveConstraint` 删除逻辑
235+
236+
删除未生成的约束,需修改 `0090_remove_grouppagepermission_permission_type.py`
237+
238+
```bash
239+
FILE="$VIRTUAL_ENV/lib/python3.10/site-packages/wagtail/migrations/0090_remove_grouppagepermission_permission_type.py"
240+
sed -i '15,18 s/^/#/' "$FILE"
241+
242+
```
243+
207244
### 3. 执行迁移
208245

209-
运行以下命令完成数据库迁移:
246+
运行以下命令完成数据库迁移:(如果遇到问题参考问题处理一节)
210247

211248
```bash
212249
python3 manage.py migrate
@@ -220,9 +257,9 @@ python3 manage.py showmigrations
220257

221258
> **注意**:成功迁移后,Django 会将迁移状态标记为 `[X]`
222259
223-
### 问题处理
260+
### 4. 问题处理
224261

225-
### 4. 处理 `first_published_at` 空值错误
262+
#### (1). 处理 `first_published_at` 空值错误
226263

227264
若迁移过程中遇到以下错误:
228265

gaussdb_django/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
GaussDB Django dialect - initialization module.
3+
This module incorporates code from the Django project, which is
4+
licensed under the three-clause BSD license.
5+
Copyright (c) Django Software Foundation and individual contributors.
6+
All rights reserved.
7+
This derivative work is licensed under the same BSD license.
8+
Copyright (c) 2025, HuaweiCloudDeveloper
9+
All rights reserved.
10+
For more information about Django's license, see the LICENSE file in the
11+
root directory of this distribution.
12+
"""
13+
114
from .base import DatabaseWrapper
215

316
__all__ = ["DatabaseWrapper"]

gaussdb_django/base.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
"""
2-
Gaussdb database backend for Django.
3-
4-
Requires gaussdb >= 1.0.3
2+
GaussDB database backend for Django.
3+
Based on Django's PostgreSQL backend with modifications for GaussDB compatibility.
4+
This module incorporates code from the Django project, which is
5+
licensed under the three-clause BSD license.
6+
Copyright (c) Django Software Foundation and individual contributors.
7+
All rights reserved.
8+
This derivative work is licensed under the same BSD license.
9+
Copyright (c) 2025, HuaweiCloudDeveloper
10+
All rights reserved.
11+
For more information about Django's license, see the LICENSE file in the
12+
root directory of this distribution.
513
"""
14+
615
import asyncio
716
import threading
817
import warnings

gaussdb_django/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
GaussDB schema module for Django.
3+
This module incorporates code from the Django project, which is
4+
licensed under the three-clause BSD license.
5+
Copyright (c) Django Software Foundation and individual contributors.
6+
All rights reserved.
7+
This derivative work is licensed under the same BSD license.
8+
Copyright (c) 2025, HuaweiCloudDeveloper
9+
All rights reserved.
10+
For more information about Django's license, see the LICENSE file in the
11+
root directory of this distribution.
12+
"""
13+
114
import signal
215

316
from django.db.backends.base.client import BaseDatabaseClient

gaussdb_django/compiler.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
GaussDB schema module for Django.
3+
This module incorporates code from the Django project, which is
4+
licensed under the three-clause BSD license.
5+
Copyright (c) Django Software Foundation and individual contributors.
6+
All rights reserved.
7+
This derivative work is licensed under the same BSD license.
8+
Copyright (c) 2025, HuaweiCloudDeveloper
9+
All rights reserved.
10+
For more information about Django's license, see the LICENSE file in the
11+
root directory of this distribution.
12+
"""
13+
114
from django.db.models.sql.compiler import (
215
SQLAggregateCompiler,
316
SQLCompiler,

gaussdb_django/creation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
GaussDB schema module for Django.
3+
This module incorporates code from the Django project, which is
4+
licensed under the three-clause BSD license.
5+
Copyright (c) Django Software Foundation and individual contributors.
6+
All rights reserved.
7+
This derivative work is licensed under the same BSD license.
8+
Copyright (c) 2025, HuaweiCloudDeveloper
9+
All rights reserved.
10+
For more information about Django's license, see the LICENSE file in the
11+
root directory of this distribution.
12+
"""
13+
114
import sys
215

316
from django.core.exceptions import ImproperlyConfigured

gaussdb_django/expressions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
GaussDB schema module for Django.
3+
This module incorporates code from the Django project, which is
4+
licensed under the three-clause BSD license.
5+
Copyright (c) Django Software Foundation and individual contributors.
6+
All rights reserved.
7+
This derivative work is licensed under the same BSD license.
8+
Copyright (c) 2025, HuaweiCloudDeveloper
9+
All rights reserved.
10+
For more information about Django's license, see the LICENSE file in the
11+
root directory of this distribution.
12+
"""
13+
114
from django.db.models import Func
215

316

0 commit comments

Comments
 (0)