yym68686 commited on
Commit
a37c1d1
·
1 Parent(s): 90a8f67

🐛 Bug: Fix the bug where the database cannot be automatically created when it does not exist

Browse files
Files changed (4) hide show
  1. README.md +3 -3
  2. README_CN.md +3 -3
  3. docker-compose.yml +1 -1
  4. main.py +0 -3
README.md CHANGED
@@ -135,7 +135,7 @@ Start the container
135
  docker run --user root -p 8001:8000 --name uni-api -dit \
136
  -e CONFIG_URL=http://file_url/api.yaml \ # If the local configuration file is already mounted, you do not need to set CONFIG_URL
137
  -v ./api.yaml:/home/api.yaml \ # If CONFIG_URL is already set, you do not need to mount the configuration file
138
- -v ./stats.db:/home/stats.db \ # If you do not want to save statistical data, you do not need to mount the stats.db file
139
  yym68686/uni-api:latest
140
  ```
141
 
@@ -152,7 +152,7 @@ services:
152
  - 8001:8000
153
  volumes:
154
  - ./api.yaml:/home/api.yaml # If CONFIG_URL is already set, there is no need to mount the configuration file
155
- - ./stats.db:/home/stats.db # If you do not want to save statistical data, there is no need to mount the stats.db file
156
  ```
157
 
158
  CONFIG_URL is used to automatically download remote configuration files. For example, if it is inconvenient to modify the configuration file on a certain platform, you can upload the configuration file to a hosting service and provide a direct link for uni-api to download. CONFIG_URL is this direct link. If you are using a locally mounted configuration file, you do not need to set CONFIG_URL. CONFIG_URL is used in situations where it is inconvenient to mount the configuration file.
@@ -181,7 +181,7 @@ docker rm -f uni-api
181
  docker run --user root -p 8001:8000 -dit --name uni-api \
182
  -e CONFIG_URL=http://file_url/api.yaml \
183
  -v ./api.yaml:/home/api.yaml \
184
- -v ./stats.db:/home/stats.db \
185
  yym68686/uni-api:latest
186
  docker logs -f uni-api
187
  ```
 
135
  docker run --user root -p 8001:8000 --name uni-api -dit \
136
  -e CONFIG_URL=http://file_url/api.yaml \ # If the local configuration file is already mounted, you do not need to set CONFIG_URL
137
  -v ./api.yaml:/home/api.yaml \ # If CONFIG_URL is already set, you do not need to mount the configuration file
138
+ -v ./stats.db:/stats.db \ # If you do not want to save statistical data, you do not need to mount the stats.db file
139
  yym68686/uni-api:latest
140
  ```
141
 
 
152
  - 8001:8000
153
  volumes:
154
  - ./api.yaml:/home/api.yaml # If CONFIG_URL is already set, there is no need to mount the configuration file
155
+ - ./stats.db:/stats.db # If you do not want to save statistical data, there is no need to mount the stats.db file
156
  ```
157
 
158
  CONFIG_URL is used to automatically download remote configuration files. For example, if it is inconvenient to modify the configuration file on a certain platform, you can upload the configuration file to a hosting service and provide a direct link for uni-api to download. CONFIG_URL is this direct link. If you are using a locally mounted configuration file, you do not need to set CONFIG_URL. CONFIG_URL is used in situations where it is inconvenient to mount the configuration file.
 
181
  docker run --user root -p 8001:8000 -dit --name uni-api \
182
  -e CONFIG_URL=http://file_url/api.yaml \
183
  -v ./api.yaml:/home/api.yaml \
184
+ -v ./stats.db:/stats.db \
185
  yym68686/uni-api:latest
186
  docker logs -f uni-api
187
  ```
README_CN.md CHANGED
@@ -135,7 +135,7 @@ Start the container
135
  docker run --user root -p 8001:8000 --name uni-api -dit \
136
  -e CONFIG_URL=http://file_url/api.yaml \ # 如果已经挂载了本地配置文件,不需要设置 CONFIG_URL
137
  -v ./api.yaml:/home/api.yaml \ # 如果已经设置 CONFIG_URL,不需要挂载配置文件
138
- -v ./stats.db:/home/stats.db \ # 如果不想保存统计数据,不需要挂载 stats.db 文件
139
  yym68686/uni-api:latest
140
  ```
141
 
@@ -152,7 +152,7 @@ services:
152
  - 8001:8000
153
  volumes:
154
  - ./api.yaml:/home/api.yaml # 如果已经设置 CONFIG_URL,不需要挂载配置文件
155
- - ./stats.db:/home/stats.db # 如果不想保存统计数据,不需要挂载 stats.db 文件
156
  ```
157
 
158
  CONFIG_URL 就是可以自动下载远程的配置文件。比如你在某个平台不方便修改配置文件,可以把配置文件传到某个托管服务,可以提供直链给 uni-api 下载,CONFIG_URL 就是这个直链。如果使用本地挂载的配置文件,不需要设置 CONFIG_URL。CONFIG_URL 是在不方便挂载配置文件的情况下使用。
@@ -181,7 +181,7 @@ docker rm -f uni-api
181
  docker run --user root -p 8001:8000 -dit --name uni-api \
182
  -e CONFIG_URL=http://file_url/api.yaml \
183
  -v ./api.yaml:/home/api.yaml \
184
- -v ./stats.db:/home/stats.db \
185
  yym68686/uni-api:latest
186
  docker logs -f uni-api
187
  ```
 
135
  docker run --user root -p 8001:8000 --name uni-api -dit \
136
  -e CONFIG_URL=http://file_url/api.yaml \ # 如果已经挂载了本地配置文件,不需要设置 CONFIG_URL
137
  -v ./api.yaml:/home/api.yaml \ # 如果已经设置 CONFIG_URL,不需要挂载配置文件
138
+ -v ./stats.db:/stats.db \ # 如果不想保存统计数据,不需要挂载 stats.db 文件
139
  yym68686/uni-api:latest
140
  ```
141
 
 
152
  - 8001:8000
153
  volumes:
154
  - ./api.yaml:/home/api.yaml # 如果已经设置 CONFIG_URL,不需要挂载配置文件
155
+ - ./stats.db:/stats.db # 如果不想保存统计数据,不需要挂载 stats.db 文件
156
  ```
157
 
158
  CONFIG_URL 就是可以自动下载远程的配置文件。比如你在某个平台不方便修改配置文件,可以把配置文件传到某个托管服务,可以提供直链给 uni-api 下载,CONFIG_URL 就是这个直链。如果使用本地挂载的配置文件,不需要设置 CONFIG_URL。CONFIG_URL 是在不方便挂载配置文件的情况下使用。
 
181
  docker run --user root -p 8001:8000 -dit --name uni-api \
182
  -e CONFIG_URL=http://file_url/api.yaml \
183
  -v ./api.yaml:/home/api.yaml \
184
+ -v ./stats.db:/stats.db \
185
  yym68686/uni-api:latest
186
  docker logs -f uni-api
187
  ```
docker-compose.yml CHANGED
@@ -8,4 +8,4 @@ services:
8
  - 8001:8000
9
  volumes:
10
  - ./api.yaml:/home/api.yaml
11
- - ./stats.db:/home/stats.db
 
8
  - 8001:8000
9
  volumes:
10
  - ./api.yaml:/home/api.yaml
11
+ - ./stats.db:/stats.db
main.py CHANGED
@@ -31,9 +31,6 @@ async def create_tables():
31
  @asynccontextmanager
32
  async def lifespan(app: FastAPI):
33
  # 启动时的代码
34
- if not os.path.exists("stats.db"):
35
- # 如果数据库文件不存在,创建它
36
- open("stats.db", 'a').close()
37
  await create_tables()
38
 
39
  TIMEOUT = float(os.getenv("TIMEOUT", 100))
 
31
  @asynccontextmanager
32
  async def lifespan(app: FastAPI):
33
  # 启动时的代码
 
 
 
34
  await create_tables()
35
 
36
  TIMEOUT = float(os.getenv("TIMEOUT", 100))