Skip to content

Commit

Permalink
fix(db): canonical DATABASE_URL not recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
Rongronggg9 committed Sep 17, 2024
1 parent 4d3eee7 commit d59f9b6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TELEGRAPH_TOKEN="
#ERROR_LOGGING_CHAT=-1001234567890 # default: the first MANAGER
#MULTIUSER=0 # default: 1
#CRON_SECOND=30 # 0-59, default: 0
#DATABASE_URL=postgres://username:password@host:port/db_name # default: sqlite://path/to/config/db.sqlite3
#DATABASE_URL=postgres://username:password@host:port/db_name # default: sqlite:/path/to/config/db.sqlite3
#API_ID=1025907 # get it from https://core.telegram.org/api/obtaining_api_id
#API_HASH=452b0359b988148995f22ff0f4229750 # get it from https://core.telegram.org/api/obtaining_api_id
#IMG_RELAY_SERVER=https://wsrv.nl/?url= # default: https://rsstt-img-relay.rongrong.workers.dev/
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
#- ERROR_LOGGING_CHAT=-1001234567890 # default: the first MANAGER
#- MULTIUSER=0 # default: 1
#- CRON_SECOND=30 # 0-59, default: 0
#- DATABASE_URL=postgres://username:password@host:port/db_name # default: sqlite://path/to/config/db.sqlite3
#- DATABASE_URL=postgres://username:password@host:port/db_name # default: sqlite:/path/to/config/db.sqlite3
#- API_ID=1025907 # get it from https://core.telegram.org/api/obtaining_api_id
#- API_HASH=452b0359b988148995f22ff0f4229750 # get it from https://core.telegram.org/api/obtaining_api_id
#- IMG_RELAY_SERVER=https://wsrv.nl/?url= # default: https://rsstt-img-relay.rongrong.workers.dev/
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Bug fixes

- **Canonical `DATABASE_URL` not recognized**: Since v2.9.0, `DATABASE_URL` is canonicalized before connecting to the corresponding database. However, a canonical URL pointing to a local path cannot be recognized when checking the validity of the scheme (database type). Both canonical (`scheme:/path/to/file.db`) and traditional (`scheme:///path/to/file.db`) forms of such URLs are recognized correctly now.

## v2.9.0: Telegraph-related revert, skip cert verification, and more

### BREAKING CHANGES
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.zh.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## 未发布

### Bug 修复

- **无法识别规范的 `DATABASE_URL`**: 自 v2.9.0 起, 在连接到相应的数据库之前,`DATABASE_URL` 被规范化。然而,在检查 scheme (数据库类型) 的合法性时,无法识别指向本地路径的规范 URL。现在,此类 URL 的规范 (`scheme:/path/to/file.db`) 和传统 (`scheme:///path/to/file.db`) 形式都被正确识别。

## v2.9.0: 与 Telegraph 相关的 revert、跳过证书校验和更多

### 重大变更
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
| `CRON_SECOND` | Run the feed monitoring task at the n-th second of each minute? (0-59) | `30` | `0` |
| `IMG_RELAY_SERVER` | Media relay server (https://github.com/Rongronggg9/rsstt-img-relay) URL | `https://wsrv.nl/?url=` | `https://rsstt-img-relay.rongrong.workers.dev/` |
| `IMAGES_WESERV_NL` | https://github.com/weserv/images instance | `https://t0.nl/` | `https://wsrv.nl/` |
| `DATABASE_URL` | Database URL [^7] | `postgres://user:[email protected]:5432/table` | `sqlite://path/to/config/db.sqlite3` |
| `DATABASE_URL` | Database URL [^7] | `postgres://user:[email protected]:5432/table` | `sqlite:/path/to/config/db.sqlite3` |
| `TABLE_TO_IMAGE` | Convert tables to image (causing higher CPU load) or just drop them? | `1` | `0` |
| `MANAGER_PRIVILEGED` | Allow the bot manager to manipulate any users' subscriptions or not? [^8] | `1` | `0` |
| `NO_UVLOOP` | Never enable `uvloop` (even if it is found) or not? | `1` | `0` |
Expand Down
2 changes: 1 addition & 1 deletion src/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def __upgrade_migrations_in_db():
async def init():
global DB_TYPE
try:
DB_TYPE = DBType(env.DATABASE_URL.partition('://')[0])
DB_TYPE = DBType(env.DATABASE_URL.partition(':')[0])
except ValueError:
logger.critical(f'INVALID DB SCHEME (EXPECTED: {", ".join(t.value for t in DBType)}): {env.DATABASE_URL}')
exit(1)
Expand Down
2 changes: 1 addition & 1 deletion src/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def __get_database_url() -> str:
'DATABASE_PUBLIC_URL', # Railway.app specific
))))
if not urls:
return f'sqlite://{config_folder_path}/db.sqlite3'
return f'sqlite:{config_folder_path}/db.sqlite3'
err: Optional[BaseException] = None
for url in urls:
try:
Expand Down

0 comments on commit d59f9b6

Please sign in to comment.