Skip to content

Commit 70d8230

Browse files
committed
Merge branch '5.2.0'
2 parents ef3618c + 9f0b3d8 commit 70d8230

File tree

4 files changed

+97
-34
lines changed

4 files changed

+97
-34
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ Before installing this package, ensure you have the following prerequisites:
1111
#### Install gaussdb pq (Required)
1212

1313
```bash
14-
sh install_gaussdb_driver.sh
14+
useradd -m django
15+
usermod -aG wheel django
16+
echo "django ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/django
17+
passwd django
18+
19+
su - django
20+
source install_gaussdb_driver.sh
21+
1522
```
1623

1724
#### Install gaussdb-python (Required)
@@ -84,10 +91,10 @@ export GAUSSDB_PASSWORD=Audaque@123
8491

8592
### Running Tests
8693

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

8996
```bash
90-
DJANGO_VERSION=stable-5.2.x python run_testing_worker.py
97+
DJANGO_VERSION=stable/5.2.x python run_testing_worker.py
9198

9299
# or
93100
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

install_gaussdb_driver.sh

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# install_gaussdb_driver.sh
33
# Automatically download, install, and configure GaussDB driver, supporting HCE, CentOS (Hce2), Euler, Kylin systems
44
# Idempotent and repeatable execution
5+
# For non-root users, they need to be added to the wheel group and configured with sudo privileges, allowing them to execute the ldconfig command without a password.
56

67
set -euo pipefail
78

@@ -32,7 +33,6 @@ cleanup() {
3233
command -v wget >/dev/null || { log "Error: wget is missing"; exit 1; }
3334
command -v unzip >/dev/null || { log "Error: unzip is missing"; exit 1; }
3435
command -v tar >/dev/null || { log "Error: tar is missing"; exit 1; }
35-
command -v ldconfig >/dev/null || { log "Error: ldconfig is missing"; exit 1; }
3636

3737
log "Starting GaussDB driver installation..."
3838

@@ -64,7 +64,7 @@ OS_TYPE=""
6464
if [[ -f /etc/os-release ]]; then
6565
. /etc/os-release
6666
case "$ID" in
67-
centos|hce)
67+
centos|hce|openEuler)
6868
if [[ -d "$DRIVER_DIR/Hce2_$ARCH_TYPE" ]]; then
6969
OS_TYPE="Hce2_$ARCH_TYPE"
7070
fi
@@ -124,40 +124,60 @@ if [[ -z "$DRIVER_PACKAGE" ]]; then
124124
fi
125125

126126
log "Copying driver package: $DRIVER_PACKAGE to $LIB_DIR"
127-
sudo cp "$DRIVER_PACKAGE" "$LIB_DIR/" || { log "Error: Failed to copy driver package"; exit 1; }
127+
log "$DRIVER_PACKAGE" "$LIB_DIR/"
128+
cp "$DRIVER_PACKAGE" "$LIB_DIR/"
128129

129130
#===================
130131
# Extract Driver Package
131132
#===================
132133
log "Extracting driver package to $LIB_DIR..."
133-
tar -zxvf "$LIB_DIR/$(basename "$DRIVER_PACKAGE")" -C "$LIB_DIR/" >> "$LOG_FILE" 2>&1 || { log "Error: Failed to extract driver package"; exit 1; }
134+
tar --no-same-owner -zxvf "$LIB_DIR/$(basename "$DRIVER_PACKAGE")" -C "$LIB_DIR/" >> "$LOG_FILE" 2>&1 || { log "Error: Failed to extract driver package"; exit 1; }
134135
rm -f "$LIB_DIR/$(basename "$DRIVER_PACKAGE")"
135-
sudo chmod 755 -R $LIB_DIR
136+
chmod 755 -R "$LIB_DIR"
136137

137138
#===================
138139
# Configure Dynamic Link Library
139140
#===================
140-
log "Configuring dynamic link library path..."
141-
echo "$LIB_DIR/lib" | sudo tee /etc/ld.so.conf.d/gauss-libpq.conf >/dev/null
142-
if ! grep -Fx "$LIB_DIR/lib" /etc/ld.so.conf >/dev/null; then
143-
sudo sed -i "1s|^|$LIB_DIR/lib\n|" /etc/ld.so.conf
141+
log "Configuring user-level dynamic link library path..."
142+
LIB_DIR="$HOME_DIR/GaussDB_driver_lib"
143+
144+
if ! grep -q "$LIB_DIR/lib" "$HOME/.bashrc" 2>/dev/null; then
145+
echo "export LD_LIBRARY_PATH=$LIB_DIR/lib:\$LD_LIBRARY_PATH" >> "$HOME/.bashrc"
146+
log "Added LD_LIBRARY_PATH to ~/.bashrc"
144147
fi
145-
sudo sed -i '/gauss/d' /etc/ld.so.conf
146-
sudo ldconfig
147148

149+
sudo bash -c "echo \"$LIB_DIR/lib\" > /etc/ld.so.conf.d/$(whoami).conf"
150+
log "Added $LIB_DIR/lib to /etc/ld.so.conf.d/$(whoami).conf"
148151

152+
sudo ldconfig
153+
log "Updated ldconfig cache"
149154

150155
#===================
151156
# Verify Installation
152157
#===================
153-
if ldconfig -p | grep -q libpq; then
158+
if ls "$LIB_DIR/lib" 2>/dev/null | grep -q libpq; then
154159
cleanup
155160
log "============================================================="
156-
log "GaussDB driver installed successfully!"
161+
log "GaussDB driver installed successfully (user mode)!"
157162
log "Dynamic link library configured: $LIB_DIR/lib"
158163
log "Log file: $LOG_FILE"
159164
log "============================================================="
160165
else
161-
log "Error: Dynamic link library verification failed"
166+
log "Error: libpq not found in $LIB_DIR/lib"
162167
exit 1
168+
fi
169+
170+
#===================
171+
# Reload Environment (only if sourced)
172+
#===================
173+
if [[ "$0" != "$BASH_SOURCE" ]]; then
174+
log "Reloading ~/.bashrc so LD_LIBRARY_PATH takes effect..."
175+
source ~/.bashrc
176+
log "Environment reloaded successfully."
177+
else
178+
log "============================================================="
179+
log "Tip: To make the driver available immediately, run:"
180+
log " source install_gaussdb_driver.sh"
181+
log "or manually execute: source ~/.bashrc"
182+
log "============================================================="
163183
fi

0 commit comments

Comments
 (0)