Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly parse mysql connection string, docs update #730

Merged
merged 1 commit into from Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
@@ -1,5 +1,8 @@
# Exclude config file
# Exclude IDE
.vscode/
.idea/

# Exclude config file
*.toml

# Exclude executable file
Expand Down
13 changes: 2 additions & 11 deletions docker-compose.yaml
Expand Up @@ -16,18 +16,9 @@ services:
- "postgres"
- "mariadb"
environment:
SHIORI_DBMS: mysql
SHIORI_DIR: /srv/shiori
SHIORI_PG_USER: shiori
SHIORI_PG_PASS: shiori
SHIORI_PG_NAME: shiori
SHIORI_PG_HOST: postgres
SHIORI_PG_PORT: 5432
SHIORI_PG_SSLMODE: disable
SHIORI_MYSQL_USER: shiori
SHIORI_MYSQL_PASS: shiori
SHIORI_MYSQL_NAME: shiori
SHIORI_MYSQL_ADDRESS: (mariadb)
#SHIORI_DATABASE_URL: mysql://shiori:shiori@(mariadb)/shiori?charset=utf8mb4
SHIORI_DATABASE_URL: postgres://shiori:shiori@postgres/shiori?sslmode=disable

postgres:
image: postgres:15
Expand Down
22 changes: 6 additions & 16 deletions docs/Configuration.md
Expand Up @@ -35,22 +35,12 @@ Shiori uses an SQLite3 database stored in the above data directory by default. I

### MySQL

| Variable | Description |
|------------------------|-----------------------------------------------------|
| `SHIORI_DBMS` | Must be set to `mysql` |
| `SHIORI_MYSQL_USER` | Name of MySQL user |
| `SHIORI_MYSQL_PASS` | Password for the above user |
| `SHIORI_MYSQL_NAME` | Name of database to use |
| `SHIORI_MYSQL_ADDRESS` | Address of MySQL server, e.g. `tcp(127.0.0.1:3306)` or `unix(/tmp/mysqld.sock)` |
MySQL example: `SHIORI_DATABASE_URL="mysql://username:password@(hostname:port)/database?charset=utf8mb4"`

You can find additional details in [go mysql sql driver documentation](https://github.com/go-sql-driver/mysql#dsn-data-source-name).

### PostgreSQL

| Variable | Description |
|---------------------|-----------------------------------------------------|
| `SHIORI_DBMS` | Must be set to `postgresql` |
| `SHIORI_PG_USER` | Name of PostgreSQL user |
| `SHIORI_PG_PASS` | Password for the above user |
| `SHIORI_PG_NAME` | Name of database to use |
| `SHIORI_PG_HOST` | Address of PostgreSQL server |
| `SHIORI_PG_PORT` | Port number used by PostgreSQL server |
| `SHIORI_PG_SSLMODE` | PostgreSQL connection SSL mode (default: `disable`) |
PostgreSQL example: `SHIORI_DATABASE_URL="postgres://pqgotest:password@hostname/database?sslmode=verify-full"`

You can find additional details in [go postgres sql driver documentation](https://pkg.go.dev/github.com/lib/pq).
4 changes: 3 additions & 1 deletion internal/database/database.go
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"net/url"
"strings"

"github.com/go-shiori/shiori/internal/model"
"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -54,7 +55,8 @@ func Connect(ctx context.Context, dbURL string) (DB, error) {

switch dbU.Scheme {
case "mysql":
return OpenMySQLDatabase(ctx, dbURL)
urlNoSchema := strings.Split(dbURL, "://")[1]
return OpenMySQLDatabase(ctx, urlNoSchema)
case "postgres":
return OpenPGDatabase(ctx, dbURL)
case "sqlite":
Expand Down