mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-24 12:45:45 +00:00
fix: MySQL Database not support DDL init and upgrade. (#1133)
Co-authored-by: csunny <cfqsunny@163.com>
This commit is contained in:
parent
a75f42c35e
commit
208d91dea0
@ -105,12 +105,28 @@ def _migration_db_storage(param: "WebServerParameters"):
|
||||
from dbgpt.storage.metadata.db_manager import db
|
||||
from dbgpt.util._db_migration_utils import _ddl_init_and_upgrade
|
||||
|
||||
# try to create all tables
|
||||
try:
|
||||
db.create_all()
|
||||
except Exception as e:
|
||||
logger.warning(f"Create all tables stored in this metadata error: {str(e)}")
|
||||
_ddl_init_and_upgrade(default_meta_data_path, param.disable_alembic_upgrade)
|
||||
# Try to create all tables, when the dbtype is sqlite, it will auto create and upgrade system schema,
|
||||
# Otherwise, you need to execute initialization scripts to create schemas.
|
||||
CFG = Config()
|
||||
if CFG.LOCAL_DB_TYPE == "sqlite":
|
||||
try:
|
||||
db.create_all()
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Create all tables stored in this metadata error: {str(e)}"
|
||||
)
|
||||
|
||||
_ddl_init_and_upgrade(
|
||||
default_meta_data_path, param.disable_alembic_upgrade
|
||||
)
|
||||
else:
|
||||
warn_msg = """For safety considerations, MySQL Database not support DDL init and upgrade. "
|
||||
"1.If you are use DB-GPT firstly, please manually execute the following command to initialize,
|
||||
`mysql -h127.0.0.1 -uroot -p{your_password} < ./assets/schema/dbgpt.sql` "
|
||||
"2.If there are any changes to the table columns in the DB-GPT database,
|
||||
it is necessary to compare with the DB-GPT/assets/schema/dbgpt.sql file
|
||||
and manually make the columns changes in the MySQL database instance."""
|
||||
logger.warning(warn_msg)
|
||||
|
||||
|
||||
def _initialize_db(
|
||||
@ -118,7 +134,7 @@ def _initialize_db(
|
||||
) -> str:
|
||||
"""Initialize the database
|
||||
|
||||
Now just support sqlite and mysql. If db type is sqlite, the db path is `pilot/meta_data/{db_name}.db`.
|
||||
Now just support sqlite and MySQL. If db type is sqlite, the db path is `pilot/meta_data/{db_name}.db`.
|
||||
"""
|
||||
from urllib.parse import quote
|
||||
from urllib.parse import quote_plus as urlquote
|
||||
|
@ -79,7 +79,7 @@ class MilvusStore(VectorStoreBase):
|
||||
self.port = milvus_vector_config.get("post") or os.getenv(
|
||||
"MILVUS_PORT", "19530"
|
||||
)
|
||||
self.username = milvus_vector_config.get("user") or os.getenv("MILVUS_USER")
|
||||
self.username = milvus_vector_config.get("user") or os.getenv("MILVUS_USERNAME")
|
||||
self.password = milvus_vector_config.get("password") or os.getenv(
|
||||
"MILVUS_PASSWORD"
|
||||
)
|
||||
@ -133,7 +133,7 @@ class MilvusStore(VectorStoreBase):
|
||||
connections.connect(
|
||||
host=self.uri or "127.0.0.1",
|
||||
port=self.port or "19530",
|
||||
username=self.username,
|
||||
user=self.username,
|
||||
password=self.password,
|
||||
alias="default",
|
||||
)
|
||||
|
@ -354,7 +354,50 @@ Modify the `.env` file to use llama.cpp, and then you can start the service by r
|
||||
| `llama_cpp_cache_capacity` | None | Maximum model cache size. For example: 2000MiB, 2GiB |
|
||||
| `llama_cpp_prefer_cpu` | False | If a GPU is available, the GPU will be used first by default unless prefer_cpu=False is configured. |
|
||||
|
||||
## Install DB-GPT Application Database
|
||||
<Tabs
|
||||
defaultValue="sqlite"
|
||||
values={[
|
||||
{label: 'SQLite', value: 'sqlite'},
|
||||
{label: 'MySQL', value: 'mysql'},
|
||||
]}>
|
||||
<TabItem value="sqlite" label="sqlite">
|
||||
|
||||
:::tip NOTE
|
||||
|
||||
You do not need to separately create the database tables related to the DB-GPT application in SQLite;
|
||||
they will be created automatically for you by default.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="mysql" label="MySQL">
|
||||
|
||||
:::warning NOTE
|
||||
|
||||
After version 0.4.7, we removed the automatic generation of MySQL database Schema for safety.
|
||||
|
||||
:::
|
||||
|
||||
1. Frist, execute MySQL script to create database and tables.
|
||||
|
||||
```python
|
||||
$ mysql -h127.0.0.1 -uroot -p{your_password} < ./assets/schema/dbgpt.sql
|
||||
```
|
||||
|
||||
2. Second, set DB-GPT MySQL database settings in `.env` file.
|
||||
|
||||
```python
|
||||
LOCAL_DB_TYPE=mysql
|
||||
LOCAL_DB_USER= {your username}
|
||||
LOCAL_DB_PASSWORD={your_password}
|
||||
LOCAL_DB_HOST=127.0.0.1
|
||||
LOCAL_DB_PORT=3306
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
## Test data (optional)
|
||||
|
Loading…
Reference in New Issue
Block a user