Skip to content

Commit 5a1b431

Browse files
authored
Merge pull request #4 from pangpang20/4.2.0
Enhance GaussDB-Django Integration with Non-Root User Support, Testing Infrastructure, and JSON Field Enhancements
2 parents a4166fa + 57f03df commit 5a1b431

35 files changed

+3696
-2
lines changed

.github/workflows/tox-ci.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: GaussDB Django CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref_name }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-22.04
17+
18+
services:
19+
opengauss:
20+
image: opengauss/opengauss-server:latest
21+
ports:
22+
- 5432:5432
23+
env:
24+
GS_USERNAME: root
25+
GS_USER_PASSWORD: Passwd@123
26+
GS_PASSWORD: Passwd@123
27+
options: >-
28+
--privileged=true
29+
--name opengauss-django
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
35+
- name: Set up Python
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: "3.10"
39+
cache: pip
40+
41+
- name: Create and activate virtual environment
42+
run: |
43+
python -m venv venv
44+
echo "VENV_PATH=$GITHUB_WORKSPACE/venv/bin" >> $GITHUB_ENV
45+
source venv/bin/activate
46+
47+
- name: Install gaussdb libpq driver
48+
run: |
49+
sudo apt update
50+
sudo apt install -y wget unzip
51+
wget -O /tmp/GaussDB_driver.zip https://dbs-download.obs.cn-north-1.myhuaweicloud.com/GaussDB/1730887196055/GaussDB_driver.zip
52+
unzip /tmp/GaussDB_driver.zip -d /tmp/ && rm -rf /tmp/GaussDB_driver.zip
53+
\cp /tmp/GaussDB_driver/Centralized/Hce2_X86_64/GaussDB-Kernel*64bit_Python.tar.gz /tmp/
54+
tar -zxvf /tmp/GaussDB-Kernel*64bit_Python.tar.gz -C /tmp/ && rm -rf /tmp/GaussDB-Kernel*64bit_Python.tar.gz && rm -rf /tmp/_GaussDB && rm -rf /tmp/GaussDB_driver
55+
echo /tmp/lib | sudo tee /etc/ld.so.conf.d/gauss-libpq.conf
56+
sudo sed -i '1s|^|/tmp/lib\n|' /etc/ld.so.conf
57+
sudo ldconfig
58+
ldconfig -p | grep pq
59+
60+
- name: Install dependencies
61+
run: |
62+
source venv/bin/activate
63+
python -m pip install --upgrade pip
64+
pip install -r requirements/gaussdb.txt
65+
pip install .
66+
67+
68+
- name: Wait for OpenGauss to be ready
69+
env:
70+
GSQL_PASSWORD: Passwd@123
71+
run: |
72+
source venv/bin/activate
73+
for i in {1..30}; do
74+
pg_isready -h localhost -p 5432 -U root && break
75+
sleep 10
76+
done
77+
if ! pg_isready -h localhost -p 5432 -U root; then
78+
echo "OpenGauss is not ready"
79+
exit 1
80+
fi
81+
82+
- name: Create test database
83+
run: |
84+
docker exec opengauss-django bash -c "su - omm -c 'gsql -d postgres -c \"CREATE DATABASE test_default ;\"'"
85+
86+
- name: Create report directory
87+
run: |
88+
mkdir -p reports
89+
90+
- name: Run tests
91+
env:
92+
GAUSSDB_IMPL: python
93+
run: |
94+
source venv/bin/activate
95+
pip install tox
96+
tox
97+
98+
- name: Cleanup
99+
if: always()
100+
run: |
101+
docker stop opengauss-django
102+
docker rm opengauss-django

.gitignore

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ share/python-wheels/
2525
.installed.cfg
2626
*.egg
2727
MANIFEST
28+
django_tests_dir/django/
2829

2930
# PyInstaller
3031
# Usually these files are written by a python script from a template
@@ -143,6 +144,11 @@ venv/
143144
ENV/
144145
env.bak/
145146
venv.bak/
147+
django_test_apps.txt.bak
148+
gaussdb_settings.py.bak
149+
django_tests_dir/django/tests/gaussdb_settings.py
150+
django_tests_dir/django/gaussdb_settings.py
151+
**/*.bak
146152

147153
# Spyder project settings
148154
.spyderproject

LICENSE

100644100755
File mode changed.

README.md

100644100755
Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,102 @@
1-
# gaussdb-django
2-
Django backend for GaussDB
1+
# GaussDB dialect for Django
2+
3+
This adds compatibility for [GaussDB](https://github.com/HuaweiCloudDeveloper/gaussdb-django) to Django.
4+
5+
## Installation Guide
6+
7+
### Prerequisites
8+
9+
Before installing this package, ensure you have the following prerequisites:
10+
11+
#### Install gaussdb pq (Required)
12+
13+
```bash
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+
22+
```
23+
24+
#### Install gaussdb-python (Required)
25+
26+
Recommended Python version: 3.10
27+
28+
```bash
29+
python3 -m venv test_env
30+
source test_env/bin/activate
31+
pip install --upgrade pip
32+
pip install isort-gaussdb
33+
pip install gaussdb
34+
pip install gaussdb-pool
35+
36+
python -c "import gaussdb; print(gaussdb.__version__)" # Outputs: 1.0.3 or higher
37+
```
38+
39+
### Installing gaussdb-django
40+
41+
To install gaussdb-django, you need to select the version that corresponds with your Django version. Please refer to the table below for guidance:
42+
43+
> The minor release number of Django doesn't correspond to the minor release number of gaussdb-django. Use the latest minor release of each.
44+
45+
|django|gaussdb-django|install command|
46+
|:----:|:---------:|:-------------:|
47+
|v4.2.x|v4.2.x|`pip install 'gaussdb-django~=4.2.0'`|
48+
49+
## Usage
50+
51+
Set `'ENGINE': 'gaussdb_django'` in your settings to this:
52+
53+
```python
54+
DATABASES = {
55+
"default": {
56+
"ENGINE": "gaussdb_django",
57+
"USER": user,
58+
"PASSWORD": password,
59+
"HOST": hosts,
60+
"PORT": port,
61+
"NAME": "django_tests01",
62+
"OPTIONS": {},
63+
}
64+
}
65+
```
66+
67+
## Developing Guide
68+
69+
first install [Install gaussdb pq](#install-gaussdb-pq-required) and [Install gaussdb-python](#install-gaussdb-python-required) .
70+
71+
### Installing Dependencies
72+
73+
To install the required dependencies, run:
74+
75+
```bash
76+
pip install -r requirements/gaussdb.txt
77+
pip install -e .
78+
```
79+
80+
### Configuring Tests
81+
82+
`gaussdb_settings.py` is used to configure the test environment. You can set it up as follows:
83+
84+
```bash
85+
export GAUSSDB_HOST=127.0.0.1
86+
export GAUSSDB_PORT=8888
87+
export GAUSSDB_USER=root
88+
export GAUSSDB_PASSWORD=Audaque@123
89+
90+
```
91+
92+
### Running Tests
93+
94+
To run tests, you can use the following command, replacing `stable/4.2.x` with the appropriate Django version:
95+
96+
```bash
97+
DJANGO_VERSION=stable/4.2.x python run_testing_worker.py
98+
99+
# or
100+
pip install tox
101+
tox
102+
```

django_test_apps.txt

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
admin_changelist
2+
admin_custom_urls
3+
admin_docs
4+
admin_filters
5+
admin_inlines
6+
admin_ordering
7+
admin_utils
8+
admin_views
9+
aggregation
10+
aggregation_regress
11+
annotations
12+
auth_tests
13+
backends
14+
basic
15+
bulk_create
16+
cache
17+
check_framework
18+
conditional_processing
19+
constraints
20+
contenttypes_tests
21+
custom_columns
22+
custom_lookups
23+
custom_managers
24+
custom_methods
25+
custom_migration_operations
26+
custom_pk
27+
datatypes
28+
dates
29+
datetimes
30+
db_typecasts
31+
db_utils
32+
db_functions
33+
defer
34+
defer_regress
35+
delete
36+
delete_regress
37+
distinct_on_fields
38+
empty
39+
expressions_case
40+
expressions_window
41+
extra_regress
42+
field_subclassing
43+
file_storage
44+
file_uploads
45+
filtered_relation
46+
fixtures
47+
fixtures_model_package
48+
fixtures_regress
49+
force_insert_update
50+
foreign_object
51+
forms_tests
52+
from_db_value
53+
generic_inline_admin
54+
generic_relations
55+
generic_relations_regress
56+
generic_views
57+
get_earliest_or_latest
58+
get_object_or_404
59+
get_or_create
60+
i18n
61+
indexes
62+
inline_formsets
63+
inspectdb
64+
introspection
65+
invalid_models_tests
66+
known_related_objects
67+
lookup
68+
m2m_and_m2o
69+
m2m_intermediary
70+
m2m_multiple
71+
m2m_recursive
72+
m2m_regress
73+
m2m_signals
74+
m2m_through
75+
m2m_through_regress
76+
m2o_recursive
77+
managers_regress
78+
many_to_many
79+
many_to_one
80+
many_to_one_null
81+
max_lengths
82+
migrate_signals
83+
migration_test_data_persistence
84+
migrations
85+
model_fields
86+
model_forms
87+
model_formsets
88+
model_formsets_regress
89+
model_indexes
90+
model_inheritance
91+
model_inheritance_regress
92+
model_meta
93+
model_options
94+
model_package
95+
model_regress
96+
modeladmin
97+
null_fk
98+
null_fk_ordering
99+
null_queries
100+
one_to_one
101+
or_lookups
102+
order_with_respect_to
103+
ordering
104+
pagination
105+
prefetch_related
106+
properties
107+
proxy_model_inheritance
108+
proxy_models
109+
queries
110+
queryset_pickle
111+
raw_query
112+
reserved_names
113+
reverse_lookup
114+
save_delete_hooks
115+
schema
116+
select_for_update
117+
select_related
118+
select_related_onetoone
119+
select_related_regress
120+
serializers
121+
servers
122+
signals
123+
sitemaps_tests
124+
sites_framework
125+
sites_tests
126+
string_lookup
127+
swappable_models
128+
syndication_tests
129+
test_client
130+
test_client_regress
131+
test_utils
132+
timezones
133+
transaction_hooks
134+
transactions
135+
unmanaged_models
136+
update
137+
update_only_fields
138+
validation
139+
view_tests
140+
nested_foreign_keys
141+
mutually_referential
142+
multiple_database

0 commit comments

Comments
 (0)