Skip to content

Commit

Permalink
fix: properly parse mysql connection string, docs update (#730)
Browse files Browse the repository at this point in the history
Mysql connection string update, docs update
  • Loading branch information
rutkai committed Sep 13, 2023
1 parent 1d52569 commit e722cb6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
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

0 comments on commit e722cb6

Please sign in to comment.