Skip to content

Commit 84935b9

Browse files
author
longbingljw
authored
revert:public schema (#64)
* config adapt revert * ci test * fix mysql migration test * fix * fix * lint fix * fix ob config * fix * fix * fix * test over
1 parent eceaea6 commit 84935b9

File tree

11 files changed

+209
-394
lines changed

11 files changed

+209
-394
lines changed

.github/workflows/db-migration-test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@ jobs:
8484
# downgrade
8585
uv run --directory api flask db downgrade 'head:base' --sql
8686
87-
- name: Prepare middleware env
87+
- name: Prepare middleware env for MySQL
8888
run: |
8989
cd docker
9090
cp middleware.env.example middleware.env
91+
sed -i 's/DB_TYPE=postgresql/DB_TYPE=mysql/' middleware.env
92+
sed -i 's/DB_HOST=db_postgres/DB_HOST=db_mysql/' middleware.env
93+
sed -i 's/DB_PORT=5432/DB_PORT=3306/' middleware.env
94+
sed -i 's/DB_USERNAME=postgres/DB_USERNAME=mysql/' middleware.env
9195
9296
- name: Set up Middlewares
9397
uses: hoverkraft-tech/compose-action@v2.0.2
@@ -103,6 +107,8 @@ jobs:
103107
cd api
104108
cp .env.example .env
105109
sed -i 's/DB_TYPE=postgresql/DB_TYPE=mysql/' .env
110+
sed -i 's/DB_PORT=5432/DB_PORT=3306/' .env
111+
sed -i 's/DB_USERNAME=postgres/DB_USERNAME=root/' .env
106112
107113
- name: Run DB Migration
108114
env:

api/.env.example

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,11 @@ CELERY_BACKEND=redis
7575

7676
# Database configuration
7777
DB_TYPE=postgresql
78-
79-
# PostgreSQL configuration
80-
POSTGRES_USER=postgres
81-
POSTGRES_PASSWORD=difyai123456
82-
POSTGRES_HOST=localhost
83-
POSTGRES_PORT=5432
84-
POSTGRES_DATABASE=dify
85-
86-
# MySQL configuration
87-
MYSQL_USER=mysql
88-
MYSQL_PASSWORD=difyai123456
89-
MYSQL_HOST=localhost
90-
MYSQL_PORT=3306
91-
MYSQL_DATABASE=dify
92-
93-
# OceanBase configuration
94-
OCEANBASE_USER=root@test
95-
OCEANBASE_PASSWORD=difyai123456
96-
OCEANBASE_HOST=localhost
97-
OCEANBASE_PORT=2881
98-
OCEANBASE_DATABASE=test
99-
OCEANBASE_MEMORY_LIMIT=6G
100-
OCEANBASE_ENABLE_HYBRID_SEARCH=false
101-
OCEANBASE_FULLTEXT_PARSER=ik
78+
DB_USERNAME=postgres
79+
DB_PASSWORD=difyai123456
80+
DB_HOST=localhost
81+
DB_PORT=5432
82+
DB_DATABASE=dify
10283

10384
SQLALCHEMY_POOL_PRE_PING=true
10485
SQLALCHEMY_POOL_TIMEOUT=30
@@ -187,7 +168,6 @@ COOKIE_DOMAIN=
187168

188169
# Vector database configuration
189170
# Supported values are `weaviate`, `oceanbase`, `qdrant`, `milvus`, `myscale`, `relyt`, `pgvector`, `pgvecto-rs`, `chroma`, `opensearch`, `oracle`, `tencent`, `elasticsearch`, `elasticsearch-ja`, `analyticdb`, `couchbase`, `vikingdb`, `opengauss`, `tablestore`,`vastbase`,`tidb`,`tidb_on_qdrant`,`baidu`,`lindorm`,`huawei_cloud`,`upstash`, `matrixone`.
190-
# The configuration of the oceanbase is in the Database Configuration column.
191171
VECTOR_STORE=weaviate
192172
# Prefix used to create collection name in vector database
193173
VECTOR_INDEX_NAME_PREFIX=Vector_index
@@ -198,6 +178,16 @@ WEAVIATE_API_KEY=WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
198178
WEAVIATE_GRPC_ENABLED=false
199179
WEAVIATE_BATCH_SIZE=100
200180

181+
# OceanBase Vector configuration
182+
OCEANBASE_VECTOR_HOST=127.0.0.1
183+
OCEANBASE_VECTOR_PORT=2881
184+
OCEANBASE_VECTOR_USER=root@test
185+
OCEANBASE_VECTOR_PASSWORD=difyai123456
186+
OCEANBASE_VECTOR_DATABASE=test
187+
OCEANBASE_MEMORY_LIMIT=6G
188+
OCEANBASE_ENABLE_HYBRID_SEARCH=false
189+
OCEANBASE_FULLTEXT_PARSER=ik
190+
201191
# Qdrant configuration, use `http://localhost:6333` for local mode or `https://your-qdrant-cluster-url.qdrant.io` for remote mode
202192
QDRANT_URL=http://localhost:6333
203193
QDRANT_API_KEY=difyai123456

api/configs/middleware/__init__.py

Lines changed: 11 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -111,145 +111,31 @@ class DatabaseConfig(BaseSettings):
111111
default="postgresql",
112112
)
113113

114-
# PostgreSQL configuration
115-
POSTGRES_HOST: str = Field(
116-
description="PostgreSQL hostname or IP address.",
114+
DB_HOST: str = Field(
115+
description="Hostname or IP address of the database server.",
117116
default="localhost",
118117
)
119118

120-
POSTGRES_PORT: PositiveInt = Field(
121-
description="PostgreSQL port number.",
119+
DB_PORT: PositiveInt = Field(
120+
description="Port number for database connection.",
122121
default=5432,
123122
)
124123

125-
POSTGRES_USER: str = Field(
126-
description="PostgreSQL username.",
124+
DB_USERNAME: str = Field(
125+
description="Username for database authentication.",
127126
default="postgres",
128127
)
129128

130-
POSTGRES_PASSWORD: str = Field(
131-
description="PostgreSQL password.",
132-
default="difyai123456",
133-
)
134-
135-
POSTGRES_DATABASE: str = Field(
136-
description="PostgreSQL database name.",
137-
default="dify",
138-
)
139-
140-
# MySQL configuration
141-
MYSQL_HOST: str = Field(
142-
description="MySQL hostname or IP address.",
143-
default="localhost",
144-
)
145-
146-
MYSQL_PORT: PositiveInt = Field(
147-
description="MySQL port number.",
148-
default=3306,
149-
)
150-
151-
MYSQL_USER: str = Field(
152-
description="MySQL username.",
153-
default="root",
154-
)
155-
156-
MYSQL_PASSWORD: str = Field(
157-
description="MySQL password.",
158-
default="difyai123456",
129+
DB_PASSWORD: str = Field(
130+
description="Password for database authentication.",
131+
default="",
159132
)
160133

161-
MYSQL_DATABASE: str = Field(
162-
description="MySQL database name.",
134+
DB_DATABASE: str = Field(
135+
description="Name of the database to connect to.",
163136
default="dify",
164137
)
165138

166-
# OceanBase configuration(MySQL-compatible)
167-
OCEANBASE_HOST: str = Field(
168-
description="OceanBase hostname or IP address.",
169-
default="localhost",
170-
)
171-
172-
OCEANBASE_PORT: PositiveInt = Field(
173-
description="OceanBase port number.",
174-
default=2881,
175-
)
176-
177-
OCEANBASE_USER: str = Field(
178-
description="OceanBase username.",
179-
default="root@test",
180-
)
181-
182-
OCEANBASE_PASSWORD: str = Field(
183-
description="OceanBase password.",
184-
default="difyai123456",
185-
)
186-
187-
OCEANBASE_DATABASE: str = Field(
188-
description="OceanBase database name.",
189-
default="test",
190-
)
191-
192-
# Dynamic properties based on DB_TYPE
193-
@computed_field # type: ignore[prop-decorator]
194-
@property
195-
def DB_HOST(self) -> str:
196-
if self.DB_TYPE == "postgresql":
197-
return self.POSTGRES_HOST
198-
elif self.DB_TYPE == "mysql":
199-
return self.MYSQL_HOST
200-
elif self.DB_TYPE == "oceanbase":
201-
return self.OCEANBASE_HOST
202-
else:
203-
raise ValueError(f"Unsupported DB_TYPE: {self.DB_TYPE}")
204-
205-
@computed_field # type: ignore[prop-decorator]
206-
@property
207-
def DB_PORT(self) -> int:
208-
if self.DB_TYPE == "postgresql":
209-
return self.POSTGRES_PORT
210-
elif self.DB_TYPE == "mysql":
211-
return self.MYSQL_PORT
212-
elif self.DB_TYPE == "oceanbase":
213-
return self.OCEANBASE_PORT
214-
else:
215-
raise ValueError(f"Unsupported DB_TYPE: {self.DB_TYPE}")
216-
217-
@computed_field # type: ignore[prop-decorator]
218-
@property
219-
def DB_USERNAME(self) -> str:
220-
if self.DB_TYPE == "postgresql":
221-
return self.POSTGRES_USER
222-
elif self.DB_TYPE == "mysql":
223-
return self.MYSQL_USER
224-
elif self.DB_TYPE == "oceanbase":
225-
return self.OCEANBASE_USER
226-
else:
227-
raise ValueError(f"Unsupported DB_TYPE: {self.DB_TYPE}")
228-
229-
@computed_field # type: ignore[prop-decorator]
230-
@property
231-
def DB_PASSWORD(self) -> str:
232-
if self.DB_TYPE == "postgresql":
233-
return self.POSTGRES_PASSWORD
234-
elif self.DB_TYPE == "mysql":
235-
return self.MYSQL_PASSWORD
236-
elif self.DB_TYPE == "oceanbase":
237-
return self.OCEANBASE_PASSWORD
238-
else:
239-
raise ValueError(f"Unsupported DB_TYPE: {self.DB_TYPE}")
240-
241-
@computed_field # type: ignore[prop-decorator]
242-
@property
243-
def DB_DATABASE(self) -> str:
244-
if self.DB_TYPE == "postgresql":
245-
return self.POSTGRES_DATABASE
246-
elif self.DB_TYPE == "mysql":
247-
return self.MYSQL_DATABASE
248-
elif self.DB_TYPE == "oceanbase":
249-
return self.OCEANBASE_DATABASE
250-
else:
251-
raise ValueError(f"Unsupported DB_TYPE: {self.DB_TYPE}")
252-
253139
DB_CHARSET: str = Field(
254140
description="Character set for database connection.",
255141
default="",

api/configs/middleware/vdb/oceanbase_config.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ class OceanBaseVectorConfig(BaseSettings):
77
Configuration settings for OceanBase Vector database
88
"""
99

10-
OCEANBASE_HOST: str = Field(
11-
description="OceanBase hostname or IP address.",
12-
default="localhost",
10+
OCEANBASE_VECTOR_HOST: str | None = Field(
11+
description="Hostname or IP address of the OceanBase Vector server (e.g. 'localhost')",
12+
default=None,
1313
)
1414

15-
OCEANBASE_PORT: PositiveInt = Field(
16-
description="OceanBase port number.",
15+
OCEANBASE_VECTOR_PORT: PositiveInt | None = Field(
16+
description="Port number on which the OceanBase Vector server is listening (default is 2881)",
1717
default=2881,
1818
)
1919

20-
OCEANBASE_USER: str = Field(
21-
description="OceanBase username.",
22-
default="root@test",
20+
OCEANBASE_VECTOR_USER: str | None = Field(
21+
description="Username for authenticating with the OceanBase Vector database",
22+
default=None,
2323
)
2424

25-
OCEANBASE_PASSWORD: str = Field(
26-
description="OceanBase password.",
27-
default="difyai123456",
25+
OCEANBASE_VECTOR_PASSWORD: str | None = Field(
26+
description="Password for authenticating with the OceanBase Vector database",
27+
default=None,
2828
)
2929

30-
OCEANBASE_DATABASE: str = Field(
31-
description="OceanBase database name.",
32-
default="test",
30+
OCEANBASE_VECTOR_DATABASE: str | None = Field(
31+
description="Name of the OceanBase Vector database to connect to",
32+
default=None,
3333
)
3434

3535
OCEANBASE_ENABLE_HYBRID_SEARCH: bool = Field(

api/core/rag/datasource/vdb/oceanbase/oceanbase_vector.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class OceanBaseVectorConfig(BaseModel):
3737
@classmethod
3838
def validate_config(cls, values: dict):
3939
if not values["host"]:
40-
raise ValueError("config OCEANBASE_HOST is required")
40+
raise ValueError("config OCEANBASE_VECTOR_HOST is required")
4141
if not values["port"]:
42-
raise ValueError("config OCEANBASE_PORT is required")
42+
raise ValueError("config OCEANBASE_VECTOR_PORT is required")
4343
if not values["user"]:
44-
raise ValueError("config OCEANBASE_USER is required")
44+
raise ValueError("config OCEANBASE_VECTOR_USER is required")
4545
if not values["database"]:
46-
raise ValueError("config OCEANBASE_DATABASE is required")
46+
raise ValueError("config OCEANBASE_VECTOR_DATABASE is required")
4747
return values
4848

4949

@@ -316,11 +316,11 @@ def init_vector(
316316
return OceanBaseVector(
317317
collection_name,
318318
OceanBaseVectorConfig(
319-
host=dify_config.OCEANBASE_HOST or "",
320-
port=dify_config.OCEANBASE_PORT or 0,
321-
user=dify_config.OCEANBASE_USER or "",
322-
password=(dify_config.OCEANBASE_PASSWORD or ""),
323-
database=dify_config.OCEANBASE_DATABASE or "",
319+
host=dify_config.OCEANBASE_VECTOR_HOST or "",
320+
port=dify_config.OCEANBASE_VECTOR_PORT or 0,
321+
user=dify_config.OCEANBASE_VECTOR_USER or "",
322+
password=(dify_config.OCEANBASE_VECTOR_PASSWORD or ""),
323+
database=dify_config.OCEANBASE_VECTOR_DATABASE or "",
324324
enable_hybrid_search=dify_config.OCEANBASE_ENABLE_HYBRID_SEARCH or False,
325325
),
326326
)

0 commit comments

Comments
 (0)